minimax() function is now returning a list of
move gives you the number you should pick to play an optimal game of Tic-Tac-Toe for any given game state.
This line of code instructs the AI to make a move as the
select_space(my_board, minimax(my_board, True), "X")
Take some time to really understand all of the parameters. Why do we pass
minimax()? Why do we use
 at the end of
Take some time to play a game against the computer. If you’re playing with
"X"s, make your move as
"X", and then call
minimax() on the board using
is_maximizing = False. The second item in that list will tell you the AI’s move. You can then enter the move for the AI as
"O", make your next move as
"X", and call the
minimax() function again to get the AI’s next move.
You can also try having two AIs play each other. If you uncomment the code at the bottom of the file, two AI will play each other until the game is over. What do you think the result will be? The file will run for about 15 seconds before showing you the outcome of the game.