Please try my tic-tac-toe

I’ll skip the obligatory War Games reference and just ask you to try it out.

my tic-tac-toe

I suppose I could have made the AI a little smarter. Here was my thinking:

  1. check if AI has a winning move
  2. check if AI needs to block winning move of opponent
  3. check if center is open
  4. check if corner is open
  5. take any random open spot

But I know that there are a few other subtleties of TTT strategy. I should have researched TTT strategy before I started my AI. I’ll have to remember that for next time. Maybe I’ll come back and fix this up.

One more build to go! And I think Simon will be easier that this!

Clicking on same tile progresses turn. It should be prevented by the game.

1 Like


I’d put my call to the AI move function outside of my “check if the player choice is already taken” logic. Easy fix.

I also added in a half second time delay before the AI move to give it a more “human” feel.

Good job! The only thing I would say is that it would be nice to have the computer start at somewhere other than center every now and then (unless you have it set to random and I just got center a whole bunch of time for whatever reason xD). Anyways, great job!

Yeah, the center is the best square and we were told to give it a robust AI. When it doesn’t matter I let it pick randomly, but claiming the center is the traditional first move. I think the video said that the AI should be unbeatable. But I don’t see that in the user stories. I’ve moved on to data visualization, but maybe before I put this in a portfolio, I’ll offer an “Imperfect AI” checkbox and let the AI occasionally make a less than perfect move.

Thank you for taking the time to look at it.

1 Like