Workshop › Chess › Step 36 of 48
When an enemy pawn has just stepped two squares past your pawn, your pawn may capture it as if it had moved one:
diagonally onto the skipped square. The captured pawn is not on that square but beside the moving pawn, so makeMove
removes it there and undo remembers it.
```js
if (enPassant && enPassant[0] === tr && enPassant[1] === tc) add(r, c, tr, tc, { ep: true })
const undo = { m, piece, captured: board[tr][tc], castling: { ...castling }, enPassant, taken: '' }
board[tr][tc] = m.promo ? piece[0] + m.promo : piece
board[fr][fc] = ''
if (m.ep) {
// The pawn taken en passant stands beside the moving pawn, not on the square it moves to.
undo.taken = board[fr][tc]
board[fr][tc] = ''
}
if (undo.m.ep) board[fr][tc] = undo.taken
```enPassant square is a capture even though it is empty; the move gets ep: true.fr, in the target column tc.undo.taken starts as '' and holds that pawn, so undoMove can put it back.enPassant line.makeMove, add taken: '' to undo, and under board[fr][fc] = '' write the if (m.ep) block.undoMove, under board[tr][tc] = undo.captured, write the restore line.Skills: Game states
← Remember the double step Checkmate and stalemate →