# TicTacToe

• 10-11-2002
neoground73
TicTacToe
Well guys I get to write a tic tac toe program for my class. This sux. In this program the computer must beable to move by itself playing against the player. Now the catch is the computer has to be smart enough to at least tie with the user. Any ideas on how to do this?
• 10-11-2002
mickey
yes! a minimax algorithm, if ever you get to make this algorithm inside your game, hope you could share it to me!! :)

• 10-11-2002
neoground73
Umm I can't seem to find any minimax algorithm that will compile under visual c++ 6.9

• 10-11-2002
BMJ
What? You don't need to use something like a minimax algorithm for Tic-Tac-Toe!

Think about Tic-Tac-Toe for a second. What's the only 'strategy' the computer can make? It prevents you from getting 3 in a row.

So... using a matrix, parse the matrix after the player moves and check for any potential wins (2 adjacent X/Os)... then have the computer move to the 3rd position...

There's a little more to it, but it's not complicated.
• 10-11-2002
first write the game without using any computer moves. Then try to add rules for the computer to follow. Things like: if you move first, always select the central box. If you move second, never select the central box. Always look block a possible winning move. etc.
• 10-11-2002
neoground73
Yeah guys im already working on the rules for the comp and i have finished the user part. I was juz asking what minimax was. I never expected to use it. So what is it?
• 10-11-2002
mickey
well okey you don't really need a minimax algo but heck it'll absoluely make your program better and prof. looking rathar than having long list of if else statements and besides this is a tremenedous practice, :)

http://www.generation5.org/minimax.shtml

try that but there's another one really good tutorial with a sample source code, can't find it right now at google, :)
• 10-11-2002
ZerOrDie
Quote:

Originally posted by BMJ
What? You don't need to use something like a minimax algorithm for Tic-Tac-Toe!

Think about Tic-Tac-Toe for a second. What's the only 'strategy' the computer can make? It prevents you from getting 3 in a row.

So... using a matrix, parse the matrix after the player moves and check for any potential wins (2 adjacent X/Os)... then have the computer move to the 3rd position...

There's a little more to it, but it's not complicated.

yes but then you can still trap the computer :(

you would also want to add moving to one of the corners if the user takes the middle and if the user takes a corner then take the middle... there will still be a couple traps letf but that should minimize it...