|
-
Nov 7th, 2002, 01:34 PM
#1
Thread Starter
Addicted Member
I need help to get started with making a TicTacToe game..
I only have codes that make each cmdbuttons to change its text to X when a user clicks at them.
I can't figure out how to make the computer decide which box it would want to pick.
Even if i wanted the comp to randomize and pick any buttons that are not yet chosen, how would i do that? I don't know if I can randomize buttons.. If you know what I mean.. Like..
VB Code:
Dim RndPick As Integer
Randomize
RndPick = Rnd() * 9 + 1
If RndPick = 1 Then Button1.Text = "O"
That's how I've thought of the comp choosing a button, but when it comes to the part where the comp has to block a 3 straight Xs...
Can someone get me started with this?
Thanks in advance.
-
Nov 7th, 2002, 01:46 PM
#2
Thread Starter
Addicted Member
Hmm...
All I can think of as of now is to try every possibilities... Like, make a function that determines which box the CPU is going to choose, and see if ONLY button1 is checked, then choose a couple of possible winning picks.
But that would make the code to be really long. There has to be a shorter way... I think..
Any help?
-
Nov 7th, 2002, 02:54 PM
#3
Hyperactive Member
This might give you some ideas:-
http://visualbasic.about.com/library.../aa093002a.htm
It uses 2-dimensional arrays to track the positions of tic/tacs. There are other ways you could do it. Looking at the the above link you will see the 8 possible lines that create a win. You could track how close to complete a line gets after each move.
-
Nov 7th, 2002, 08:13 PM
#4
Thread Starter
Addicted Member
Hey, thanks!
It'll help me a lot!
However... 
I was thinking about playing against the comp...
Here is a link of a source code of a tic tac toe game with AI: http://freevbcode.com/code/TTT_AI.zip.
I can't figure it out... Especially the part about patterns in AI module...
Here's another example, which, of course, I couldn't understand : http://freevbcode.com/code/nghtcros.zip.
Last edited by nahya^^; Nov 7th, 2002 at 08:50 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|