Help with my first basic AI

Started by
2 comments, last by silmaril 18 years, 11 months ago
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.
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.
Gary.Goodbye, and thanks for all the fish.
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
Hope I was helpful. And thank you if you were!
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.

This topic is closed to new replies.

Advertisement