Undo/Redo in Card Games Without Writing Undo Logic
Most undo actions in games require writing precise and careful reverse actions for every move. In CentriFuGe I avoid all this by storing state snapshots of each move.
Hi world,
Having an undo feature in your card game is a very common and useful feature. It can help:
- Replay a match
- Save and load the game
- As a player, undo a mistake you just made
- As a developer, follow card interactions and debug different actions
An undo system sounds simple enough until you try to implement it.
The usual approach is to write a reverse action, which undoes everything the action performs. This can become brittle very quickly as more complexity is added to the game. This happens especially with the interaction-heavy style of more modern card games, which sport a wealth of different card effects and combinations. One missed interaction can completely break the game.
I didn’t want every move in CentriFuGe, my Card Game Framework, to require hand-written undo code. Instead, I’m choosing a system that is not only simpler, but also has further benefits.
