Tic Tac Toe Project Help for a noob

Tic Tac Toe Project Help for a noob
0.0 0


Hello, I;m having some trouble with alternating turns between the player and the AI. I tried using a while loop with a counter to try to constantly iterate through the if statement, but that didn’t work. Any ideas? Right now the AI is choosing open squares at random. I’m just trying to get a constant response from both sides. Any ideas? Here is the code:


For my T3 program, I had an object literal called gameState. One of the properties was “playerTurn,” which was a boolean. You can probably see where I’m going with that. Basically if it was the player’s turn, the computer just sits inactive until a token is placed. That toggles gameState.playerTurn to false. Then the computer evaluates the board, makes a move, and toggles gameState.playerTurn back to true.

Is that the best way? I have no idea. It worked for me, at least.


Thanks alot for your reply. This was a hard project. I just got finished with it a few minutes ago. Here is the final result so far: