How the Klotski puzzle works
Klotski is one of the best-known sliding-block puzzles: a crowded tray, two empty squares, and one big block that has to escape through a narrow gap. This page explains the rules and the way moves are counted, where the puzzle comes from, how to think about it, and how a computer finds the shortest solution of every puzzle on PictorX.
The rules
The tray is 4 squares wide and 5 high, with a gap two squares wide in the middle of the bottom edge. Inside are one big 2 x 2 block, tall 1 x 2 and wide 2 x 1 blocks and small 1 x 1 blocks, which leave exactly two squares empty. A block can slide into free squares in any of the four directions, but it never lifts, turns or passes another block. The goal is to bring the big block to the gap, where it slides out of the tray.
Counting the moves
In the classic counting, one move is one block sliding any distance, including around a corner, as long as no other block moves in between. Counted that way, the traditional Forget-me-not start needs 81 moves at least, a figure that computer searches have confirmed. If every one-square step counted separately, the shortest solution would be more than a hundred steps. PictorX uses the classic counting, and moving the same block twice in a row is still one move.
A puzzle with many names
Puzzles with one big block that must escape through a gap became popular in the early 20th century. In France the puzzle is L'Âne Rouge, the red donkey; in China it is Huarong Dao, after a story from the Romance of the Three Kingdoms in which the general Cao Cao, the big block, escapes through the Huarong pass past the generals and soldiers of his enemies; in Poland and Russia it is known as Klotski, from the Polish word for wooden blocks. Collectors have catalogued hundreds of starting layouts.
Strategies that help
Think about the two empty squares rather than the blocks. Bringing the gaps together, side by side or one above the other, is what lets a long block or the big block move; spreading them out lets the small blocks shuffle around. Keep the small blocks near the big one, because they fill the holes it leaves behind. And do not be afraid to move the big block away from the exit: in Forget-me-not it has to travel sideways and back several times.
How the puzzles are solved and graded
Blocks of the same shape are interchangeable, so the computer writes each arrangement as one number that only records which shape covers which square. A breadth-first search lists every arrangement the blocks can reach, 25,955 for the classic set of blocks, and a second search back from the arrangements with the big block at the exit gives each one its fewest moves. Generated puzzles start at the distance the difficulty asks for: 10 to 25 moves on Easy, 26 to 50 on Medium, and the farthest arrangement found, 51 moves or more, on Hard.
Frequently asked questions
What is the hardest Klotski layout?
With the classic set of blocks, the farthest arrangement from the exit needs 93 moves. Other sets of blocks go deeper: some generated Hard puzzles here need well over 100 moves.
Why does the big block have to move away from the exit?
Because the two empty squares are never in the right place. To let the big block down, the blocks under it have to go up past it, and that only works when the big block steps aside and makes room for them.
How does the computer find the fewest moves?
It treats every arrangement of the blocks as a point and every move as a step between two points, then runs a breadth-first search from the arrangements where the big block is at the exit. The first time the search reaches a position, it has found the shortest way from there.
Are the classic layouts all solvable?
Yes. Every layout offered here was checked by the solver, which also gives its fewest moves: 81 for Forget-me-not, 72 for Three ways, 70 for Calm command and 60 for Side by side.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Play Klotski