Hi,
I have been trying to create a method so the player can play against the computer for my Tic Tac Toe game here. The problem is that "x" always seems to win or the game ends in a draw even when its not. Not only that for some reason the first computer turn "o" is displayed as you would expect but after that only blank disabled buttons represent the shot the computer has taken.
This is how I am trying to do the A.I:
VB Code:
Private Sub cmdTile_Click(index As Integer) If result = vbYes Then If (CLICKCOUNT Mod 2 = 1) Then cmdTile(index).Caption = "x" Else cmdTile(index).Caption = "o" End If cmdTile(index).Enabled = False 'CLICKCOUNT = CLICKCOUNT + 1 CheckWinner Else computer (index) End If End Sub Private Sub computer(index As Integer) MsgBox (CLICKCOUNT) If (CLICKCOUNT Mod 2 = 1) Then cmdTile(index).Caption = "x" cmdTile(index).Enabled = False CLICKCOUNT = CLICKCOUNT + 1 Else index = Rnd(index + i) cmdTile(index).Caption = "o" cmdTile(index).Enabled = False End If CLICKCOUNT = CLICKCOUNT + 1 CheckWinner End Sub
Also, before anyone asks I have had a look at a couple of Martin's A.I examples but they left me with this look on my faceand I couldn't figure out how to make the automation work with my current code.
Thanks,
Nightwalker




and I couldn't figure out how to make the automation work with my current code.
Reply With Quote