Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Show Off Your Open Source Projects (http://www.programmingforums.org/forum52.html)
-   -   Another tic tac toe (http://www.programmingforums.org/showthread.php?t=12845)

commodore Mar 19th, 2007 6:42 AM

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.

mrynit Mar 19th, 2007 6:58 AM

The only winning move is not to play

DaWei Mar 19th, 2007 8:46 AM

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.

commodore Mar 19th, 2007 2:59 PM

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.

King Mar 19th, 2007 11:10 PM

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.

Seif Mar 20th, 2007 2:11 AM

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. :)

Fall Back Son May 24th, 2007 9:35 PM

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).

DaWei May 25th, 2007 2:12 AM

I suspect the OP realizes that, but wonders HOW to instruct the machine to determine the "best" choice.

melbolt May 25th, 2007 8:39 AM

Quote:

Originally Posted by Fall Back Son (Post 128256)
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).

But then you get into things like, should it have some form of error programmed into it as well or will it just be a flawless player? Is it even possible to ever beat this computer or will it always be a draw?


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.

DaWei May 25th, 2007 10:41 AM

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