PDA

Click to See Complete Forum and Search --> : Tic-Tac-Toe Game - Loops Needed


amesjustin
Feb 16th, 2001, 05:09 PM
Attached is my Tic-Tac-Toe game. It is not finished - I still need to write the Hard level AI and the End-Game determination loop and fix a few minor bugs.

What I need is Help writing a loop to determine when the computer or the player wins. I could also use some Ideas on how to condense the code. I already know how to fix the bugs and write the Hard AI. Thanks guys!
-Justin

plenderj
Feb 19th, 2001, 09:48 AM
Christ thats a lot of code ...

plenderj
Feb 19th, 2001, 10:01 AM
To check if someone won :
(first I'd create a control array for the labels)


PlayerWon = False
For i = 1 To 4
Select Case i
Case 1:
PlayerWon = (Lbl(i).Caption = Lbl(i + 1).Caption) And (Lbl(i + 1).Caption = Lbl(i + 2).Caption)
PlayerWon = PlayerWon Or (Lbl(i).Caption = Lbl(i + 3).Caption) And (Lbl(i + 3).Caption = Lbl(i + 7).Caption)
PlayerWon = PlayerWon Or (Lbl(i).Caption = Lbl(i + 4).Caption) And (Lbl(i + 4).Caption = Lbl(i + 8).Caption)
Case 2:
PlayerWon = (Lbl(i).Caption = Lbl(i - 1).Caption) And (Lbl(i - 1).Caption = Lbl(i + 1).Caption)
PlayerWon = PlayerWon Or (Lbl(i).Caption = Lbl(i + 3).Caption) And (Lbl(i + 3).Caption = Lbl(i + 6).Caption)
Case 3:
PlayerWon = (Lbl(i).Caption = Lbl(i - 2).Caption) And (Lbl(i - 2).Caption = Lbl(i - 1).Caption)
PlayerWon = PlayerWon Or (Lbl(i).Caption = Lbl(i + 2).Caption) And (Lbl(i + 2).Caption = Lbl(i + 4).Caption)
PlayerWon = PlayerWon Or (Lbl(i).Caption = Lbl(i + 3).Caption) And (Lbl(i + 3).Caption = Lbl(i + 6).Caption)
Case 4:
PlayerWon = (Lbl(i).Caption = Lbl(i - 3).Caption) And (Lbl(i - 3).Caption = Lbl(i + 3).Caption)
PlayerWon = PlayerWon Or (Lbl(i).Caption = Lbl(i + 1).Caption) And (Lbl(i + 1).Caption = Lbl(i + 2).Caption)
End Select
Next i



Something like that should work ...

- jamie

SteveCRM
Feb 19th, 2001, 10:09 AM
The computer player moves to the same spot each time I move to a certain place...

WOW :eek: I thought you were using loops! Why so much code????????? :eek:

I have a multiplayer tic tac toe game on my site (http://www.stevescyberhome.net). That will show you about how much code you should have.

Wow you really made it hard on yourself! :(

amesjustin
Feb 19th, 2001, 11:54 AM
That's why I am asking for help - a single player game is alot tougher to code than a mulitplayer, and I could not think of a way to incorporate loops into the AI - I will check out your game, though.

Thanks Plenderj - I will try it!

I still need to reduce that code, though....

amesjustin
Feb 19th, 2001, 02:09 PM
Obviously, I ripped no one off, Steve.

plenderj
Feb 20th, 2001, 01:57 AM
I'd rip his code :)

SteveCRM
Feb 20th, 2001, 08:23 AM
It's on my site for the taking :)

Just remember its internet play only.

amesjustin
Feb 20th, 2001, 02:22 PM
actually, steve took an entirely different approach than I am with mine - the only part I really need help with is the Computer movement & Win-Check coding. Steves is a single player, therefore not having any AI code. Still inspired some of my ideas, though....

amesjustin
Feb 20th, 2001, 02:23 PM
I meant steves was NOT multiplayer. Braindead today.

The internet playing was a cool idea, too.
:)

plenderj
Feb 21st, 2001, 02:13 AM
Well the code I posted above, or a modification thereof, would tell you who won.

- jamie