Advertisement

tic-tac-toe

Started by June 17, 2006 10:48 PM
4 comments, last by tomcant 18 years, 5 months ago
hi all im not sure if this thread is about the kind of AI that your probly used to but i was thinking about making my first game a simple tic-tac-toe, possible text based since im not at the level of and graphics library, or even the GDI for that matter but anyway im really confused about how to create the computer player AI for tic tac toe.....what ive established so far is: the ai needs to be able to 'defend' against the player from creating a row of x's or o's and at the same time it needs to also have the intelligence to try to create its own row of elements when not in any danger of losing.....now this all sounds great but i just cant make the connection from human logic to c++ any help would be appreciated.
Hi,

Take a look at the entry on wikipedia, there's a section about the strategy to win a game of tic tac toe.

Now, something you could do is have methods that determines the fitness of a move by evaluating it against all of the 6 possible actions, and picking the move with the highest priority.

Hope this helps
Advertisement
Tic-tac-toe AI is a well-understood problem and usually done with algorithms like these.
A straight conversion from human-like strategy to C++ is a rather big step. I suggest to subdivide your problem into a more math-sounding form, then translate it to pseudo-code or to a flowchart. After that you're free to code it in any language you like :)
You can easily note that you'r problem solution's related to a static world (eg. the player moves, than nothing happens while it's the AI turn to move), thus a simple search over a graph should do the trick. I guess that's what the link posted by lightbringer is about, so read it carefully ;)
I just wanted to give you a hint on formalizing problems, nothing added to what's been already told...

gl
[ King_DuckZ out-- ]
Kind of, just that we have solutions readily available for solving zero-sum games, so there's no need to reinvent the wheel :D it might be interesting to do it by hand like you say, but I thought it might take a while longer than necessary :D
Minimax. :-)
______Tom

This topic is closed to new replies.

Advertisement