My random sliding puzzle sometimes cannot be solved at all
Shuffling the tiles at random hands about half of the players a puzzle that no sequence of moves can finish, and they blame themselves. This entry shows the quick test that tells a solvable board from a stuck one for any board width, and a one-swap repair.
Why this works
Exactly half of all random shuffles can never be finished, and whether a board is one of them follows from a simple count of how out of order the tiles are. A tiny rule settles it without searching, and one swap turns a stuck board into a fair one.
When not to use it
It does not help for puzzles with other rules, such as tiles that rotate or wrap around the edge, where the count is different. If you build each board by making random moves from the finished picture, it is always solvable and needs no test.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 4 common mistakes and the fix
- 27 lines of example code with 4 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "My random sliding puzzle sometimes cannot be solved at all" (read_entry generated-sliding-puzzle-has-no-solution) in my game. Build it step by step, and show me how you checked that it works.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP