Minimax Algorithm: A Complete Solved Numerical Example
Scenario: Strategy Game AI
The Objective: Work backwards from the bottom of the tree to find your safest guaranteed move against an opponent who is actively trying to minimize your score.
Core Mechanics▼
- MAX takes the Maximum: MAX seeks the highest possible score, assuming the best possible move for itself. It looks at all of its evaluated children and pulls up the largest number.
- MIN takes the Minimum: MIN seeks the lowest possible score, assuming the opponent plays perfectly against you. It looks at all of its evaluated children and pulls up the smallest number.
- Bottom-Up Evaluation: Interior nodes have no initial value. The algorithm must reach the terminal leaf nodes first, then pass those utility scores back up the tree layer by layer.
- Exhaustive Search: To guarantee the mathematically optimal move, basic Minimax must evaluate every single leaf node. There are no shortcuts and absolutely no pruned branches.
Step 1: The Initial Game Tree
Before we begin evaluating, here is the full structure of the game tree. Standard Minimax performs an exhaustive depth-first search, meaning it will evaluate every single node without any pruning.
Step 2: Step-by-Step Resolution
Watch the node values update as the depth-first search traverses back up. The active node being evaluated is highlighted with a glowing blue ring.
Evaluating Node: C
Position:Level 2 (Bottom-most evaluating layer)|Layer Type:MAX
Child Node Evaluations
Evaluating Node: D
Position:Level 2 (Bottom-most evaluating layer)|Layer Type:MAX
Child Node Evaluations
Evaluating Node: A
Position:Level 1 (Intermediate Layer)|Layer Type:MIN
Child Node Evaluations
Evaluating Node: E
Position:Level 2 (Bottom-most evaluating layer)|Layer Type:MAX
Child Node Evaluations
Evaluating Node: F
Position:Level 2 (Bottom-most evaluating layer)|Layer Type:MAX
Child Node Evaluations
Evaluating Node: B
Position:Level 1 (Intermediate Layer)|Layer Type:MIN
Child Node Evaluations
Evaluating Node: Root
Position:Level 0 (Root Node)|Layer Type:MAX
Child Node Evaluations
Final Takeaway
Notice how the algorithm assumes the opponent plays perfectly by blocking the highest score (9) at Node E and forcing us down to Node F (7). However, MAX still chooses the right side because a guaranteed 7 is safer than going left, where the MIN opponent would trap us with a 6.