Learn by Building Workshop Skills GitHub Türkçe Workshop › Chess › Step 21 of 48
Bishops and queens What we are doing A bishop slides the same way, only diagonally; a queen is a rook and a bishop together. The slide code stays as it
is; only the list of directions changes.
```js
const DIAGONAL = [[1, 1], [1, -1], [-1, 1], [-1, -1]]
if (kind === 'R' || kind === 'B' || kind === 'Q') {
const dirs = kind === 'R' ? STRAIGHT : kind === 'B' ? DIAGONAL : [...STRAIGHT, ...DIAGONAL]
for (const [dr, dc] of dirs) {
```What it means
DIAGONAL lists the four diagonal steps.
The chained ? : reads: rook → straight, else bishop → diagonal, else (queen) → both.
[...STRAIGHT, ...DIAGONAL] spreads both lists into one new list of 8 directions.
Your turn
Under STRAIGHT write DIAGONAL.
Replace the if (kind === 'R') { line and the for line under it with the three new lines.
Skills: Arrays and objects
← The rook slides Pawns step forward →
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