Workshop › Chess › Step 32 of 48
The rook jumps over
What we are doing
In a castling move the rook jumps to the other side of the king: from column 7 to 5, or from 0 to 3. makeMove moves
it and undoMove puts it back.
```js
board[fr][fc] = ''
if (m.castle === 'K') [board[fr][5], board[fr][7]] = [board[fr][7], '']
if (m.castle === 'Q') [board[fr][3], board[fr][0]] = [board[fr][0], '']
board[tr][tc] = undo.captured
if (undo.m.castle === 'K') [board[fr][7], board[fr][5]] = [board[fr][5], '']
if (undo.m.castle === 'Q') [board[fr][0], board[fr][3]] = [board[fr][3], '']
```
What it means
[a, b] = [x, y] assigns two places at once: the rook's new square gets the rook, its corner gets ''.
- The king's row is
fr, the same for both pieces.
undoMove does the same the other way round.
Your turn
- In
makeMove, under board[fr][fc] = '', write the two rook lines.
- In
undoMove, under board[tr][tc] = undo.captured, write the two lines that put it back.
Skills: Game states
← Castling moves Losing the right to castle →
All steps
- A dark table
- One row of squares
- All 64 squares
- The starting position as text
- Color and kind
- Draw the pieces
- An outline for white
- Draw again and again
- The knight's jumps as data
- A list of moves
- The king steps too
- Which square was clicked?
- Light up the selected square
- Whose turn is it?
- Where can it go?
- Show the targets
- Play a move
- Click a dot to move
- Say whose turn it is
- The rook slides
- Bishops and queens
- Pawns step forward
- Pawns capture diagonally
- A pawn becomes a queen
- Is a square attacked?
- Attacks from far away
- Is the king in check?
- A move that remembers
- Take a move back
- Only legal moves
- Castling moves
- The rook jumps over
- Losing the right to castle
- No castling through check
- Remember the double step
- En passant
- Checkmate and stalemate
- Check! and the result
- Click to play again
- Show the last move
- A score for a position
- Thinking ahead
- Pick the best move
- Alpha-beta: skip what cannot matter
- Try the best-looking moves first
- The computer plays black
- You are white
- Build it yourself: the fifty-move rule