Public Group

#### Archived

This topic is now archived and is closed to further replies.

# TickTackToe AI

This topic is 5941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

ok i made a simple Ttt for DOS, and now i want to make it so u can play agains the computer..i have no idea how to do the AI though..help..

##### Share on other sites
Well you can either program the AI to try and go for the perfect game each time or try another way.

From the top of my head (assuming the board is held in an array).

Start

1. Check to see if the AI can place a marker to make a win,
If so place the marker to win and skip.

2. Check the array to see if the human can win,

3. Check to see if the AI can place a marker to make a row of two,

4. Place a random marker

End

You may also want to check if the AI can place a counter to make two or more rows of two, that would go between steps 2 and 3.

Hope that helps.

Ballistic Programs

##### Share on other sites
Well, a good way to begin would be to think about how you play tic-tac-toe. You could formulate something like this:

#states for tic-tac-toe choices

1. Go for the win, if possible
2. Block opponent, if necessary
3. Try to get two in a row
4. Go for the center
5. Go for a random square

It would probably also help if you precalculate the number of possible different wins (8) and pairs that can lead to wins (24).

John.

##### Share on other sites
ok thx guys..but im not quite sure how to do that..like..how do i make the -can i win- checking thing..?

##### Share on other sites
This might help: Tic-Tac-Toe.

Miles

thx

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013743
×