Undo in a game: reverse everything the move touched
transcript
Add undo to your game. Even after a win. What exactly must it reverse? More than the board. Miss one thing, and the bug shows up three moves later.
The mark on the board. That's the obvious one. The win checker's counters. Forget this, and a later win is miscounted. Then the status, the winner and the turn.
Now a trick. A bot wants to know: would this cell win? Place the mark on the board. Then ask the checker. Take it back. The state is now exactly as it was before. The bot never copied the board. It used undo.
No copy of the board. The same code as a real move. Forget half the undo, and the game corrupts silently. So always do both halves together, in a single method.
Undo is play, run backwards. Everything it touched. Get that right, and look-ahead comes free.
Full breakdown in the lecture.