Workshop › Chess › Step 35 of 48
En passant needs to know one thing from the last move: did a pawn just move two squares, and which square did it
skip? A double step is marked double: true; makeMove keeps the skipped square in enPassant for exactly one move,
and undo saves and restores it.
```js
let enPassant // the square a pawn could capture onto en passant right now, or null
enPassant = null
if (r === start && !board[r + 2 * dir][c]) add(r, c, r + 2 * dir, c, { double: true })
const undo = { m, piece, captured: board[tr][tc], castling: { ...castling }, enPassant }
if (m.castle === 'Q') [board[fr][3], board[fr][0]] = [board[fr][0], '']
enPassant = m.double ? [(fr + tr) / 2, fc] : null
castling = undo.castling
enPassant = undo.enPassant
```(fr + tr) / 2, in the same column.enPassant back to null, so the chance lasts one move.enPassant inside { ... } is short for enPassant: enPassant.Add the variable and its reset line, { double: true } on the two-square move, enPassant in the undo object, the
line in makeMove under the castling rook lines, and the restore line in undoMove.
Skills: Game states
← No castling through check En passant →