Sokoban AI Solver: Why This Simple Game Is Such a Headache for Computers

Sokoban is a PSPACE-complete AI classic, solved via A* search, heuristics, and deadlock pruning.
Sokoban may look simple, but it is a PSPACE-complete problem whose state space grows exponentially with level size, and whose irreversible deadlocks make brute-force search completely infeasible. Top solvers use A* or IDA* as their search core, guided by carefully designed heuristics such as Manhattan distance and minimum-cost matching, combined with deadlock detection, tunnel macros, and Zobrist hashing to compress the search space. Sokoban has also been adopted by organizations like DeepMind as a benchmark for testing long-term planning in reinforcement learning agents, reflecting its enduring relevance to general AI research.
Introduction: A Problem That Looks Simple but Isn't
Sokoban is a classic puzzle game that originated in the 1980s. Players control a character who pushes boxes around a warehouse to designated target positions. The rules are simple enough that almost anyone can grasp them instantly: boxes can only be pushed, never pulled, and you can only push one box at a time. Yet this deceptively simple game has earned a well-deserved reputation in AI and algorithms research as one of the toughest nuts to crack.
Recently, a developer shared their Sokoban AI Solver project on Hacker News, sparking lively discussion in the community. The project once again drew attention to this classic algorithmic challenge: why is a game that children can play so extraordinarily difficult for computers?
Why Sokoban Is a Classic Hard Problem in AI
Computational Complexity: The PSPACE-complete Abyss
From a computational theory perspective, the Sokoban problem has been proven to be PSPACE-complete. This means its difficulty is theoretically at least on par with some of the hardest known search problems — in certain respects even more intractable than typical NP-complete problems.
The crux of the issue is the exponential explosion of the state space. In a warehouse level, each box can occupy multiple positions, and the player character can also be in many different locations. As the number of boxes and the size of the map increase, the number of possible game states grows exponentially. Even a moderately sized level can have an astronomically large state space, making brute-force enumeration completely infeasible.
The Irreversible "Deadlock" Trap
What makes Sokoban particularly devious is irreversibility (deadlocks). Since boxes can only be pushed and never pulled, once a box is pushed into a corner or certain specific positions, it can never be moved again. These situations are called deadlocks.
This poses an enormous challenge for search algorithms: the algorithm must not only find a path to the goal, but also identify in advance and avoid moves that lead to unsolvable states. Without deadlock detection, a solver wastes enormous amounts of time exploring branches that are doomed to fail.
Core Search Algorithms in Sokoban Solvers
A* and IDA*: The Mainstream Search Strategies
The vast majority of Sokoban solvers are built on state-space search. Common approaches include:
- Breadth-First Search (BFS): Guarantees finding the solution with the fewest moves, but consumes enormous memory.
- A Search Algorithm*: Uses a heuristic function to guide the search direction — the mainstream choice for solvers.
- IDA (Iterative Deepening A)**: Performs better under memory constraints, and is the preferred method for many high-performance Sokoban solvers.
Heuristic Functions: The Key to Solver Quality
The design of the heuristic function directly impacts solving efficiency. Commonly used heuristic strategies include:
- Computing the sum of Manhattan distances from all boxes to their nearest target positions
- Using minimum-cost bipartite matching to pair boxes with targets, providing a more accurate estimate of the minimum remaining moves needed
A good heuristic function must be precise enough to guide the search effectively, yet not so computationally expensive that it slows the overall process down.
Deadlock Detection and Pruning Optimization Strategies
High-quality solvers integrate multiple pruning techniques to reduce the search space:
- Deadlock Detection: Pre-computes which cells in the map are "dead squares" — if a box is pushed into one of these cells and it isn't a target, that branch is immediately abandoned.
- Tunnel Macros: Identifies corridor structures in the map and merges consecutive pushes into a single operation.
- State Deduplication: Uses hash tables to record previously visited states (typically via Zobrist hashing), avoiding redundant computation.
These optimization techniques can often improve solving speed by several orders of magnitude, and are the deciding factor in whether a solver can tackle complex levels.
Lessons from Sokoban for General AI
A Touchstone for Reinforcement Learning and Planning
Notably, Sokoban has in recent years been incorporated into reinforcement learning and planning research. Organizations like DeepMind have used Sokoban as a benchmark environment for testing an agent's planning capabilities — because it demands lookahead reasoning. One wrong move can render the entire puzzle unsolvable, which is precisely the kind of core capability required for general artificial intelligence.
An Excellent Practice Project for Developers
For developers, writing a Sokoban solver is an excellent hands-on project for learning search algorithms and optimization techniques. It spans a wide range of topics — from foundational graph search and heuristic design to advanced pruning strategies and memory management — making it a comprehensive workout for algorithmic engineering skills.
In this sense, a small Sokoban solver actually touches on a much grander proposition in AI: how to enable machines to make correct long-term decisions in irreversible environments with enormous state spaces.
Conclusion
The Sokoban AI Solver project reminds us that classic problems never lose their value. In today's world filled with the noise of large language models and generative AI, returning to the fundamentals of computer science — search algorithms and heuristic design — can give us a much deeper understanding of what "intelligence" truly means. For any developer looking to strengthen their algorithmic foundations, building a Sokoban solver from scratch is a challenge well worth taking on.
Related articles

Remote Compose: A New Document-Driven Paradigm for Cross-Platform UI on Android
Remote Compose transmits compact binary documents instead of screen pixels, enabling efficient UI rendering on remote surfaces like Wear OS and widgets. This article covers its document creation API, expression animations, size optimization techniques, and Wear OS progress.

How Crashlytics Eliminates Android Memory and Responsiveness Issues
Through the Chroma Clip case study, this article explains how Firebase Crashlytics uses Application Exit Info, Profiling Manager, GWP ASAN, and ARM MTE to pinpoint ANRs, OOMs, memory limit terminations, and native memory corruption—solving the challenge of stack traces that don't point to the real culprit.

Googlebook's First Developer Case Studies: How Notability and Logitech Built Desktop-Class Android Experiences
Notability and Logitech share first-hand experience building for Googlebook: using Jetpack Compose, Navigation 3, and Jetpack Ink for desktop-class Android, plus how the peripheral customization API bridges hardware and OS.