Minimax in Python: Learn How to Lose the Game of Nim
You’ve gotten to know the steps of the minimax algorithm. In this section, you’ll implement minimax in Python. You’ll start by tailoring the algorithm directly to the game of Simple-Nim. Later, you’ll refactor your code to separate the core of the algorithm from the rules of the game, such that you can later apply your minimax code to other games.
Implement a Nim-Specific Minimax Algorithm
Consider the same example as in the previous section: it’s Maximillian’s turn, and there are six counters on the table. You’ll use the minimax algorithm to confirm that Maximillan can win this game and to calculate his next move.
First, though, consider a few examples of late-game situations. Assume it’s Maximillian’s turn and he sees