![]() |
Another tic tac toe
http://commodore.gran.ee/tictactoe.zip
The "source" folder contains the python file which can also be ran on Linux. The tictactoe folder contains the windows executable (python and pygame are not needed). Currently the computer selects a square randomly (no AI). The plus is that the game is beatable (very, very easily) but the negative side is that I didn't learn anything from it :P. If someone gives me a tutorial for making AI for it I'll consider doing it. Press escape to leave the game. I suck but at least it doesn't have programmer art :D. |
The only winning move is not to play
|
Your AI could be as simple as blocking any opponent move which results in an immediate win for the opponent, and making any move which results in an immediate win for the machine. It could be as complex as a neural network whose weights are chosen by a genetic algorithm. Obviously you won't learn anything from it unless you work at it in one fashion or another.
|
I'm thinking of doing it with a game tree (if that's what they call it) because pathfinding algorithms and other stuff use it too.
|
If even do a couple things that DaWei has suggested and cleaned up the AI, it would be a very slick tic-tac-toe game, very nice interface.
|
Nice app chap, graphics are a lot better than the one I made thats for sure. look forward to seeing it with some smart AI. :)
|
AI for tic tac toe really wouldn't be that hard. There are a limited number of possible moves that can be made, and there is always a definite "best" choice (although there may be more than one choice that is equally good).
|
I suspect the OP realizes that, but wonders HOW to instruct the machine to determine the "best" choice.
|
Quote:
not sure if this is the best way, but here is probably how I would approach giving tic-tac-toe some AI. -The first check it will make at the beginning of every turn is to see if it has two in a row anywhere and if it could win. -if not it would check to see if you have two in a row anywhere so it can prevent you from winning. -if not it would check for two empty spots next to one it currently has placed on the board so it can set itself up. -if not then it would look for 3 empty spots on the board in a row so it could set itself up. Start out with something simple, get it working, and then refine it, test it, refine it some more, etc. I would probably then add difficulty levels which determine how often it has a chance to make a mistake, which would then be determined by some form of random number. |
Three previous shots and a discussion thread, among others. It's why there's a search box prominently displayed.
|
| All times are GMT -5. The time now is 5:00 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC