What is Klotski?
Klotski is a sliding block puzzle played in a box four cells wide and five cells tall, where you shuffle wooden blocks through the empty cells until the large 2×2 block can leave through the opening in the middle of the bottom edge. Blocks can never be lifted, only slid along the floor of the box.
The same puzzle has a story in every country. In China it is called Huarong Dao, after the narrow Huarong trail in the Romance of the Three Kingdoms where the defeated Cao Cao is trapped and Guan Yu lets him pass; the big block is Cao Cao and the long blocks are generals. In Japan it is Hakoiri Musume, the daughter in the box. The English name Klotski is usually traced to the Polish word klocki, meaning wooden blocks. Nobody knows for sure who invented it, but by the early twentieth century wooden versions were sold in many countries.
Here the blocks carry no characters. They are red lacquered wood with gold leaf borders and simple patterns: a gold seal on the big block, two diamonds on the tall blocks, three linked rings on the wide blocks and a four petal flower on the small ones.
What are the pieces and rules?
A block moves only up, down, left or right, and only into empty cells. No diagonal moves and no jumping over other blocks. You win when the top left cell of the big block reaches the middle of the second row from the bottom, right in front of the gate.
| Block | Size | Pattern |
|---|---|---|
| Big block (Cao Cao, the daughter) | 2×2, one | Gold seal. This is the one to get out |
| Tall block | 1×2 | Two diamonds |
| Wide block (Guan Yu) | 2×1 | Three linked rings |
| Small block (soldier) | 1×1 | Four petal flower |
| Empty cells | Usually 2, 4 on easy levels | The only space anything can move into |
How are moves counted?
Moving one block in one go counts as one move, however far it travels and even if it turns a corner. Moving the same block again straight after also merges into the same move.
This is the most common way to count Klotski moves, which is why the classic Heng Dao Li Ma layout comes out at the well known 81 moves. Counting every single cell step instead would push the same layout past 100. Undo takes back the whole last move and lowers the count by one.
How do I earn stars?
Your move count is compared with the fewest possible for that level: exactly the fewest gives three stars, up to 20% more gives two, anything else gives one. The star row under the board always shows what you can still earn.
| Stars | Condition | Heng Dao Li Ma (81 moves) |
|---|---|---|
| ★★★ | Fewest possible, no hints | 81 moves |
| ★★ | Within 120% of the fewest, or hints used | 82 to 97 moves |
| ★ | Escaped | 98 moves or more |
Using even one hint caps that level at two stars. A level finished by the auto solver is not recorded.
What is the fewest number of moves for each layout?
The 30 levels range from 3 to 138 moves, and every number was worked out by the built in solver checking every reachable position. Heng Dao Li Ma (81), Zhi Hui Ruo Ding (70), Bing Fen San Lu (72), Qi Tou Bing Jin (60) and Feng Hui Lu Zhuan (138) are classic Chinese layouts.
| Level | Name | Fewest moves |
|---|---|---|
| 1 | First Step | 3 |
| 2 | Open Gate | 5 |
| 3 | Corner Room | 8 |
| 4 | Three Ways | 11 |
| 5 | Empty Yard | 14 |
| 6 | Middle Path | 18 |
| 7 | Four Pillars | 21 |
| 8 | Twisted Alley | 24 |
| 9 | Row of Guards | 28 |
| 10 | Five Passes | 33 |
| 11 | Stone Wall | 36 |
| 12 | Crossbars | 40 |
| 13 | Surrounded | 44 |
| 14 | Double Doors | 48 |
| 15 | Narrow Gate | 52 |
| 16 | Stacked Bars | 56 |
| 17 | Hillside Path | 58 |
| 18 | Shoulder to Shoulder (Qi Tou Bing Jin) | 60 |
| 19 | Crossed Paths | 62 |
| 20 | Winding Road | 66 |
| 21 | Calm Command (Zhi Hui Ruo Ding) | 70 |
| 22 | Three Columns (Bing Fen San Lu) | 72 |
| 23 | Deep Fort | 75 |
| 24 | Blade and Horse (Heng Dao Li Ma) | 81 |
| 25 | Maze | 90 |
| 26 | Last Gate | 93 |
| 27 | Four Bars | 97 |
| 28 | Layered Guard | 120 |
| 29 | Long Road | 135 |
| 30 | Winding Peaks (Feng Hui Lu Zhuan) | 138 |
Feng Hui Lu Zhuan is known as one of the hardest layouts that can be made from one big block, three tall, two wide and four small blocks, and the solver confirms that no start with that set of blocks needs more than 138 moves. The standard Japanese Hakoiri Musume layout has the same shape as Heng Dao Li Ma, so it also takes 81 moves.
Any tips for solving Klotski?
- Keep the two empty cells together. A pair of adjacent gaps is what lets tall, wide and big blocks pass.
- Do not rush the big block down. Clear the gate area first, or the big block gets stuck halfway and has to climb back up.
- Use the small blocks as an engine. A 1×1 block fits anywhere, so it is the best tool for moving the gaps where you need them.
- Decide where the wide block goes. When it sits right under the big block, as in Heng Dao Li Ma, making room to move it aside is the first goal.
- Stuck? Take one hint. It shows the next move of a shortest solution from the current position, and you still keep two stars.
How do hints and the auto solver work?
A hint runs a breadth first search from the position on the board to the nearest escape and highlights its first move with a gold outline and an arrow. If you follow it, the next hint appears instantly without searching again.
Because the search looks at every possible position, following the hints always finishes in exactly the fewest remaining moves. Even the hardest level takes no more than a second or two on a phone.
Controls
- Phone and mouse: drag a block and it follows your finger into empty cells, then snaps to the nearest cell when you let go. Drag around a corner to make an L shaped move. A block with only one free side moves one cell with a single tap.
- Top buttons: ↶ undo, 💡 hint, ↺ restart, ≡ levels, 🔊 sound, ⌂ menu.
- Keyboard: Tab or Space picks a block, arrow keys or WASD slide it one cell, Z undo, H hint, R restart, Esc level list.
Names and move counts of the classic layouts follow the Chinese Huarong Dao tradition; the other level names were given by this game. Records are kept in this browser only and disappear if you clear its storage.