0

I am using the code.org AppLab, and trying to make a game of Tic-Tac-Toe. Currently I have it so the computer will randomly choose a location from the available places, but I am trying to make it more difficult. What would be the best way to have the computer make more intelligent decisions when choosing moves?

I tried using a series of else if statements to check each square, but that didn't work continuously.

  • 1
    You can look at a YouTubr video about this. YouTube has hundreds of this. Example [here](https://m.youtube.com/watch?v=JTZz72q35WA). – 0x01010 Apr 18 '23 at 15:53

1 Answers1

0

The way to implement a computer player for tic tac toe is to simulate each move that the computer can make an score it appropriately. For example, blocking the other player winning might score very highly, completing a row of three might score infinite and anything else might be a low score. Then you just pick the move with the highest score.

You might chose to simulate more than the next move, examine what might happen for the rest of the game, and score the next move based on all the moves that might come after it. Again, highest scoring move would be the one to make the computer play,

Tic tac toe is a good place to play around with how to implement this, its got a pretty low number of moves possible. More complex games (Chess, Go, etc) is the same process just much more complex so you need to take some shortcuts.

Jamiec
  • 133,658
  • 13
  • 134
  • 193