Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 19th, 2007, 6:42 AM   #1
commodore
Programmer
 
Join Date: Nov 2005
Location: Estonia
Posts: 97
Rep Power: 0 commodore is an unknown quantity at this point
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 . 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 .
commodore is offline   Reply With Quote
Old Mar 19th, 2007, 6:58 AM   #2
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
The only winning move is not to play
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Mar 19th, 2007, 8:46 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Mar 19th, 2007, 2:59 PM   #4
commodore
Programmer
 
Join Date: Nov 2005
Location: Estonia
Posts: 97
Rep Power: 0 commodore is an unknown quantity at this point
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.
commodore is offline   Reply With Quote
Old Mar 19th, 2007, 11:10 PM   #5
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 377
Rep Power: 0 King is an unknown quantity at this point
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.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Mar 20th, 2007, 2:11 AM   #6
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 215
Rep Power: 3 Seif is on a distinguished road
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.
Seif is offline   Reply With Quote
Old May 24th, 2007, 9:35 PM   #7
Fall Back Son
Professional Programmer
 
Join Date: Oct 2006
Posts: 263
Rep Power: 2 Fall Back Son is on a distinguished road
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).
Fall Back Son is offline   Reply With Quote
Old May 25th, 2007, 2:12 AM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I suspect the OP realizes that, but wonders HOW to instruct the machine to determine the "best" choice.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 25th, 2007, 8:39 AM   #9
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 244
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
Quote:
Originally Posted by Fall Back Son View Post
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.
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt
melbolt is offline   Reply With Quote
Old May 25th, 2007, 10:41 AM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Three previous shots and a discussion thread, among others. It's why there's a search box prominently displayed.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC