Skip to content
Advertisement

Why does my tic tac toe minimax algorithm not work?

Sorry to dump my code like this, but I’ve been pulling my hair out the last hours trying to figure out where my minimax algorithm in python is going wrong. Any help is greatly appreciated!

JavaScript

Output: [1, 0] Expected output: [2, 0]

Advertisement

Answer

You are always sending a 1 in case ‘X’ wins, this is not correct. This means that if it is O:s turn it will think it is good if X wins. The easiest way would be to give a different value depending on who’s turn it is, that is give a score of 1 if YOURSELF win, -1 if OPPONENT wins and 0 if draw.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement