-
1 Attachment(s)
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
-
Christ thats a lot of code ...
-
To check if someone won :
(first I'd create a control array for the labels)
Code:
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
-
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. That will show you about how much code you should have.
Wow you really made it hard on yourself! :(
-
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....
-
Obviously, I ripped no one off, Steve.
-
-
It's on my site for the taking :)
Just remember its internet play only.
-
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....
-
I meant steves was NOT multiplayer. Braindead today.
The internet playing was a cool idea, too.
:)
-
Well the code I posted above, or a modification thereof, would tell you who won.
- jamie