Workshop › Connect Four › Step 33 of 38

The computer's turn

What we are doing

Yellow is now the computer. When the turn passes to it, it waits half a second (30 frames), so you can see what happened, then plays computerMove(). thinking counts the frames down in update.

```js
let thinking // frames until the computer moves

  thinking = 0

    turn = 3 - turn
    if (turn === 2) thinking = 30

    return
  }
  if (!winner && turn === 2) {
    thinking -= 1
    if (thinking <= 0) play(computerMove())
  }
```

What it means

Your turn

  1. Under let hoverCol write let thinking; in reset, under falling = null, write thinking = 0.
  2. In land, under turn = 3 - turn, start the countdown.
  3. In update, add return at the end of the falling block and the countdown after it.

Skills: Game states, The game loop

All steps

  1. A dark background
  2. A drawing function
  3. The blue board
  4. One hole
  5. A whole row
  6. All 42 holes
  7. The board in memory
  8. Discs in their colors
  9. Draw every frame
  10. Where does the disc land?
  11. Play a column
  12. Taking turns
  13. Click to play
  14. The next disc
  15. Whose turn?
  16. Playing with the keyboard
  17. Keys 1 to 7
  18. A disc on its way
  19. Gravity
  20. Watch it fall
  21. Inside the board?
  22. Walking along a line
  23. Four in a row?
  24. We have a winner
  25. Circle the four
  26. Who won?
  27. A draw
  28. Play again
  29. Try a move and take it back
  30. Win, or block
  31. Don't help the player
  32. Prefer the middle
  33. The computer's turn
  34. Only on your turn
  35. You and the computer
  36. Counting wins
  37. Show the score
  38. Build it yourself: the loser starts