Advertisement

TickTackToe AI

Started by September 12, 2002 12:23 PM
4 comments, last by branhield 22 years, 3 months ago
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..
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,
If so block that move and skip to the end.

3. Check to see if the AI can place a marker to make a row of two,
If so place the marker and skip to the end.

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
Advertisement
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.
ok thx guys..but im not quite sure how to do that..like..how do i make the -can i win- checking thing..?
This might help: Tic-Tac-Toe.

Miles
thx

This topic is closed to new replies.

Advertisement