O and X's or tic tac toe

How could i make ai for a noughts and crosses or tic tac toe game
so it would look like this


||||
|
|||
|||_|

when u click the box it turns to a circle.
then the “computer player” has a turn but how can i make it so the computer player makes his move blocking the “player 1’s” circles?

and could i make it so if 3 are in a line then player 1 wins

thanks in advance,
yhack

Basically… To create a Tic tac toe AI. You would simply create a numberring f importance scheme.

You would evaluate all the spaces on the boards as if they were a mathmatical equation. If you have a piece in a spot on the grid. It would be classified as a single point. If the computer has a spot in the grid. it would be classified as a -1 point.

_|x|o

o|x|_

||_

Now… Mathematically… You would want to add up all of the rows and columns that you possibly can… using this equation…

0_|1|-1 = 0

-1|1|_0 = 0

0_|0|_0 = 0
= = = =
-1 2 -1 1

Now… Looking at these numbers and judging by what we see. You can see that the player (x’s) has a column that ends up equalling 2. There is only one move moe superior than a 2 column… And that is any possible winning columns… Which can be settled by a -2 value. getting a -3 value = win for the computer. Stopping a player from reaching a 3 value is a possible draw / win for the computer.

So… These are just some hints. :slight_smile: I would elaborate more… But I need some sleep.