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.

1

Evaluating Node: C

Position:Level 2 (Bottom-most evaluating layer)Layer Type:MAX

Initial Target: -\infty
Child Node Evaluations
Evaluated child 4 (returns 4)max(,4)=4max(-\infty, 4) = 4
Evaluated child 8 (returns 8)max(4,8)=8max(4, 8) = 8
Evaluated child 2 (returns 2)max(8,2)=8max(8, 2) = 8
Result: Node C locks in a value of 8.
Global Tree State (Step 1)
Root
A
B
C [8]
D
E
F
4
8
2
6
-3
5
9
0
7
3
2

Evaluating Node: D

Position:Level 2 (Bottom-most evaluating layer)Layer Type:MAX

Initial Target: -\infty
Child Node Evaluations
Evaluated child 6 (returns 6)max(,6)=6max(-\infty, 6) = 6
Evaluated child -3 (returns -3)max(6,3)=6max(6, -3) = 6
Result: Node D locks in a value of 6.
Global Tree State (Step 2)
Root
A
B
C [8]
D [6]
E
F
4
8
2
6
-3
5
9
0
7
3
3

Evaluating Node: A

Position:Level 1 (Intermediate Layer)Layer Type:MIN

Initial Target: \infty
Child Node Evaluations
Evaluated child C (returns 8)min(,8)=8min(\infty, 8) = 8
Evaluated child D (returns 6)min(8,6)=6min(8, 6) = 6
Result: Node A locks in a value of 6.
Global Tree State (Step 3)
Root
A [6]
B
C [8]
D [6]
E
F
4
8
2
6
-3
5
9
0
7
3
4

Evaluating Node: E

Position:Level 2 (Bottom-most evaluating layer)Layer Type:MAX

Initial Target: -\infty
Child Node Evaluations
Evaluated child 5 (returns 5)max(,5)=5max(-\infty, 5) = 5
Evaluated child 9 (returns 9)max(5,9)=9max(5, 9) = 9
Result: Node E locks in a value of 9.
Global Tree State (Step 4)
Root
A [6]
B
C [8]
D [6]
E [9]
F
4
8
2
6
-3
5
9
0
7
3
5

Evaluating Node: F

Position:Level 2 (Bottom-most evaluating layer)Layer Type:MAX

Initial Target: -\infty
Child Node Evaluations
Evaluated child 0 (returns 0)max(,0)=0max(-\infty, 0) = 0
Evaluated child 7 (returns 7)max(0,7)=7max(0, 7) = 7
Evaluated child 3 (returns 3)max(7,3)=7max(7, 3) = 7
Result: Node F locks in a value of 7.
Global Tree State (Step 5)
Root
A [6]
B
C [8]
D [6]
E [9]
F [7]
4
8
2
6
-3
5
9
0
7
3
6

Evaluating Node: B

Position:Level 1 (Intermediate Layer)Layer Type:MIN

Initial Target: \infty
Child Node Evaluations
Evaluated child E (returns 9)min(,9)=9min(\infty, 9) = 9
Evaluated child F (returns 7)min(9,7)=7min(9, 7) = 7
Result: Node B locks in a value of 7.
Global Tree State (Step 6)
Root
A [6]
B [7]
C [8]
D [6]
E [9]
F [7]
4
8
2
6
-3
5
9
0
7
3
7

Evaluating Node: Root

Position:Level 0 (Root Node)Layer Type:MAX

Initial Target: -\infty
Child Node Evaluations
Evaluated child A (returns 6)max(,6)=6max(-\infty, 6) = 6
Evaluated child B (returns 7)max(6,7)=7max(6, 7) = 7
Result: Node Root locks in a value of 7.
Global Tree State (Step 7)
Root [7]
A [6]
B [7]
C [8]
D [6]
E [9]
F [7]
4
8
2
6
-3
5
9
0
7
3

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.