> Canonical HTML: https://kerfscript.mylasertools.com/models/slide-grid/

# Captive sliding tile puzzle

Slide grid: a solvably shuffled sliding puzzle with a removable clear retainer. Circular finger ports let tiles slide beneath the cover while keeping them in. Assembly: glue the plywood spacer to the floor. Add tiles, then bolt the acrylic cover on with thin washers for vertical play. Undo it to change tiles.

This design has 18 parts on 2 sheets. Customize it in the [playground](https://kerfscript.mylasertools.com/playground/?model=slide-grid).

## Downloads

- [KerfScript source](https://kerfscript.mylasertools.com/models/slide-grid/slide-grid.kerf)
- [slide-grid-sheet-1.svg](https://kerfscript.mylasertools.com/models/slide-grid/slide-grid-sheet-1.svg)
- [slide-grid-sheet-1.dxf](https://kerfscript.mylasertools.com/models/slide-grid/slide-grid-sheet-1.dxf)
- [slide-grid-sheet-2.svg](https://kerfscript.mylasertools.com/models/slide-grid/slide-grid-sheet-2.svg)
- [slide-grid-sheet-2.dxf](https://kerfscript.mylasertools.com/models/slide-grid/slide-grid-sheet-2.dxf)

## Parts

| Part | Quantity | Size |
| --- | ---: | --- |
| Floor | 1 | 146 × 146 mm |
| Cavity spacer | 1 | 146 × 146 mm |
| Tile 1 | 1 | 30 × 30 mm |
| Tile 2 | 1 | 30 × 30 mm |
| Tile 3 | 1 | 30 × 30 mm |
| Tile 5 | 1 | 30 × 30 mm |
| Tile 6 | 1 | 30 × 30 mm |
| Tile 7 | 1 | 30 × 30 mm |
| Tile 4 | 1 | 30 × 30 mm |
| Tile 9 | 1 | 30 × 30 mm |
| Tile 10 | 1 | 30 × 30 mm |
| Tile 11 | 1 | 30 × 30 mm |
| Tile 8 | 1 | 30 × 30 mm |
| Tile 13 | 1 | 30 × 30 mm |
| Tile 14 | 1 | 30 × 30 mm |
| Tile 15 | 1 | 30 × 30 mm |
| Tile 12 | 1 | 30 × 30 mm |
| Clear retainer | 1 | 146 × 146 mm |

## Settings

| Name | Default | Range or choices |
| --- | --- | --- |
| `columns` | `4` | 3 to 6 |
| `rows` | `4` | 3 to 6 |
| `tile_size` | `30` | 24 to 45 |
| `shuffle_steps` | `32` | 0 to 80 |
| `seed` | `7` | 1 to 99 |
| `numbers` | `true` | on or off |
| `tile_slide` | `0` | 0 to 1 |
| `slide_gap` | `0.4` | 0.2 to 0.8 |
| `vertical_play` | `0.3` | 0.2 to 0.6 |
| `cover_thickness` | `2` | 1.5 to 3 |
| `bolt_diameter` | `3` | 3 to 4 |
| `$thickness` | `3` | 2 to 6 |
| `$kerf` | `0.15` | 0 to 0.3 |

## Source

```kerf
// Slide grid: a solvably shuffled sliding puzzle with a removable clear retainer.
// Circular finger ports let tiles slide beneath the cover while keeping them in.
// Assembly: glue the plywood spacer to the floor. Add tiles, then bolt the
// acrylic cover on with thin washers for vertical play. Undo it to change tiles.

/* [Puzzle] */
columns = 4; // [3:1:6]
rows = 4; // [3:1:6]
tile_size = 30; // [24:1:45]
shuffle_steps = 32; // [0:1:80]
seed = 7; // [1:1:99]
numbers = true;

/* [Assembled view] */
// Slide one adjacent tile into the blank, and back, without changing the cut.
tile_slide = 0; // [0:0.05:1]

/* [Fit] */
slide_gap = 0.4; // [0.2:0.05:0.8]
vertical_play = 0.3; // [0.2:0.05:0.6]
cover_thickness = 2; // [1.5:0.5:3]
bolt_diameter = 3; // [3:0.5:4]

/* [Material] */
$thickness = 3; // [2:0.5:6]
$kerf = 0.15; // [0:0.01:0.3]

/* [Hidden] */
$material = "plywood";
t = $thickness;
border = 12;
pitch = tile_size + slide_gap;
iw = columns * pitch + slide_gap;
id = rows * pitch + slide_gap;
w = iw + 2 * border;
d = id + 2 * border;
cells = columns * rows;
assert(tile_slide >= 0 && tile_slide <= 1, "Tile slide must stay between neighbouring cells");
function swapped(v, a, b) = [for (i = [0:len(v) - 1]) i == a ? v[b] : i == b ? v[a] : v[i]];
function shuffled(v, empty, n) = n <= 0 ? v : let (
  choices = [for (i = [0:cells - 1]) if (abs(i % columns - empty % columns) + abs(floor(i / columns) - floor(empty / columns)) == 1) i],
  pick = choices[min(len(choices) - 1, floor(rands(0, len(choices), 1, seed + n)[0]))])
  shuffled(swapped(v, empty, pick), pick, n - 1);
values = shuffled(concat([for (i = [1:cells - 1]) i], [0]), cells - 1, shuffle_steps);
empty = [for (i = [0:cells - 1]) if (values[i] == 0) i][0];
moving = [for (i = [0:cells - 1]) if (abs(i % columns - empty % columns) + abs(floor(i / columns) - floor(empty / columns)) == 1) i][0];
function location(i) = [border + slide_gap + (i % columns) * pitch, border + slide_gap + floor(i / columns) * pitch, t];
module screw_holes() for (x = [border / 2, w - border / 2], y = [border / 2, d - border / 2]) translate([x, y]) circle(d = bolt_diameter + 0.3);
module plate() difference() { rect([w, d], r = 4); screw_holes(); }
module numeral(n, size) {
  digits = [[0, 1, 2, 3, 4, 5], [1, 2], [0, 1, 6, 4, 3], [0, 1, 6, 2, 3], [5, 6, 1, 2], [0, 5, 6, 2, 3], [0, 5, 4, 3, 2, 6], [0, 1, 2], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 5, 6]];
  strokes = [[[0, 2], [1, 2]], [[1, 2], [1, 1]], [[1, 1], [1, 0]], [[0, 0], [1, 0]], [[0, 1], [0, 0]], [[0, 2], [0, 1]], [[0, 1], [1, 1]]];
  scale(size / 2) for (k = digits[n]) line(strokes[k][0], strokes[k][1]);
}
step("Glue the spacer onto the floor") {
  part("Floor", at = [0, 0, 0]) plate();
  part("Cavity spacer", at = [0, 0, t]) difference() {
    plate();
    translate([border, border]) rect([iw, id], r = 1);
  }
}
step("Set the tiles in the tray")
  for (i = [0:cells - 1]) if (values[i] > 0) part(str("Tile ", values[i]), at = location(i) + (i == moving ? (location(empty) - location(i)) * tile_slide : [0, 0, 0])) {
    rect([tile_size, tile_size], r = 1);
    if (numbers) score() translate([tile_size / 2, tile_size / 2]) {
      if (values[i] >= 10) {
        translate([-7, -5]) numeral(floor(values[i] / 10), 10);
        translate([1, -5]) numeral(values[i] % 10, 10);
      } else translate([-2.5, -5]) numeral(values[i], 10);
    }
  }
step("Bolt the clear retainer on, with thin washers for a little play")
  material(thickness = cover_thickness, name = "clear acrylic") part("Clear retainer", at = [0, 0, 2 * t + vertical_play]) difference() {
    plate();
    for (i = [0:cells - 1]) translate([location(i)[0] + tile_size / 2, location(i)[1] + tile_size / 2]) circle(d = tile_size * 0.64);
  }
```

Set power, speed and cut order in your laser software. See the [laser software guide](https://kerfscript.mylasertools.com/docs/compatibility/index.md).
