Show HN: Sokoban AI Solver
TL;DR Highlight
An A* solver in plain JavaScript finds optimal Sokoban solutions in milliseconds inside the browser.
Who Should Read
A backend or frontend developer who wants to solve state-space problems efficiently with classic search like A* in the age of LLMs.
Core Mechanics
- It's called AI, but it's A* search, not an LLM
- The optimal Sokoban solver is built as an A* search problem.
- A native C++ optimal solver was ported to plain JavaScript and runs in the browser.
- One box push is one search step
- Edge cost is the keeper's shortest walk to the push spot plus 1.
- Walking steps are skipped in the search, yet the total move count is the true minimum.
- States are packed into a few integers
- Boxes fit in a 32-bit integer over reachable cells, and the keeper is one more number.
- A state is a ~8-byte key instead of a ~1 KB object, so millions of states fit in tens of MB.
- The queue and hash avoid allocations
- The A* frontier is a bucket queue keyed by cost.
- The visited set and parent links live in a flat typed-array hash.
- Deadlock pruning keeps A* optimal
- A dead-square table comes from reverse reachability from the goals.
- A freeze check discards unsolvable positions.
- A wall-aware push-distance lower bound keeps the heuristic admissible.
- Only board 15 replays a precomputed answer
- The 8-box maze needs ~49 million states and more than 1 GB, too much for a browser tab.
- Its optimum of 184 moves was computed by native C++ parallel A* in ~5 s on 24 cores and verified by replay.
- Boards 1-14 are solved live to the proven optimum in milliseconds.
Community Reactions
- A fan of the classic meaning of AI
- One commenter said old techniques like expert systems, A*, and SAT may feed into the next AI breakthrough.
- They also floated constraining LLM output with classic AI methods.
- Suggestions that board 15 could run in-browser
- Commenters suggested WASM to speed it up.
- They suggested storing the keeper's whole reachable region in the state, or trying BFS.
- They also pointed to pruning techniques from state-of-the-art Sokoban solvers.
- Criticism: behind SOTA solvers, easy examples
- One commenter said it lags several available SOTA Sokoban solvers and only handles small, simple levels.
- Another wanted harder examples with many trap dead states.
- Hands-on experience and rule differences
- One player found that a first move they had ruled out on board 12 was the optimal one.
- They also saw the solver beat their own move count from their starting position.
- Another noted the rules differ from original Sokoban because the keeper must also end on a goal.
How to Apply
- Turn one of your search states into a bitmask key
- Pick one search state you currently keep as an object or JSON.
- Pack it into an integer key and compare Map memory and speed.
- Use meaningful actions as edges instead of single steps
- In workflow or pathfinding code, collapse pointless intermediate steps into one edge.
- Sum the intermediate costs so optimality is preserved.
- Add a classic search validator after LLM output
- Check an agent's plan for validity with A* or constraint checks.
- Precompute a dead-state table to prune.
- Precompute heavy searches offline and replay them
- Solve cases that the browser can't handle offline and store the result.
- Make the client only replay the stored solution.
Try It
# Paste into Claude or ChatGPT as-is (simplified version of the article's method)
You are a Python developer. Write a small optimal Sokoban solver in under 30 lines using this approach.
- Search unit: one box push (macro-push). Cost = BFS shortest walk of the keeper to the push spot + 1
- State: (frozenset of box positions, keeper position)
- Heuristic: sum of Manhattan distances from each box to its nearest goal (admissible)
- Deadlock: prune cells unreachable by reverse pulling from the goals
- Rules: win when every box and the keeper are on goals; goals = boxes + 1
Board:
{{paste the board using # wall, $ box, . goal, @ keeper}}
Next to try: compare the number of expanded states against step-by-step BFS on the same board.Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques