Workshop › Chess › Step 17 of 48
play(m) carries out a move: the piece goes to the target square (whatever stood there is captured), its old square
is emptied, the turn passes to the other side and the selection is cleared.
```js
const other = (color) => (color === 'w' ? 'b' : 'w')
function play(m) {
const [fr, fc] = m.from
const [tr, tc] = m.to
const piece = board[fr][fc]
board[tr][tc] = piece
board[fr][fc] = ''
turn = other(turn)
selected = null
targets = []
}
```other returns the opposite color.const [fr, fc] = m.from unpacks the start square into row and column; [tr, tc] the target.const inside = ... write other.const same = ... write play, with an empty line after it.Skills: Game states, Functions
← Show the targets Click a dot to move →