Workshop › Chess › Step 16 of 48
Show the targets
What we are doing
Draw a small see-through dot in the middle of each target square, after the board and pieces so the dots are on top.
```js
// A dot on every square the selected piece can move to.
ctx.fillStyle = 'rgba(15, 23, 42, 0.4)'
for (const m of targets) {
ctx.beginPath()
ctx.arc(LEFT + m.to[1] * SQ + SQ / 2, TOP + m.to[0] * SQ + SQ / 2, 9, 0, Math.PI * 2)
ctx.fill()
}
```
What it means
- For each move in
targets, m.to[1] is the column and m.to[0] the row; the same formula as the squares, plus
half a square, gives the center.
beginPath, arc(x, y, radius, start, end) and fill draw a filled circle; Math.PI * 2 is a full turn.
Your turn
In draw, after the two loops close (before the last } of draw), write the dot lines.
Skills: Drawing on a canvas
← Where can it go? Play a move →
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