View: Multi-Page Single Page

Generating Puzzles

Every dial, what it changes, and what each mode is good at.

The Generate window

Window ▸ Living Failure ▸ Simple Klotski ▸ Puzzle Generator. Settings on the left, the result set on the right. Generation runs on a background thread, so a batch of heavy boards never freezes the editor — you get live progress ("Board 3/10 · attempt 47") and a Cancel button.

Every dial is remembered across recompiles and play-mode reloads, including the unsaved batch, so an experiment survives a script change.

Shared dials

  • Mode — Gridlock, Klotski, Clear, Clear 3D or Clear Snakes. The last two are Clear underneath: same solver, same guarantees, different pieces. Picking a mode resets the dials belonging to the others, so a recipe never carries hidden leftovers.
  • Board width / height3–16 a side for flat Clear boards (including Clear Snakes), 3–8 for everything else. Width and height are independent, so 10×14 and 16×3 are as valid as 8×8.
    The split is measured, not arbitrary: flat Clear is a dependency graph and costs 0.2–0.9 ms a board at any size, while the sliding modes search a state space and already take about 6 seconds a board (Gridlock) and 23 (Klotski) at 8×8. Their cap is there to protect you, not the data.
  • Pieces — how many blocks to place; 0 means "auto for this mode and board". In Clear, a non-zero count overrides the Fill dial.
  • Obstacles — static blocked cells (see below).
  • Checkpoints — pressure plates, Gridlock and Klotski only.
  • Seed / Random — a seed reproduces a board exactly. Leave Random on while exploring; type a seed to get a specific board back.
  • Batch count — how many boards per click, appended to the set.
  • Max attempts (Advanced) — how hard the generator tries before returning its closest near-miss.

Difficulty & windows

Two ways to ask for difficulty, and they cooperate:

  • Target difficulty (0–5★) — moving the slider snaps the move window to that star's band for the current mode. 0 means "any".
  • Min / Max moves — the window itself, always editable. A board is accepted only if its proven par lands inside it.

In Clear the window measures chain depth instead of moves, because every Clear board takes exactly one tap per block — the interesting number is how many blocks must leave before the most buried one can.

The star bands, for reference:

  • Gridlock — 1★ ≤4 moves, 2★ ≤8, 3★ ≤13, 4★ ≤19, 5★ 20+.
  • Klotski — 1★ ≤10, 2★ ≤25, 3★ ≤45, 4★ ≤70, 5★ 71+.
  • Clear — by chain depth: 1★ ≤2, 2★ ≤3, 3★ ≤5, 4★ ≤7, 5★ 8+.

Auto sets a window that the current mode and board size hit reliably — a good starting point before you tighten it.

Gridlock

The parking-lot / traffic-jam genre: a lot full of vehicles that can only roll along their own axis, one of them yours, and a gap in the wall to escape through.

The rules. A block's shape sets its axis — wide blocks slide left/right, tall ones up/down, single squares either way. The hero sits on the exit lane, and you win by sliding it flush against the exit opening.

How boards are built. The hero is placed with a bias toward the far end of its lane (so the puzzle isn't "drive out"), traffic is packed to a density that leaves the board tight but legal, and any layout whose hero lane is already clear is vetoed outright. The solver then measures the true par.

Getting hard boards. Windows above roughly 12 moves are where the brain-burners live. Give it room: a 6×6 board and 300+ attempts. Small boards simply do not contain 5★ puzzles, and the report will tell you when it fell back.

Klotski

The classic wooden sliding-block puzzle — the Huarong Dao family, sold under many names for a century. A dense board, one big hero block, and a target it must reach.

The rules. Every block slides freely in any direction, as far as space allows. There is no exit — you win when the hero's top-left cell sits on the marked target.

Depth engineering. This mode builds boards backwards: it starts from the solved position, maps the whole reachable space, and picks a starting layout at the distance you asked for. Then the forward solver re-proves the par independently. That is how a "60-move puzzle" request produces an actual 60-move puzzle.

Hero size. 2×2 is the classic; 1×2 or 1×1 heroes slip through gaps and give shallower boards. The dial caps at 2 per side — a 3-wide hero needs three aligned free cells to move at all, which dense boards essentially never offer.

Klotski is the heavy mode: roughly 0.2–1 second per board, since each candidate is fully searched. Batches of 10 are comfortable; batches of 100 want a coffee.

Clear

The arrow block-clearing genre: every block wears an arrow, a tap sends it flying off the board that way, and blocks in its path stop it. Clear the lot.

Solvable by construction. Boards are built from a witness removal order: the generator schedules the blocks one at a time, only ever giving a block a direction whose path crosses blocks that leave earlier. That schedule is a proof the board can be emptied.

Monotone — no dead ends, ever. Removing a block can only unblock others, never block them. So a solvable Clear board cannot be played into a stuck state, no matter what order the player taps. That is a property of the mode, proven once, not something each board has to be checked for.

Two looks from two dials:

  • Max piece length 1 + high Fill — the packed arrow-grid look, single cells edge to edge.
  • Max piece length 2–3 at moderate Fill — the parking-lot look, with long vehicles among the singles.

Fill is the fraction of cells covered: 0.6 is airy, 1.0 is packed solid. Leave Pieces at 0 or it overrides Fill and you keep the gaps.

Clear 3D

The same law, one dimension up: a lattice of blocks with arrows in six directions, which the player orbits, pans and zooms around, peeling it apart.

  • Board depth — 1 keeps the flat board; 2–8 makes a lattice.
  • Fill 1.0 gives the solid-block look; lower values leave interior gaps (invisible from outside, and they make interesting escape channels).
  • Piece budget — a lattice caps at 63 blocks. The window warns you before generating when the volume you asked for cannot be covered by that many blocks; sizes like 4×4×4, 6×6×3 and 8×8×2 pack solid comfortably.

Obstacles and checkpoints are not available in 3D — a lattice shapes itself by which cells hold blocks.

Reading a 3D solution. Steps name a block by grid reference and layer — B3 L0 is column B, row 3, layer 0. Columns run A–H across and rows 1–8 down, and the slice diagrams below the list carry the same headers, so a step is read off the picture rather than decoded from a pair of numbers. Layer 0 is the top of the structure, which is why 3D directions are worded up (out the top) and down (out the bottom) instead of in and out.

Clear Snakes

The same law again, tangled: a piece is a rope of cells bent into an L, a U or a long snake, carrying a single arrowhead. Tap it and it slithers out head first along its own body — every segment following into the cell the one ahead just left.

Only the lane ahead of the head has to be clear. A rope's body moves through cells the rope already occupied, so the only cells it needs from anyone else are the ones directly in front of its head — a single lane, however much the body winds. That is what makes a board of interlocking ropes solvable at all.

Everything Clear promises still holds: boards are built from the same witness removal order, so they are solvable by construction and monotone — no dead ends, ever.

  • Snake ratio — the share of pieces grown as ropes rather than straight cars. 0 is an ordinary Clear board; 1 makes a rope of every piece that can be one. It is a ratio rather than a cap because placement takes whatever fits, and a straight piece fits more often — an "allow up to N bends" ceiling would leave ropes rare however high you set it.
  • Max length — the longest rope, as a multiple of (width + height). Proportional on purpose: six cells is most of a 4×4 and a modest squiggle on a 16×16, so an absolute count would mean something different on every board and presets would not travel. 0 = auto (0.4).
  • Bendiness — 0 grows ropes that run straight and turn only when boxed in; 1 turns wherever it can. This shapes the rope; it does not cap how many bends one may have.

Ropes are what make big boards work. A board holds at most 63 pieces, so covering a 16×16 needs about four cells each — more than a car (max 3) can reach, and easily within a rope's range. Measured on a packed 16×16: 32 ropes covering all 256 cells. The same board built from single tiles runs out of pieces a third of the way in, and says so.

Ropes and rectangles mix freely on one board, because a rope board is a Clear board. A single pack can hold plain arrow grids, cars and snakes together — useful for a difficulty ramp.

Obstacles & checkpoints

Obstacles are permanently blocked cells. They are scattered by a distribution scorer (the same one used across the Living Failure puzzle assets) that penalises clumping, so they read as designed walls instead of a random dusting. Gridlock additionally refuses to drop one in the hero's escape lane.

Checkpoints are pressure plates: the win condition becomes "the hero is home and every plate is covered by some block". The solver treats that as one conjoined condition, which has a nice consequence — a non-hero block settling the last plate can be the winning move, and the par accounts for it. Plates are placed away from the hero's start and its lane ahead, and the generator verifies they are coverable.

On dense boards, plates are often covered incidentally. The generator reports how many boards had plates that actually changed the par, so you can dial up their count when you want them to bite.

Presets

Full recipes, not just a mode switch — each sets size, window, attempt budget and any mode dials it needs:

  • Gridlock — easy lot 6×6 · brain-burner 6×6 · walled lot 6×6 · plates & doors 6×6
  • Klotski — classic deep 4×5 · monster 4×5 (90+ moves)
  • Clear — parking lot 6×6 · arrow grid 7×7 · deep chains 7×7 · big lot 12×12 · wide letterbox 14×8 · walled lot 8×8
  • Clear 3D — tap cube 4×4×4 · box 6×6×3 · slab 8×8×2
  • Clear Snakes — tangle 10×12 · gentle bends 8×8 · mixed with cars 9×9 · full board 16×16

Batches & saving

Set Batch count and press Generate; boards append to the set and the pager walks them. Only unique filters the view to single-solution boards, and ✕ drops a board you don't want.

Save offers three shapes: the current board as a KlotskiPuzzleAsset, the whole set as a KlotskiPuzzlePack, or only the unique boards as a pack. Saving uses Unity's own in-project save dialog, so assets always land somewhere valid.

Limits, honestly

  • Unique boards are scarce. Require unique hunts for boards with exactly one shortest solution (or, in Clear, one valid removal order). They exist, but not on every size — expect fallbacks, and read the report.
  • Order counts stop at 16 blocks. Clear counts removal orders exactly by subset dynamic programming up to 16 blocks; beyond that the count is astronomically large and simply not computed. The board is still fully verified — this only means Require unique can't be checked above 16.
  • High star bands need room. A 4×4 board has no 5★ puzzle in it. The generator returns its closest board and marks the result as a fallback rather than pretending.
  • Search budgets are reported. If a board is so tangled that the search hits its state budget, you are told — the par may be proven while the solution count is left incomplete, and Require unique refuses to trust it.
  • A board holds at most 63 pieces. Every piece carries a bitmask of what blocks it, and that mask is 64 bits wide. On a large board packed with single cells the ceiling is reached before the board is full — generation says so rather than quietly handing back a third-empty board: "Piece budget reached (63 max): 84 of 256 cells left empty. Raise Max piece length or Snake ratio to cover a board this size." Longer pieces and ropes cover the same area with fewer of them.
  • Bigger is not harder for the sliding modes. A larger Gridlock or Klotski board gives pieces more room, which makes them easier, not harder — and the search grows sharply. That is why those modes stop at 8×8 while flat Clear reaches 16.

Generating from code

The window is a front end for plain C#. Anything it does, you can do at runtime:

var s = new GenerationSettings {
  Mode = KlotskiMode.Gridlock, Width = 6, Height = 6,
  MinMoves = 8, MaxMoves = 20, ObstacleCount = 2,
  MaxAttempts = 300, Seed = "level-12"
};
var puzzle = GridlockGenerator.GenerateVerified(s);
Debug.Log($"par {puzzle.MinMoves}, {puzzle.Difficulty}/5, matched {puzzle.Report.Matched}");

A rope board is the same call with three more dials — snakes are Clear, so there is no separate generator to reach for:

var s = new GenerationSettings {
  Mode = KlotskiMode.Clear, Width = 16, Height = 16, ClearFill = 1f,
  SnakeRatio = 1f, SnakeMaxLength = 0.6f, SnakeBendiness = 0.6f,
  MinMoves = 4, MaxMoves = 24, Seed = "ropes-1"
};
var board = ClearGenerator.GenerateVerified(s);
bool rope = board.IsSnake(0);  // body cells live on the puzzle

For a whole batch, or for anything running inside a live game, KlotskiBatch picks the generator for you and can run off the main thread — which is what the demo does behind its loading bar:

var boards = await KlotskiBatch.GenerateAsync(s, 10, p => _progress = p.Fraction);

Progress is reported per attempt rather than per board, so a bar keeps moving through a hard one — but the callback arrives on the worker thread, so store the value and read it back on the main thread.

See the API Reference for the full surface.