There's alot of TicTacToe games out there...mostly 2 player. But im trying to get mine to work and it be a one player game. Programming AI isn't too fun . But could someone help me out here? The "AI()" function is blank..thats where the AI programming goes. The code is messy but it shouldn't be impossible to read BTW, its C++
If you want to do something simple, why don''t you try this:
If you can complete three in a row do it else If center is available take that else if there''s a spot adjacent to any of the computer''s X''s take that
Ahhh, a tic-tac-toe, sounds like a good place to try out that ''game tree AI'' For example, assume AI start out. Most likely he would like to take the center piece. Hence, the root of the tree would be ''take center piece''. Next, the player has 8 possible places to put, giving you 8 possible scenarios. Based on each scenario, handle each one respectively. Meaning branching out of root, you get 8 child nodes to handle. Do this recursive, generating a complete tree handling all the game state(you might want to use an editor for it). Dump the content into a file, and load into the game, and just do simple node navigation! Sounds like a pain in the ass, but it''s a way to try this tree concept out. I think it was used for that Deep Blue machine which won the world chess champion, I''m not sure.
yes there is a way to always insure a draw, so the game isnt that fun if 2 people are smart. The middle spot is not always the best spot when available (considering that it is the first turn, and the person you are playing doesnt know the game very good).
You can use something called a Game Tree to solve a game like Tic-Tac-Toe (or checkers, or chess). The nice thing about it is that you can easily adjust the difficulty level of the computer from a perfect player, to a crappy player.
If you do a search on google for game tree, minimax, and tic-tac-toe you''ll come up with some explanations that are far better than anything I could give.
If you have any questions I''ll try my best to answer them.