Can You Beat This Game?
HN,
git://github.com/inteq/Tic-Tac-Toe.git
I would like to issue a challenge to see if you can find a way to beat my tic-tac-toe program. I would definitely appreciate any feedback that will help me improve the brains of the cpu opponent. It is console driven and not pretty on the outside. Thanks!
14 comments
[ 3.7 ms ] story [ 57.9 ms ] threadTic-tac-toe is basically a solved game which should make it easy to code.
You're encoding the game state as a giant switch statement. This is not the best approach. The size of your code will increase exponentially with the complexity of the game. The only reason it works at all is because tic-tac-toe is very simple. You should read up on representing this as a game tree:
http://en.wikipedia.org/wiki/Game_tree http://en.wikipedia.org/wiki/Extensive-form_game
Here was my first run, pretty much randomly choosing boxes:
Hope that is helpful.After a few minutes trying different strategies:
If I win the coin toss I'm winning the game, every time. If I lose the coin toss it always ends in a draw.
Transcript (of 7 wins): http://dl.dropbox.com/u/142733/tictactoe.txt
Assuming I win the coin toss, I always choose a corner for my first move. The CPU should then take the center but it never does. This ensures I always win.
That said, great job so far. It's very close to perfect IMO.
http://github.com/RichardBronosky/Tic-Tac-Toe
The forked network for this project is interesting. Is this for a class or something?
Check out http://en.wikipedia.org/wiki/Tic-tac-toe#Strategy for the description of the algorithm.