Feb 16th, 2001, 06:09 PM
#1
Thread Starter
Lively Member
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
Attached Files
Feb 19th, 2001, 10:48 AM
#2
Retired VBF Adm1nistrator
Christ thats a lot of code ...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Feb 19th, 2001, 11:01 AM
#3
Retired VBF Adm1nistrator
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
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Feb 19th, 2001, 11:09 AM
#4
Frenzied Member
Feb 19th, 2001, 12:54 PM
#5
Thread Starter
Lively Member
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....
Feb 19th, 2001, 03:09 PM
#6
Thread Starter
Lively Member
Obviously, I ripped no one off, Steve.
Feb 20th, 2001, 02:57 AM
#7
Retired VBF Adm1nistrator
I'd rip his code
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Feb 20th, 2001, 09:23 AM
#8
Frenzied Member
It's on my site for the taking
Just remember its internet play only.
Feb 20th, 2001, 03:22 PM
#9
Thread Starter
Lively Member
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....
Feb 20th, 2001, 03:23 PM
#10
Thread Starter
Lively Member
I meant steves was NOT multiplayer. Braindead today.
The internet playing was a cool idea, too.
Feb 21st, 2001, 03:13 AM
#11
Retired VBF Adm1nistrator
Well the code I posted above, or a modification thereof, would tell you who won.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
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