Fix an undo button that forgets moves, ruins redo or eats memory
Puzzle players undo constantly. Saving the whole board each move gets heavy, a redo after a new move leads to nonsense, and an undo that does not exactly reverse the move is worse than none. This entry shows how to make the AI store only what changed.
Why this works
Undo is only trustworthy if it is the exact opposite of the move. Writing down what each cell was and what it became gives you that for free, with no special cases. And a redo only makes sense for the board it was made on, so a new move must end it.
When not to use it
Undo is the wrong thing to offer when the puzzle depends on irreversible choices or on tension, such as a game with permanent loss, or when the world also changes by itself in real time. There, offer a restart or a rewind to safe points instead.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 4 common mistakes and the fix
- A diagram of every state
- 39 lines of example code with 4 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "Fix an undo button that forgets moves, ruins redo or eats memory" (read_entry undo-button-breaks-or-uses-too-much-memory) in my game. Build it step by step, and show me how you checked that it works.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP