Jump to content
  • Advertisement
Sign in to follow this  
Charmed

Help with my first basic AI

This topic is 4904 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

Hi, I was just wondering how I would go about implementing my first smart-AI for a TicTacToe game. I know I could have a simple loop, where the next available space would get chosen for the AI or I could just use a random number to decide its move. That would work, but it would not be very effective. I could also just hard-code every possible choice, but that seems a little crazy. Is there a more effective way at going about it? Thank you for any help.

Share this post


Link to post
Share on other sites
Advertisement
Personally I had the AI 1st look for a position that would give it a winning line...if one was available I used that position...if not then I looked for a position that would block a players winning line...if one was available I used that one...Otherwise I just chose the next empty space on the board.

Share this post


Link to post
Share on other sites
hi there,

i havent done any AI in C++ or C, and i haven't done any TicTacToe game, but my guess is this:

In the first round, the computer chooses a random position.

In the second round, the computer chooses the next available position to the upperleft(if any)to the left(if any)to the right(if any)to the upperight(if any)to the lowerleft(if any) or to the lowerright(if any).

in the third round, the computer checks to see where the player has to go in order to win(depending on wheter or not the player or computer starts the first round)and checks to see where he has to go in order to get three in a row.

As i said i'm not at all an AI programmer, but that would be my guess =)

Good luck and cheers,

Samsonite

Share this post


Link to post
Share on other sites
There's another active thread about that right now. The solution there is to use the Min-Max algorithm to perform an exhaustive search over the possible moves. There are many other ways to have an AI play optimal Tic Tac Toe, but that is rather straight-forward and the algorithm is intuitive. I'd suggest you look up some background info on the Min-Max algorithm, and refer back to that thread (here) if you get stuck.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!