Jump to content
  • Advertisement

Archived

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

branhield

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!