Crate puzzles forged by playing backward from the goals, then solved by A*.
Each level starts solved: crates on their goals. A pull undoes a push, so a breadth-first search over pulls, starting from every spot the robot could finish in, labels every layout it reaches with the exact number of pushes needed to solve it. The farthest layout with every crate off its goal becomes the level, so it is solvable by construction and its par is known. The forge tries six rooms and several goal placements each and keeps the hardest, and you watch the robot pull the crates out to build it. Then A* solves it forward with a crate-to-goal assignment heuristic, pruning pushes into dead squares (hatched) and 2x2 freeze deadlocks; its answer has to match the par, and the floor glows where its search spent time.
Try it. Arrow keys or WASD move the robot along the grid and push crates, or click a tile to walk there and click a crate next to the robot to push it. Solve (Space) plays the optimal pushes from wherever you are, Hint (H) marks the next optimal push, Undo (Z), Restart (R), and New level (N) forges another. Pushing a crate into a deadlock gets a warning.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build a crate-pushing warehouse puzzle (in the style of Sokoban) that generates its own levels and solves them, using JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.
Start simple:
- Hard-code one small level as an array of strings: # wall, . goal, $ crate, @ player, space floor. Draw it as a top-down grid on a canvas that fills the window and stays sharp on high-DPI screens.
- Arrow keys move the player. Walking into a crate pushes it if the cell behind it is free. Add undo (Z) and restart (R), and show a message when every crate is on a goal.
- Write a solver: a state is the crate positions plus the region the player can walk to (store the smallest reachable cell to stand for the region). From a state, every push the player can reach is a move. Use breadth-first search over pushes, then animate the solution: walk to each push, then push.
- Precompute dead squares, cells from which a lone crate can never be pushed onto any goal, and never push a crate onto one.
Once that works, make it generate levels:
- Carve a random room, put the crates on random goals, and search backward: a pull (player steps back and drags a crate) undoes a push. Breadth-first search over pulls labels each layout with how many pushes it needs. Pick the farthest one where every crate is off its goal. It is solvable by construction.
- Switch the solver to A* with the sum of each crate's push distance to its nearest goal as the heuristic, and check that it agrees with the generator's count.
- Draw it in isometric projection with brick walls, wooden crates and a little robot, sorted back to front.
Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as freeze deadlock detection, a better heuristic from crate-to-goal matching, or animating the reverse play that built each level.