# O and X's or tic tac toe

**URL:** <https://forum.kirupa.com/t/o-and-xs-or-tic-tac-toe/110987>\
**Category:** Uncategorized\
**Created:** [May 21, 2004, 7:13pm UTC](https://forum.kirupa.com/t/o-and-xs-or-tic-tac-toe/110987 "2004-05-21T19:13:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yhack](https://avatars.discourse-cdn.com/v4/letter/y/3da27b/32.png) [@yhack](https://forum.kirupa.com/u/yhack)\
**Post date:** [May 21, 2004, 7:13pm UTC](https://forum.kirupa.com/t/o-and-xs-or-tic-tac-toe/110987/1 "2004-05-21T19:13:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 27, 2004, 4:43am UTC](https://forum.kirupa.com/t/o-and-xs-or-tic-tac-toe/110987/2 "2004-05-27T04:43:22Z")

</div>

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. 🙂 I would elaborate more… But I need some sleep.
