Push every crate onto a ring — you can push, but never pull
← Back to Fun TimeThis game is split into small library files inside funtime/lib/, and every function has a comment saying exactly what goes in, what comes out, and the algorithm in plain English. Empty any function out, read its comment, and write it yourself.
| File | What it does | Good functions to try re-writing |
|---|---|---|
| lib/sokoban-rules.js | The rules: the levels, the pushing, the undo | isWall, boxAt, movePlayer, undoMove |
| lib/sokoban-draw.js | Painting the walls, the crates and the player | drawWall, drawBox, renderGame |
| lib/sokoban-main.js | The glue: the keyboard, the taps, the buttons | doAction, connectBoard, setUpGame |
💡 The big idea: a stack gives you undo for free. Before every move, save a copy of everything and pile it up. Undo takes the top copy off and puts it back. That is how the undo button works in every program you have ever used.
🛠️ Want to be walked through it? Build Sokoban Yourself takes you through the key functions one step at a time and tests each one you write. There is a Python version too.