Sokoban Solver, Fewest Pushes

Paint

    Or paste a level as text: # wall, $ box, . goal, @ player, * box on a goal, + player on a goal, space for floor.

    How to use the Sokoban solver

    Paste a level in the standard text form, which most Sokoban sites and collections use, or paint one: pick Wall, Box, Goal or Player and tap or drag across the room. Press Solve. The solver finds the way with the fewest pushes, lists every push, and marks the path the player walks before each one. Step through with Forward and Back (or the arrow keys), or press Play to watch it. The search runs in the background, and Stop ends it.

    The rules of Sokoban

    The player walks around a warehouse and pushes boxes, one square at a time, by walking into them. A box can only be pushed, never pulled, and only if the square beyond it is free, so the player cannot push two boxes at once. The level is solved when every box sits on a goal.

    How the solver works

    It searches through positions of the boxes, counting pushes, and always looks first at the positions that could still lead to the shortest finish: each box needs at least as many pushes as its distance to the nearest goal. Before searching it marks the dead squares, corners and walls from which a box could never be pushed to any goal, and it never pushes a box onto one. It also never makes a square block of boxes and walls, which can never move again. Together these cut the search from millions of positions to thousands for most levels. Levels with many boxes in wide open rooms can still be too big to finish in a browser, and it says so.

    How it was checked

    The solver was run on all 110 levels of the daily Sokoban. On every one it found a solution with exactly the fewest pushes the daily page records, and every solution was replayed square by square under the plain rules to confirm it ends with each box on a goal.

    More puzzles

    There is a new daily Sokoban every day. The 15 puzzle solver searches for the fewest moves in the same way, and the water jug solver shows a shortest search on a smaller scale. For sliding and packing puzzles you hold in your hands, see our mechanical puzzles. There are more solvers on the puzzle tools page.

    Frequently Asked Questions

    How do you solve a Sokoban level?

    Find the boxes that can only go one way first, and never push a box into a corner or along a wall that has no goal: it can never come back out. Plan which goal each box will take, and leave yourself room to walk around behind each box before you push it.

    What are the rules of Sokoban?

    The player pushes boxes one square at a time by walking into them. Boxes cannot be pulled, and only one can be pushed at once. The level is solved when every box is on a goal.

    What does the text form of a Sokoban level mean?

    Each character is one square: # is a wall, $ a box, . a goal, @ the player, * a box already on a goal, + the player standing on a goal, and a space is floor. Most level collections share levels this way, and the solver reads it directly.

    Does the solver find the shortest solution?

    It finds the solution with the fewest pushes, which is how Sokoban solutions are usually compared. Among those it does not try to shorten the walking in between.

    Why can some levels not be solved here?

    Levels with many boxes in large open rooms have so many positions that searching them all takes far longer than a browser allows. The solver says when it stops without an answer.