Sokoban ("warehouse keeper") is simply a 1980s puzzle: push each container onto a goal. In this variant the keeper must also decorativeness connected a goal.
Moves: 0 Optimal: –
Keeper (you) Box Goal Box connected goal Wall
How to play & the rulesThe storage is simply a grid. On each measurement the keeper moves 1 quadrate up, down, near aliases right. The keeper cannot locomotion into a wall aliases a box. It can push a azygous box if the quadrate conscionable beyond the container (in the push direction) is quiet level aliases a goal. Only 1 box moves per step, and a container tin beryllium pushed out of a extremity again to make room.
- Controls: arrow keys aliases W A S D, aliases the on-screen pad. Undo steps back. Reset restores the board.
- Goal: the puzzle is won erstwhile every movable entity. Every box and the keeper. Is sitting connected a goal. That is why each committee has 1 much goal than it has boxes: the past extremity is for the keeper.
- Objective: scope that authorities successful arsenic fewer moves arsenic possible. For respective boards the optimal move count is known and shown above. The AI (with an admissible heuristic) returns an optimal solution connected the boards it tin hunt exhaustively.
Sokoban is an A* hunt problem, but a naive type that explores 1 keeper measurement astatine a clip explodes connected crowded boards. What runs present is a plain-JavaScript larboard of a autochthonal C++ optimal solver I wrote. It returns the provably fewest-moves solution, not conscionable immoderate solution:
- Move-optimal macro-push A*. Each hunt separator is simply a full box push costed arsenic (the keeper's shortest locomotion to the push spot) + 1, truthful the full is the existent minimum number of keeper moves, while the hunt skips complete the individual walking steps.
- Compact bitmask states. The boxes are packed into a 32-bit integer complete the board's reachable "live" cells and the keeper into 1 much number, truthful a full authorities is a azygous ~8-byte cardinal alternatively of a ~1 KB object. Millions of states fresh successful tens of MB.
- Dial bucket queue + open-addressed hash. The A* frontier is simply a bucket queue keyed by cost, and the visited group (with the solution's genitor links) lives successful a flat typed-array hash. Allocation-free and cache-friendly.
- Deadlock pruning. A fixed dead-square table (reverse-reachability from the goals) positive a freeze cheque discard provably-unsolvable positions, guided by a wall-aware push-distance little bound that keeps A* admissible (hence optimal).
Boards 1–14 are solved unrecorded to the proven optimum successful milliseconds (the move counts shown arsenic "Optimal" supra are precisely what this solver returns). Board 15. The 8-box maze. Is the exception: its optimal hunt explores ~49 million states and needs >1 GB, which would return acold excessively agelong to tally wrong a browser tab. So its optimum (184 moves) was computed offline by the autochthonal C++ build of this nonstop algorithm (a parallel A* search, ~5 s crossed 24 cores) and verified by replay, and the page simply plays that precomputed solution back. That is why committee 15's reply is hardcoded alternatively than searched here.
Built from my Sokoban solver. About Sokoban →
English (US) ·
Indonesian (ID) ·