Need Help with Tic-Tac-Toe Minimax

Need Help with Tic-Tac-Toe Minimax
0

#1

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.

https://jsfiddle.net/aeanpd8e/


#2

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:
https://mostafa-samir.github.io/Tic-Tac-Toe-AI/

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:
http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html
https://toddmotto.com/mastering-the-module-pattern/

Happy coding!
Gideon