Workshop › Chess › Step 4 of 48

The starting position as text

What we are doing

The board needs data: what stands on each square. We write the starting position the way chess players do, one text per row, and turn it into board: an array of 8 rows, each an array of 8 letters.

```js
// Row 0 is black's back rank at the top, row 7 white's at the bottom. Capitals are white.
const START = ['rnbqkbnr', 'pppppppp', '........', '........', '........', '........', 'PPPPPPPP', 'RNBQKBNR']

let board // board[row][col]: '' or a color and a kind, like 'wN' or 'bQ'

function reset() {
  board = START.map((line) => [...line])
}

reset()
draw()
```

What it means

Your turn

  1. Under the TOP line write START, board and reset (with the empty lines).
  2. Above the draw() call at the bottom write reset().

Skills: Arrays and objects

All steps

  1. A dark table
  2. One row of squares
  3. All 64 squares
  4. The starting position as text
  5. Color and kind
  6. Draw the pieces
  7. An outline for white
  8. Draw again and again
  9. The knight's jumps as data
  10. A list of moves
  11. The king steps too
  12. Which square was clicked?
  13. Light up the selected square
  14. Whose turn is it?
  15. Where can it go?
  16. Show the targets
  17. Play a move
  18. Click a dot to move
  19. Say whose turn it is
  20. The rook slides
  21. Bishops and queens
  22. Pawns step forward
  23. Pawns capture diagonally
  24. A pawn becomes a queen
  25. Is a square attacked?
  26. Attacks from far away
  27. Is the king in check?
  28. A move that remembers
  29. Take a move back
  30. Only legal moves
  31. Castling moves
  32. The rook jumps over
  33. Losing the right to castle
  34. No castling through check
  35. Remember the double step
  36. En passant
  37. Checkmate and stalemate
  38. Check! and the result
  39. Click to play again
  40. Show the last move
  41. A score for a position
  42. Thinking ahead
  43. Pick the best move
  44. Alpha-beta: skip what cannot matter
  45. Try the best-looking moves first
  46. The computer plays black
  47. You are white
  48. Build it yourself: the fifty-move rule