Alpha-Beta Pruning: A Complete Solved Numerical Example
Scenario: Turn-Based Board Game AI
The Objective: You are programming an AI (MAX) to find the move that yields the highest score, while anticipating an opponent (MIN) who will always choose the path that hurts you the most. Use Alpha-Beta Pruning to find the optimal path while instantly cutting off branches that are mathematically irrelevant.
Core Mechanics▼
- MAX only updates : It starts at because MAX is searching for the highest possible value. represents the best score MAX is guaranteed so far.
- MIN only updates : It starts at because MIN is searching for the lowest possible value. represents the best score MIN is guaranteed so far.
- Down vs. Up: The boundary limits ( and ) flow down the tree. The evaluated leaf scores flow up the tree.
- The Cutoff: If at any node, the algorithm instantly stops evaluating that branch. The opponent would never allow this path to be reached!
Step 1: The Initial Game Tree
Before we begin evaluating, here is the full structure of the game tree. The algorithm tracks (Alpha) for the MAX player and (Beta) for the MIN player.
Step 2: Step-by-Step Resolution
Watch the full global tree 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: E
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: 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 the two types of pruning! At Node D (Beta Cutoff): MIN already secured an 8 at Node C. When D reveals a 9, MIN immediately rejects it, saving us from checking D's remaining leaves. At Node B (Alpha Cutoff): Node F caps B's potential at 6. Since MAX already secured a guaranteed 7 on the left side, it completely abandons the entire right branch (G)!