Important alert: (current site time 7/16/2013 1:14:26 AM EDT)
 

winzip icon

[ Perfect Tic Tac Toe ]

Email
Submitted on: 10/8/2002 11:59:55 PM
By: Brian Matthew Anderson 
Level: Beginner
User Rating: By 54 Users
Compatibility: VB 5.0, VB 6.0
Views: 83871
author picture
(About the author)
 
     Demonstrates the use of variable levels of AI to challenge an opponent at any level. Highest level is unbeatable, lowest level is very easy. This code is HEAVILY documented (see for yourself). Can you beat the "Clever" level???

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
10/9/2002 5:52:23 AM<>

grrr... you got me addicted to tic-tac-toe ;)).... very nice prog... 5 little * from me
(If this comment was disrespectful, please report it.)

 
10/9/2002 8:25:16 AMKenneth Foster

I usually do not care for tic tac toe, but this one is really good. Thanks .
(If this comment was disrespectful, please report it.)

 
12/2/2002 4:44:48 AM

This was great, Thanks
(If this comment was disrespectful, please report it.)

 
1/15/2003 1:00:40 PM

This was great, Thanks

(If this comment was disrespectful, please report it.)

 
1/15/2003 8:39:57 PMBrian Matthew Anderson

Thank you all for your generous votes and comments. Your feedback makes me want to take on more ambitious projects. Keep it coming, please! :)
(If this comment was disrespectful, please report it.)

 
3/10/2003 4:56:49 PMSteven A. Groesz

About the only other thing to add to this program would be cat's game prediction. End the game if no more winning moves exist. Great code.
(If this comment was disrespectful, please report it.)

 
4/23/2003 1:48:00 PM

yer nice dude was just wondering how long u been programming VB?
(If this comment was disrespectful, please report it.)

 
4/27/2003 2:06:43 AMMichael Drotar

Pretty decent code. The only flaw in the AI that I see is the computer doesn't play to win, only to not lose.
(If this comment was disrespectful, please report it.)

 
4/28/2003 11:19:39 PMBrian Matthew Anderson

Your comment is true to a degree... The computer WILL try to win on intelligence level of "Poor" or greater if there are 2 of its X's (or O's) in a row and the square to make a winning move is open, but otherwise it does not try to "trick" the human by trying to win in 2 places at the same time. I thought about making a slider for defensive AI (which is really what the AI slider on this program is for) and a slider for offensive AI. Offensive AI would try one of the three "tricks" (already described in my code I think) to sucker the human player into making a wrong move that the AI could capitalize on. If I get a free weekend I'll code it and update. Thanks for the suggestion!
(If this comment was disrespectful, please report it.)

 
5/2/2003 10:38:42 PM

awesome...very educational.and fun
.THANKS
(If this comment was disrespectful, please report it.)

 
5/4/2003 5:52:31 PM

Good Work! I Have Won Every One Of Them Besides the Genius.
Very Nice Program!
(If this comment was disrespectful, please report it.)

 
5/18/2003 7:07:12 PMabandoned_programmer

i found no searching method.
if you have to check using If..else..End if, then what happens when there are more than 9 squares? nightmare
(If this comment was disrespectful, please report it.)

 
5/20/2003 8:48:03 PMBrian Matthew Anderson

Ummm Tic-Tac-Toe only has 9 squares that I know of... There's nothing wrong with using If..Then..Else statements anyway. I use them because it is how the program gives weighted values to the open squares. This actually makes my program more fun because I am able to selectively remove (through use of the A.I. slider) conditions that make the computer opponent a better player. Who would want to play against an opponent that never had a chance to lose? By the way, have you figured out how to beat the A.I. on the "Clever" level???
(If this comment was disrespectful, please report it.)

 
5/21/2003 5:03:52 PMHH

nice code...
possible update......
Have an option where the computer can play itself.( kinda like the movie wargames ) :) ..
(If this comment was disrespectful, please report it.)

 
6/6/2003 3:20:54 AM

Its impossable to beat clever
(If this comment was disrespectful, please report it.)

 
6/7/2003 12:49:48 PMBrian Matthew Anderson

It IS possible... like the guy who commented before you - it has to do with perceived threats... The computer AI at that level sees every threat except one, and I don't want to give it away, so I'll give a hint to those who think the same thing you do: Try taking a corner square first, and next move take the opposing side square... Sometimes the AI at that level doesn't see a double threat. At genius level you can not win, but like I said, it is possible at Clever. You just have to keep trying... :)
(If this comment was disrespectful, please report it.)

 
6/12/2003 3:11:23 PM

i like this game i downloaded the code several times and i always did loose it its a 5 to me
(If this comment was disrespectful, please report it.)

 
6/15/2003 3:30:33 PM

You mentioned early about learning HTML.. email me about that, ive been working with HTML for 3 years now.. maybe more ive lost track. i havent even downloaded your program and i would rate it a 5 just by the comments you are getting, sounds awesome
(If this comment was disrespectful, please report it.)

 
7/5/2003 4:11:38 PM

The font for the title above the game board in your screenshot may not be on my NT 4 workstation. The default font that your app is too large is too large. It ends up saying `` Tic - Tac - ''. Also, if the layout cannot dynamically change with the size of the application window, you may want to disable the ability to resize or maximize it. Otherwise seems pretty tight. I had fun figuring out Clever. It all depends on AI's second move (that's if you make the correct first move). Thanks.
(If this comment was disrespectful, please report it.)

 
7/7/2003 6:59:19 PMBrian Matthew Anderson

Great feedback. I always wondered if I was going to have problems using that font. I'll have to maybe use a more "traditional" font just to make sure it looks the same on everyone's computer. Good point on resizing it too. At one point I was going to make the form dynamically resizable such that all the buttons, fonts, and squares resized according to the dimensions of the form after resizing, but it ended up being a lot of work and it unnecessarily complicated the program. Glad you figured out the "Clever" level. Persistance is the key - and it helps to be "Clever" yourself :)
(If this comment was disrespectful, please report it.)

 
7/8/2003 7:32:08 PMBrian Matthew Anderson

Okay, I did a few updates per recent feedback on the fonts and making the form non-resizable. Shouldn't cause any problems :)
(If this comment was disrespectful, please report it.)

 
8/15/2003 9:16:14 PMJohannes B

This is good =)
(If this comment was disrespectful, please report it.)

 
8/20/2003 1:52:19 AMTahir Fall

MAn you've been keeping this code for almost a year, and you're still having good comments for it. And just for that i'll give you five globes. Me myself i'm know interested in AI. And the project I'm thinking of is related to speech reconigtion. I hope i'll finish it. Aight keep the good work.
(If this comment was disrespectful, please report it.)

 
10/3/2003 12:39:46 AM

gj, this has helped me alot
(If this comment was disrespectful, please report it.)

 
10/5/2003 12:13:34 AM

Very good!! Iam learning VB I can only make webrowsers media player word pads ect. But now Iam learning Games, this will help me learn alot FUN GAME TOO MAN KEEP IT UP!!!
(If this comment was disrespectful, please report it.)

 
10/5/2003 12:18:13 AM

1 more thing I just finshed playing it, I cant beat the last mode genus its always a tie LOL me and the AI are tieing every time, lol. Fun Game Though, I gave you the BIG 5!! :)
(If this comment was disrespectful, please report it.)

 
10/27/2003 2:02:44 PM

this is heavy... very clever indeed .. whoeva wrote it ...
(If this comment was disrespectful, please report it.)

 
12/25/2003 9:32:33 PMSoMeGuY_dUdE

excellent code, great job
(If this comment was disrespectful, please report it.)

 
1/16/2004 5:05:44 AMNice coder

This is VERRY GOOD code. 5*****, i'm working on an adaptive tick-tack-toe program (uses an array, and my autocompleate methods to select the best move, if it has encountered it before), and i was wondering if you could help?
(If this comment was disrespectful, please report it.)

 
1/22/2004 1:32:07 AMBrian Matthew Anderson

Advice for anyone trying to make a TTT game: **1) Understand how the game is won. Seems simple, but many so called "unbeatable" TTT games had to be rewritten several times because of clever human opponents (see my "Special AI" subroutine for details on this) **2) Try something different. There are at least 140 TTT games on PSC at last count. Try putting a twist on the game that will make the game unique. **3) Don't upload until you are sure you have a nice finished product. Uploading half finished buggy programs wastes your time and the time of everyone foolish enough to download it. **4) Most of all, make sure it is something somebody else will enjoy. Would you enjoy playing the program if you hadn't written it yourself? Fun factor is a big PLUS. **5) Have fun making the program!
(If this comment was disrespectful, please report it.)

 
2/7/2004 10:19:14 PMMosquito developer

I never thought to make an AI program for fun, I already know how much lines of code there were to develop, your is a good work, congratulation Brian, you did an excellent work.
Greetings from Italy
(If this comment was disrespectful, please report it.)

 
2/8/2004 2:26:48 PM

I just started to learn Visual Basic, and I wanted to learn something simple like tic tac toe. After seeing this, it helped a lot since it was documented to make the reader understand it, thx
(If this comment was disrespectful, please report it.)

 
2/29/2004 11:53:29 PM

I find that the AI is all pre-programmed, my type of AI is the one which can actually learn from experience towards prefections!
(If this comment was disrespectful, please report it.)

 
3/2/2004 1:58:01 AMBrian Matthew Anderson

The AI is NOT pre-programmed. Actually, there is quite a bit of randomness to it. The AI is designed to look at certain situations based on the selected intelligence level (like if the opponent takes 2 opposite corners for its first 2 moves) and make changes to how it values certain open squares accordingly. *** See next comment for continuation...
(If this comment was disrespectful, please report it.)

 
3/2/2004 1:58:14 AMBrian Matthew Anderson

Anyone who plays will notice that the computer does not make the same sequence of moves every game. There are other examples of TTT games on PSC that save board positions and choose to not repeat poor outcomes, but this is not fun to play, nor is it even truly AI. Merriam Webster defines AI as "The capability of a machine to imitate intelligent human behavior". I think you would be hard pressed to tell the difference between a good human opponent and the computer player on Average or Clever level. Play anyone else's TTT game (including ones which use the logic process you describe) and you will see right away that their games do not really fit the definition of AI as well as this program does.
(If this comment was disrespectful, please report it.)

 
3/10/2004 5:24:28 AM

the program contains a large set of possible game flows and plays according to programmed steps. it would be far nicer if the program would calculate it next step by pure logic without any predefined situations. (recently i have made an attempt myself, if you are interested i can send you my code)
(If this comment was disrespectful, please report it.)

 
3/10/2004 4:12:11 PM

This is greaT!!!!!!!!1
(If this comment was disrespectful, please report it.)

 
3/10/2004 5:58:35 PM

hi Mr. Anderson! i like your program a lot it amazes me the fact that when you drag the skill level of the computer it generates a level of competence and its intelligence until now i still can't beat the ai even at the average level. ummm... can you do me a favor pls...? i have this subject in my Information Technology class and our intsructor assigned us in generating a program bout games. and i'm having a difficult time handling this task. this game is about a movable object that seeks it's fellow object, it's more like a hide and seek game. wherein you look for the other objects hidden in the form and when you locate it, it appears and scores you a point. i have generated this prog. already but my prob. is this the other object that i hid doesn't appear when i crossed their path. the object doesn't appear even though i have calculated it's location. can you help me on this one? pls.... ;o) thanks...
(If this comment was disrespectful, please report it.)

 
3/11/2004 11:00:21 PMBrian Matthew Anderson

Of course, I am happy to look at other's code, but since I've had over 15,000 viewers thus far, I cannot look at everything. I doubt I'd ever write my own code if I was busy examining everyone else's! As to person #1's comment, indeed there is logic involved in the program. Its inherent in its design in that open squares are given values and the computer simply chooses the highest rated value. Granted, I do give it some "help" with the 3 special cases, but for the most part it is decent AI and actually fun to play since the AI is adjustable. The alternative (and I think this is what you're expecting) is to "look ahead" 2 moves deep (much like a chess algorithm) and make a move that has the best chances of reducing an opponent's chance to win while maximizing the computer's chances. The result would *perhaps* be more in line with many people's expectations of what AI is, but it would hardly be fun.
(If this comment was disrespectful, please report it.)

 
3/25/2004 3:34:57 AM

this was grate tanx my friend.
(If this comment was disrespectful, please report it.)

 
7/24/2004 11:13:27 AM

kk... This is a great program, Its tough to beat and still very fun. Thanks much Brian for shaing this gem with us!
(If this comment was disrespectful, please report it.)

 
8/16/2004 3:45:13 AM

thank you for the code, it rocks
love the AI
I am making a tic tac toe app for my schools HOD in computing, because he wants me to extend myself.
thanks again for showing me the way
5+
(If this comment was disrespectful, please report it.)

 
8/21/2004 8:55:16 PM

dude i love this program, and you saying you beging. hate to ask this from you, and if others want to. would you mind giving me a few tips. my email is stephanstas@hotmail.com

dont have to but i wish you did
(If this comment was disrespectful, please report it.)

 
8/31/2004 2:19:04 PMAndrew Cooke

Tic-Tac-Toe Expert^^^^^^^^^^

This is one hell of a great practise arena for me, i can beat every level apart from Genius, however the game hasnt beaten me once yet :(
However i will beat it... I MUST!
lol.
(If this comment was disrespectful, please report it.)

 
8/31/2004 11:02:06 PMBrian Matthew Anderson

You will indeed spend a LONG time trying to beat it. I had the computer play itself for several hours using random moves against the "Genius" level AI and it never won. In that amount of time it tried every possible move combination several times over. Previous itirations discovered holes in the AI, but they are all patched and the 20000+ people who have downloaded it before have tried too. Good luck though ;) As far as the offensive AI trying to beat you, I must admit I need to come out with a version that does a better job of taking some initiative. As I have moved on to grander projects however, I may not have time to come back to modify this one. Glad you enjoyed it.
(If this comment was disrespectful, please report it.)

 
9/28/2004 7:22:50 AM

You got a load of comments. i'm impressed. Anyways, a wonderful game.
How bout moving up to 3D programming?
The AI challenge would be great.
(If this comment was disrespectful, please report it.)

 
10/29/2004 11:14:47 PM

Verry Nice...
Is there any way to make it actuly beat me?
it keeps getting tie but it never beats me:^)
Yip very nice
(If this comment was disrespectful, please report it.)

 
1/23/2005 9:10:31 AM

it's amazing Game...Thank's for your Science....it's fun games..
(If this comment was disrespectful, please report it.)

 
2/22/2005 5:29:33 PMMatt Elton

Wow! Awesome game! Probably the best Tic Tac Toe game I've ever seen! I made a Tic Tac Toe game too, it's called MonkeyMoose Tic Tac Toe (but it's not as good as your's).
(If this comment was disrespectful, please report it.)

 
3/6/2005 12:28:08 PMLucas Budd

Nice game :P i rate it 5 globe :P
(If this comment was disrespectful, please report it.)

 
3/14/2005 8:09:55 PM

i like your project it was very fun and interesting keep up the good work
(If this comment was disrespectful, please report it.)

 
4/30/2005 11:08:22 AMBrian Matthew Anderson

I just realized this program is now in the top ten most popular submissions for the "Games" section. Kinda inspiring when I think about it. I will have to release more projects after I've cleaned them up. I can only hope that they are as well received. Thanks for the votes and the comments, everyone!
(If this comment was disrespectful, please report it.)

 
6/3/2005 6:11:29 AM

nice program. easy to learn tnx for the vb planet
(If this comment was disrespectful, please report it.)

 
6/21/2005 5:04:37 PM

Wow!! Amazing i'v beaten it on clever but is it possible to win on genious?

Great code. nicely documented, However some people dont like reading alot :p

5* from me
(If this comment was disrespectful, please report it.)

 
7/24/2005 9:57:18 PMBabb Systems

Very nice code. I may use some of these techniques for a RPG that I am developing...
(If this comment was disrespectful, please report it.)

 
12/28/2005 9:52:15 PMDuy Hung

Verry,verry good.Ths 4 u!...
(If this comment was disrespectful, please report it.)

 
1/25/2006 7:25:46 AMreynan

thx very much for th code
(If this comment was disrespectful, please report it.)

 
2/17/2006 1:48:09 AMKR

can i have a sample code from your game tic-tac-toe??? please... thanks!
(If this comment was disrespectful, please report it.)

 
3/14/2006 1:18:10 AMPANKUSOFT

nice idea .***** globes.From this code i got an idea of developing real AI TIC TAC TOE.I will soon come with that
(If this comment was disrespectful, please report it.)

 
8/19/2006 6:51:55 AMJames

It's very cool
(If this comment was disrespectful, please report it.)

 
11/13/2006 5:07:16 PMKamaron Peterson

Excelent job. Your code is amazing. It was very impressive for your first real VB project.
(If this comment was disrespectful, please report it.)

 
11/27/2006 5:00:06 PMFlubber

This is really amazing, alot of codes there, great job, 5 * from me! clever: cat's game, genius: cat's game :/
(If this comment was disrespectful, please report it.)

 
1/1/2007 7:10:36 PMBen Doherty

congrats brian. you are now the top spot for the games category.
(If this comment was disrespectful, please report it.)

 
1/2/2007 9:40:01 PMBrian Matthew Anderson

Woo Hoo... I suspect the # of downloads is partially due to the alphabetical positioning in the listing under the "games" category. I don't feel so bad about this as the program is actually pretty well written - albeit not really a great demonstration of true "A.I." Funny thing is I've dabbled in C++ and C# .NET and keep finding myself coming back to VB6 because it is SO MUCH EASIER to program. Thanks all for the kind feedback.
(If this comment was disrespectful, please report it.)

 
1/14/2007 11:17:20 AMEmmanuel B. Albino Jr.

Wow great game I can't beat the AI on genius level always cat's game grrr how about cheats for this hehhehe just kidding but it is great specially for a beginner like me thank you for the code.
(If this comment was disrespectful, please report it.)

 
2/26/2007 11:30:02 PM

This is good.
(If this comment was disrespectful, please report it.)

 
3/14/2007 2:09:14 PM

Hey could you e-mail me the code for version 6.0??
(If this comment was disrespectful, please report it.)

 
3/14/2007 2:09:50 PM

Hey could you e-mail me the code for version 6.0?? my e-mail is big_e_1509@yahoo.com i would appreciate it thanks.
(If this comment was disrespectful, please report it.)

 
10/19/2007 3:50:54 AMabdullah

cool man good job can be used to challenge kids
(If this comment was disrespectful, please report it.)

 
11/20/2007 12:50:28 AMPrakash

Still the best to come from you...Best of luck
(If this comment was disrespectful, please report it.)

 
1/24/2008 3:26:39 AMmont

good
(If this comment was disrespectful, please report it.)

 
7/8/2008 12:10:36 AMSPY-3

That is rather nice, it is almost like versing a real person! It can do something different each time rather then prerecorded good moves (like someone else's comment spoke of) great job *plays more tic tac toe... ah tie again!* 5 globes!!!
(If this comment was disrespectful, please report it.)

 
7/13/2008 3:33:18 PM

thank you
(If this comment was disrespectful, please report it.)

 
12/7/2008 12:05:08 PMOmi

GR8 work Brian! Hats off 2 u!
(If this comment was disrespectful, please report it.)

 
12/2/2009 5:24:55 AMOwen

I am trying to make a Kalaha game and I have to make it so that a player can play against the computer. Do i have to know all the possible ways to win before making even a basic AI system? The main point of the project is to make a game that works, the extended part is making it so that the computer can play against you, even if the AI is weak. I need some help and don't know where to turn.
(If this comment was disrespectful, please report it.)

 
9/28/2010 3:21:27 PMEmmanuel B. Albino Jr.

It is a great code. Hehehe I beat the Clever level but once. I just followed your guide at the sides but on the Genius level, man it's always a tie game. But will not stop trying to beat it haha ^_^
(If this comment was disrespectful, please report it.)

 
9/28/2010 3:24:54 PMEmmanuel B. Albino Jr.

Oh sorry moderator i forgot to put my vote. I give it 5 globes (it is the highest I think) and I don't see an input for putting my 5 globes, must be included in my comment sorry being noob to this site. Thanks
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.