Workshop › Chess › Step 47 of 48
Now clicks are only for white: nothing happens on the board while the computer thinks, and only white pieces can be
picked up. The messages speak to you: Your move (white), Computer is thinking..., and who won.
```js
function clickSquare(r, c) {
if (state !== 'playing' || turn !== 'w') return
if (board[r][c][0] === 'w') {
let message = turn === 'w' ? 'Your move (white)' : 'Computer is thinking...'
if (state === 'playing' && inCheck(turn)) message = 'Check! ' + message
if (state === 'checkmate') message = (turn === 'w' ? 'Checkmate: the computer wins.' : 'Checkmate: you win!') + ' Click to play again'
```clickSquare returns at once when the game is over or it is black's turn.'w' pieces can be selected now, whatever turn says.turn is the mated side: if it is white, the computer won.clickSquare, extend the first if with || turn !== 'w' and change turn to 'w' in the selection if.draw, change the first message line and the checkmate line.Skills: Keyboard and mouse input, Game states
← The computer plays black Build it yourself: the fifty-move rule →