Need Help with Tic-Tac-Toe Minimax

Need Help with Tic-Tac-Toe Minimax


I have difficulty getting my tic-tac-toe’s minimax to work.

Can I get some help?

My approach was to have 2 arrays

  • Player spots
  • AI spots

Function to check for wins works
Function to check for empty spots also works

but I can’t get the minimax to work for the life of me.


Hi nstyler,
I looked at your JSFiddle for a while yesterday. I really like that you are trying to have the AI win algorithmically. I was unable to figure out the problem you are having, but I found a resource that might help a lot:

Also I suggest you organize your code a bit better… I started using a module method that helps clarify the intent of all of my code, making each part of my code fit together in ways that make everything clearer. That makes getting help from other campers and developers easier. I found these two pages invaluable for this:

Happy coding!