I made a great tutorial on on tic-tac-toe [but in Java] the idea is pretty much the same.
I haven't looked at your code yet, but I will as I am very interested. However, it will take me a while to understand your code, and in the meantime you could make some headway. So...
To figure out who's turn it is, I have a variable increment each time a move is made. The variable [say i] starts off at 0 and if
if ( i % 2 = 0 )
// X goes
else
// O goes
to check if it is a tie, just check if i == 9, if it is 9 than there are no more moves that can be made -- the game is a tie and the game is over. Display a message and your done.
As for the AI, you just need a whole bunch of else if's [you can look at my code in the Java tutorial section for how I implemented it AI, I'm sure you can understand what is going on -- the syntax is very similar]
|