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:
  1. Private Sub cmdTile_Click(index As Integer)
  2. If result = vbYes Then
  3.  If (CLICKCOUNT Mod 2 = 1) Then
  4.   cmdTile(index).Caption = "x"
  5.   Else
  6.   cmdTile(index).Caption = "o"
  7.  End If
  8.    cmdTile(index).Enabled = False
  9.  'CLICKCOUNT = CLICKCOUNT + 1
  10.   CheckWinner
  11. Else
  12.   computer (index)
  13. End If
  14. End Sub
  15.  
  16. Private Sub computer(index As Integer)
  17. MsgBox (CLICKCOUNT)
  18. If (CLICKCOUNT Mod 2 = 1) Then
  19.   cmdTile(index).Caption = "x"
  20.    cmdTile(index).Enabled = False
  21.      CLICKCOUNT = CLICKCOUNT + 1
  22.   Else
  23.   index = Rnd(index + i)
  24.  cmdTile(index).Caption = "o"
  25.  cmdTile(index).Enabled = False
  26.  End If
  27.  CLICKCOUNT = CLICKCOUNT + 1
  28.   CheckWinner
  29. 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 face and I couldn't figure out how to make the automation work with my current code.

Thanks,


Nightwalker