I’m currently working on the Tic Tac Toe project, and I’m stuck with where to even begin? I understand that the most effective method for writing a decent AI for this would be using some sort of min max algorithm. However, I haven’t been able to find a decent example of a min max algorithm for tic tac toe that explains it from the ground up.

From what I’m understanding, a min max algorithm would essentially look at all possible moves the computer could make, then all the possible moves the other play could make, then could be made from there, and so on and so forth. Then it would figure out if any of those lead to it, within the next turn winning. If so, do that. If not, is there any plays with the other player could make which would result in them winning? If so, block that. Then try and find the next optimal move.

Largely my issue seems to be stemming from the inability to wrap my head around this. I understand the theory behind it, but how do I go about applying it in actual Javascript? So far with all the FCC projects, I’ve at least known where I can start, and then built off from there until I kinda just stumbled across the solution to the problem, but here I don’t even know where to begin with developing the algorithm. How can I tell if the computer is close to winning? How can I tell if the other player can win on their next turn?

Does anyone know any good places to go to go and get some good examples of minmax algorithms for tic tac toe? A lot of the ones I’m finding aren’t in Javascript, and thus have syntax which I don’t understand. The example project also doesn’t make sense to me. Is there any examples which break this sort of thing down into smaller chunks so it can be better understood?

Any help would be greatly appreciated!