~learn.
0:00 / 1:32
LLD · Chess

A capture that lands on an empty square. Now undo it.

transcript

This pawn captures. But it lands on an empty square. The pawn it takes is beside it. Now try to undo that.

White's pawn walks up to e5. Black plays d7 to d5. A double step that skips d6. White captures en passant. It lands on d6, the skipped square. But the pawn it took was on d5. Three squares changed. Undo. The d5 pawn is back. And d6 is the en passant square again.

Store only what was captured? Undo puts it back where the move landed. That's d6. Wrong square. So undo stores where the captured piece stood. Not just what it was.

The rule: an undo record holds what a move destroys. The piece as it was. The captured piece, and where it stood. The old castling rights and en passant square.

Promotion, same story. A pawn plays a7 to a8. It becomes a queen. Undo puts a pawn back on a7. Not a queen. The record kept the piece as it was.

Legality checks, the undo button and perft use the same two methods. One en passant or promotion bug? Perft's published counts stop matching.

Don't reverse a move from what's left on the board. Store what the move destroyed. Then undo is exact.

Full breakdown in the lecture.