My level solver returned « no solution within 4 moves » for a level I had built by hand to need exactly 4 moves. The solver was correct on 500 generated levels. The difference: this level required a piece to come back to where it started, after an invisible property of another piece had changed. My visited-state key did not include that property, so the solver treated the return as a revisit and pruned it.
TL;DR — If a puzzle has state that is not a position (a frozen flag, a lock counter, an opened door), the transposition-table key must encode it too, or iterative deepening will prune paths that pass through a « same board, different flags » state. Write one test level where the only solution revisits a position with a changed flag: it fails on a position-only key and passes on the full key.
The setup
A sliding-block puzzle on a 6×8 grid. A swipe moves a block as far as it can go in one direction; a block leaves the board through a door of its colour; the level is won when the board is empty. Solutions are 2 to 14 moves long. One twist, frost: a frozen block cannot be moved until another block slides into it, which thaws it permanently. Another twist, keys: a door stays shut while a designated key block is still on the board.
The solver is an iterative-deepening depth-first search (IDDFS) with a transposition table: a dictionary from state key to the largest remaining move budget already explored from that state. Arriving at a known state with an equal or smaller budget is pruned. The first key encoded, per block, its position or « gone »:
func key() -> int:
var k := 0
for id in ids:
var b = model.blocks.get(id)
var code := 0 if b == null else 1 + b.pos.x + b.pos.y * cols
k = k * (cell_count + 1) + code
return k
What I expected
Positions determine the board, the board determines the future, so two states with identical positions are interchangeable and pruning the second one is safe. That reasoning is exactly right for the base game, and the solver had already produced 500 levels whose recorded solutions replayed correctly.
What actually happens
Take a frozen red block F at the top of a column, its door directly above it, but shut until block H leaves. H sits below F, and H’s own door is on the left edge of H’s row. A wall cell under H stops it from sliding past its start row. The only solution has four moves: H slides up and thaws F; H slides back down to its start cell; H slides left and exits, which opens F’s door; F slides up and exits.
After move 2 the board looks exactly like the start: F at the top, H at the bottom. The only difference is F’s frozen flag. With a position-only key the start state was stored with budget 4, the return state arrives with budget 2, and the search prunes it. The 4-move solution is never found:
FAIL solver: returning to the start position after a thaw is a new state
unique 4-move solution (expected [[h, up], [h, down], [h, left], [f, up]], got [])

The fix
Fold every non-positional property into the key. For one boolean per block, double the alphabet: a block contributes 1 + cell when thawed and 1 + cell + cell_count when frozen, with base 2 * cell_count + 1. Exited blocks stay at code 0. Counters that derive from the positions, like « number of blocks that have left the board », need nothing: they are a function of which blocks are gone.
func key() -> int:
var base := 2 * cell_count + 1
var k := 0
for id in ids:
var b = model.blocks.get(id)
var code := 0
if b != null:
code = 1 + b.pos.x + b.pos.y * cols + (cell_count if b.frozen else 0)
k = k * base + code
return k
With a 7×9 grid the base is 127, so a 64-bit integer holds 9 blocks (127⁹ < 2⁶³); beyond that I fall back to a string key that spells out position and flag per block.
The test that catches the regression builds the level above and asserts the exact 4-move solution. It is the only test in the suite that fails with the old key, because every other level happens to have a shorter path that avoids the revisit.
Why it works
IDDFS with a transposition table is sound only if the key is a bijection onto the game state the rules can observe. The rules observe the frozen flag (a frozen block refuses to move), so two states that differ by it can have different futures; merging them lets the first-visited one, explored with a budget that was too small to reach the exit through the return path, veto the second. Including the flag makes the return a fresh state with its own budget. The same argument applies to any per-piece or per-door property the move resolution reads: locked counters, door open/closed, orientation.
This also explains why a large corpus of random levels does not protect you: random generators rarely produce levels where the only solution loops back through a visually identical board. My previous post on solver optimality, testing optimality, not just correctness, came from a similar false sense of coverage.
What I did not test
Whether the same key bug hides behind other twists in my game that I have not yet combined with a forced revisit, such as a door that opens then stays open. The Python mirror of the solver got the same fix and the same test; I did not measure the search-time cost of the larger key space, which was negligible on levels of at most 10 blocks.
Facts
context: IDDFS puzzle solver with a transposition table keyed per block on position or "exited"
problem: a level whose only solution returns to the start positions after a hidden flag changed was reported unsolvable because the return state was pruned as a revisit
solution: encode every property the move rules read (frozen flag, lock state, door state) into the state key; keep one test level that forces a flagged revisit
verified_on: 2026-09-06
applies_to: [any depth-first or BFS solver with a visited set, GDScript and Python implementations]
does_not_apply_to: [games where all state is positional and no hidden per-piece property exists]