Adversarial Search Exercise

Minimax Algorithm with Alpha-Beta Pruning

Complete step-by-step analysis of game tree evaluation

Problem Statement

Step 1: Define the Game Environment

Consider a two-player, zero-sum strategy game between MAX and MIN:

  • MAX moves first and wants to maximize the final score
  • MIN moves second and wants to minimize MAX's score
  • Each player takes turns choosing from available actions
  • After a few moves, the game reaches a terminal state with a final utility value

Goal: MAX wants to guarantee the best possible outcome, assuming MIN plays optimally.

Step 2: How the Tree Represents All Possible Games
  • Root (MAX's turn): MAX can choose to go Left or Right
  • Level 1 (MIN's turn):
    • If MAX chose Left → MIN can pick action A, B, or C
    • If MAX chose Right → MIN can pick action D or E
  • Leaves (Game Over): Final utility values for MAX
🎯 Think of it like:
"What if MAX goes left, then MIN chooses A, then the game ends with score 3?"
Step 3: The Complete Game Tree

Each path from root to leaf represents one possible way the game could unfold.

MAX's Turn (Root)
MAX
MAX decides: "Go Left" or "Go Right"
MIN's Response
MIN
MIN
Left MIN: "Choose A, B, or C" | Right MIN: "Choose D or E"
MIN's Action Choices
A
B
C
D
E
Each action leads to different possible game endings
Final Game Outcomes (Utility for MAX)
3
12
8
2
14
5
2
10
Higher numbers = better for MAX, lower numbers = better for MIN
Step 4: Example Game Flows
Path 1: MAX→Left, MIN→A, MIN→Left child

MAX chooses LeftMIN chooses AGame ends: Score = 3

Path 2: MAX→Right, MIN→D, MIN→Right child

MAX chooses RightMIN chooses DGame ends: Score = 10

The tree shows ALL possible game sequences. MAX must pick a strategy that works no matter what MIN does!
MAX

Maximizing Player
Chooses highest value
MIN

Minimizing Player
Chooses lowest value
3

Terminal Values
Utility for MAX
Step 5: The Minimax Challenge

The Problem: MAX doesn't know which path MIN will choose! MAX needs a strategy that guarantees the best possible result regardless of what MIN does.

🤔 MAX's Dilemma:
  • "If I go Left, MIN might choose A (score 3) or B (score 2) or C (score 5)"
  • "If I go Right, MIN might choose D (score 2) or the E path (score 10)"
  • "What's the safest choice assuming MIN plays optimally against me?"
🧠 Minimax Solution:
  • Assume MIN is smart → MIN will choose the worst outcome for MAX
  • Plan accordingly → MAX chooses the option that gives the best worst-case
  • Work backwards → Start from leaves, propagate up the tree
Your Mission: Solve MAX's Strategy Problem

Now that you understand the game, you'll solve MAX's strategy problem using two approaches:

  • Part A: Standard Minimax → Evaluate ALL possible game endings
  • Part B: Alpha-Beta Pruning → Smart shortcuts while getting the same answer
  • Part C: Compare efficiency → See how much computation we can save

Key insight: Both methods find MAX's optimal strategy, but Alpha-Beta does it faster!

Learning Outcomes

By completing this exercise, you will be able to:

  • Connect game trees to real games → Understand how abstract trees represent concrete game situations
  • Apply the Minimax algorithm → Systematically evaluate optimal strategies for both players
  • Implement Alpha-Beta pruning → Use mathematical bounds to eliminate unnecessary computations
  • Analyze computational efficiency → Compare algorithmic performance and understand optimization trade-offs
  • Think like a game AI → Plan optimal moves in adversarial environments
  • 1. Perform the Minimax evaluation of the complete tree:
    • Evaluate all leaf nodes and propagate values upward
    • Apply MIN operation at MIN nodes, MAX operation at MAX nodes
    • Show the backed-up values at each internal node
    • Determine MAX's optimal action at the root
Standard Minimax Solution
1 Evaluate Terminal Nodes (Leaf Values):
The leaf nodes represent terminal game states with utilities for MAX:
Node A children: 3, 12
Node B children: 8, 2
Node C children: 14, 5
Node D children: 2, 10
2 Evaluate Internal Nodes A, B, C (MIN operations):
Node A
MIN(3, 12)
= 3
MIN chooses lower
Node B
MIN(8, 2)
= 2
MIN chooses lower
Node C
MIN(14, 5)
= 5
MIN chooses lower
3 Evaluate Left MIN Node:
The left MIN node has children A, B, C with values 3, 2, 5
Left MIN = MIN(3, 2, 5) = 2
MIN player chooses the minimum among all children
4 Evaluate Internal Node D (MIN operation):
Node D
MIN(2, 10)
= 2
MIN chooses lower
5 Evaluate Right MIN Node:
The right MIN node has only child D with value 2
Right MIN = 2
6 Evaluate Root MAX Node:
The root MAX node has children: Left MIN = 2, Right MIN = 2
Root MAX = MAX(2, 2) = 2
In case of tie, MAX chooses the leftmost option
Node Type Children Values Operation Result
A MIN [3, 12] MIN(3, 12) 3
B MIN [8, 2] MIN(8, 2) 2
C MIN [14, 5] MIN(14, 5) 5
Left MIN MIN [3, 2, 5] MIN(3, 2, 5) 2
D MIN [2, 10] MIN(2, 10) 2
Right MIN MIN [2] 2 2
ROOT MAX [2, 2] MAX(2, 2) 2
Minimax Evaluation Path:
A: 3
B: 2
C: 5
Left MIN: 2
D: 2
Right MIN: 2
ROOT: 2 (Choose Left)


MAX's Optimal Action: Choose Left Subtree, Value = 2
Evaluation Summary

Total nodes evaluated: All 8 leaf nodes + 6 internal nodes = 14 nodes. The standard minimax algorithm examines every possible terminal position to determine the optimal play, guaranteeing the best possible outcome for MAX assuming optimal play from both players.

  • 2. Perform Minimax with Alpha-Beta pruning:
    • Clearly show the α (alpha) and β (beta) values at each step
    • Identify which branches are pruned and explain why
    • Show the final optimal action and value at the root
    • Compare the number of evaluated nodes to standard minimax
Alpha-Beta Pruning Solution
1 Initialize Root (MAX node):
Start at root with initial bounds:
α = -∞ (best value MAX can guarantee)
β = +∞ (best value MIN can guarantee)
α represents MAX's lower bound, β represents MIN's upper bound
2 Explore Left MIN Subtree (α = -∞, β = +∞):
Evaluate Node A:
First leaf: 3
Update β = MIN(+∞, 3) = 3
α = -∞, β = 3
Second leaf: 12
Since 12 > β = 3, MIN ignores
Node A value = 3
Update Left MIN bounds:
β = MIN(+∞, 3) = 3 (Left MIN node's bound updated)
3 Evaluate Node B (α = -∞, β = +∞):
First leaf: 8
β = MIN(+∞, 8) = 8
Local bounds start fresh
Second leaf: 2
β = MIN(8, 2) = 2
B's final value = 2
No Pruning at B: Node B starts with fresh local bounds (α = -∞, β = +∞). Both children are evaluated normally.
Node B value = 2
4 Evaluate Node C (α = -∞, β = +∞):
First leaf: 14
β = MIN(+∞, 14) = 14
Local bounds start fresh
Second leaf: 5
β = MIN(14, 5) = 5
C's final value = 5
No Pruning at C: Node C starts with fresh local bounds (α = -∞, β = +∞). Both children are evaluated normally.
Node C value = 5
5 Complete Left MIN Evaluation:
Left MIN has children: A = 3, B = 2, C = 5
Left MIN = min(3, 2, 5) = 2
Left subtree returns value 2 to root
6 Update Root and Explore Right MIN Subtree:
Back at root: Left MIN = 2
Root updates α = MAX(-∞, 2) = 2
Right MIN subtree inherits bounds: α = 2, β = +∞
Evaluate Node D (α = 2, β = +∞):
First leaf: 2
β = MIN(+∞, 2) = 2
Check cutoff: β (2) ≤ α (2) ✓
Second leaf: 10
🚫 PRUNED!
β ≤ α cutoff triggered
Beta Cutoff: After Node D's first child = 2, we have β = 2 ≤ α = 2. This triggers the pruning condition! MIN at D cannot improve upon what MAX already guarantees from the left subtree.
Node D value = 2
🤔 Why is Node E skipped?

After the β-cutoff at D, the entire Right MIN node's value is fixed at 2.

Current Status:
  • MAX root knows: Left = 2, Right ≤ 2
  • D gives us Right MIN ≤ 2
  • Root will choose MAX(2, ≤2) = 2
Even if E had better values:
  • E = 1 or 0 → Right MIN = min(2, E) ≤ 2
  • MAX still chooses MAX(2, ≤2) = 2
  • Outcome unchanged!
✅ Key Insight: Once β ≤ α cutoff triggers, we know enough about the subtree to make the optimal decision without exploring further nodes.
7 Final Root Evaluation:
Root MAX chooses between:
Left subtree: 2
Right subtree: 2
MAX chooses: MAX(2, 2) = 2
In case of tie, MAX chooses the leftmost option
Step Node α β Action Result
1 Root -∞ +∞ Initialize Start search
2 A -∞ +∞→3 Evaluate [3,12] 3
3 B -∞ +∞ Evaluate [8,2] 2
4 C -∞ +∞ Evaluate [14,5] 5
5 Left MIN -∞→2 +∞ min(3,2,5) = 2 2
6 D 2 +∞→2 Found 2, β≤α, prune 10 2
7 Root 2 +∞ MAX(2,2) 2
Alpha-Beta Pruning Evaluation Path:
A: [3, 12] → 3 ✓
B: [8, 2] → 2 ✓
C: [14, 5] → 5 ✓
Left MIN: min(3, 2, 5) = 2 ✓
D: [2, pruned] → second child (10) cut ✗
Right MIN: 2 ✓
ROOT: MAX(2, 2) = 2 (Left subtree)


✅ Optimal Value = 2, Best Action = Left Subtree

📊 Leaves Evaluated: 7/8 (A: 3,12 | B: 8,2 | C: 14,5 | D: 2)
✂️ Leaves Pruned: 1/8 (D: 10) → 12.5% savings
Pruning Efficiency

Standard Minimax: 8 leaf evaluations

Alpha-Beta Pruning: 7 leaf evaluations

Pruned nodes: 1 leaf (D's second child: 10). This represents a 12.5% reduction in evaluated nodes while maintaining the same optimal result.

  • 3. In 2-3 sentences, explain how alpha-beta pruning changes the search process compared to standard minimax.
Comparison Analysis
Standard Minimax
  • Completeness: Evaluates every terminal node
  • Guaranteed optimal: Always finds the best move
  • Time complexity: O(b^d) where b=branching factor, d=depth
  • Space complexity: O(bd) for recursive calls
  • Simplicity: Straightforward implementation
8 leaf evaluations
Examines all possibilities
Alpha-Beta Pruning
  • Efficiency: Eliminates irrelevant branches
  • Same result: Produces identical optimal moves
  • Best-case pruning: O(b^(d/2)) - dramatic improvement
  • Move ordering sensitive: Better ordering = more pruning
  • Complexity: Slightly more complex bookkeeping
6 leaf evaluations
25% reduction in this example
Detailed Explanation

Alpha-beta pruning optimizes the minimax search by maintaining bounds on achievable values (α for MAX's guaranteed minimum, β for MIN's guaranteed maximum) and eliminating branches that cannot influence the final decision. When the algorithm determines that a subtree cannot produce a better result than alternatives already found, it prunes that entire subtree without evaluation, significantly reducing search time while maintaining the same optimal result as standard minimax.

Performance Comparison
  • Standard Minimax: Always O(b^d)
  • Alpha-Beta Best Case: O(b^(d/2))
  • Alpha-Beta Average: O(b^(3d/4))
  • Practical speedup: 2-1000x faster
Key Pruning Insights
  • α-cutoff: MAX found better alternative
  • β-cutoff: MIN found better alternative
  • Move ordering: Good moves first = more pruning
  • Transposition tables: Further optimizations possible
1 Search Process Difference:

Standard minimax explores every path to completion before making decisions, while alpha-beta pruning uses partial information to eliminate unpromising branches early in the search process.

2 Bound Maintenance:

Alpha-beta maintains running bounds (α and β) that represent the best outcomes each player can guarantee, allowing immediate recognition when a branch cannot improve upon already-found alternatives.

3 Identical Results:

Both algorithms produce the same optimal decision, but alpha-beta achieves this with significantly fewer node evaluations, making it practical for deeper searches in real-time game applications.

Adversarial Search Fundamentals
  • Game theory: Optimal play against rational opponents
  • Zero-sum games: One player's gain is another's loss
  • Minimax principle: Minimize maximum possible loss
  • Perfect information: Complete game state visibility
Optimization Techniques
  • Pruning: Eliminate irrelevant search branches
  • Bounds tracking: Maintain achievable value ranges
  • Early termination: Stop search when outcome is determined
  • Move ordering: Examine promising moves first
Key Educational Insights
  • Algorithmic optimization: Same results with less computation
  • Bound-based pruning: Mathematical foundations of efficiency
  • Game tree analysis: Systematic evaluation of strategic options
  • Worst-case reasoning: Planning for optimal opponents
  • Practical scalability: Making deep search feasible
  • Trade-off analysis: Complexity vs. performance benefits
  • Real-world applications: Chess, checkers, and game AI
  • Computational thinking: Smart search vs. brute force
Common Mistakes to Avoid
❌ Algorithm Errors:
  • Confusing MAX and MIN operations
  • Incorrect alpha/beta bound updates
  • Wrong pruning condition checks
  • Forgetting to propagate values upward
❌ Conceptual Errors:
  • Not understanding pruning doesn't change results
  • Misapplying α-cutoff vs β-cutoff conditions
  • Incorrect node type identification
  • Poor bound initialization or maintenance
✅ Pro tip: Always verify that pruned branches truly cannot affect the final result!
Beyond Basic Minimax
🚀 Advanced Optimizations:
  • Iterative deepening search
  • Transposition tables (memoization)
  • Quiescence search for tactical positions
  • Null-move pruning for deeper search
🎯 Real-world Applications:
  • Chess engines (Deep Blue, Stockfish)
  • Checkers (solved game using minimax)
  • Go programs (combined with Monte Carlo methods)
  • Two-player strategy games and puzzles

Continue Learning