
I Built a Procedural Sokoban Generator in One Day. Here's Why It Kept Making Unsolvable Levels.
Sokoban level generation is a solved problem. Taylor & Parberry published the backward simulation algorithm in 2011. The idea is elegant: start from a solved configuration (all boxes on goals), apply legal reverse pushes, and you get a playable puzzle. You can't generate an invalid level because you start from a valid one. Except you can. And we did. Repeatedly. Here's what we found building Sokobot — a procedural Sokoban generator that runs in a single 522-line HTML file. How Backward Generation Works A standard Sokoban move pushes a box: player steps into the box's position, box moves one cell ahead. The reverse is a pull : box moves toward the player, player moves away. If you apply N random legal pulls starting from a solved state, you get a scrambled-but-solvable puzzle. // Simplified backward step function backwardStep ( grid , playerPos , boxes , W , H , rng ) { const dirs = [[ 0 , - 1 ],[ 0 , 1 ],[ - 1 , 0 ],[ 1 , 0 ]]; shuffle ( dirs , rng ); for ( const [ dx , dy ] of dirs )
Continue reading on Dev.to JavaScript
Opens in a new tab



