Applying Minimax and Alpha-Beta to a Real Game
From game state to optimal strategyConsider the following Tic-Tac-Toe board in the middle of a game:
O's Dilemma: Where should O play to get the best possible outcome?
Solve O's strategic problem using systematic game tree analysis:
Goal: Determine O's best move and understand why it's optimal!
Show all possible moves and resulting board states (6 points)
In every branch, if X plays at position 1, X wins by completing the main diagonal (1-5-9). This is X's dominant strategy - O must find a way to deal with this threat!
| O's Move | X's Responses | Outcomes | Summary |
|---|---|---|---|
| 1 | X→2, X→3, X→7 | 0, 0, 0 | All moves lead to draws |
| 2 | X→1, X→3, X→7 | +1, 0, 0 | X wins with move 1 |
| 3 | X→1, X→2, X→7 | +1, 0, 0 | X wins with move 1 |
| 7 | X→1, X→2, X→3 | +1, 0, 0 | X wins with move 1 |
Determine optimal strategies for both players (8 points)
X can choose: {2, 3, 7}
Outcomes: [0, 0, 0]
MAX chooses: MAX(0, 0, 0) = 0
All X moves lead to drawsX can choose: {1, 3, 7}
Outcomes: [+1, 0, 0]
MAX chooses: MAX(+1, 0, 0) = +1
X will play at position 1 to winX can choose: {1, 2, 7}
Outcomes: [+1, 0, 0]
MAX chooses: MAX(+1, 0, 0) = +1
X will play at position 1 to winX can choose: {1, 2, 3}
Outcomes: [+1, 0, 0]
MAX chooses: MAX(+1, 0, 0) = +1
X will play at position 1 to winO has a way to force a draw! While most moves lead to X winning, O can play at position 1 to achieve a draw.
From the minimax perspective, O should choose position 1 - it's the only move that doesn't result in X's victory. This demonstrates the power of systematic game analysis in finding optimal strategies.
| Node Type | Position | Possible Outcomes | Operation | Result |
|---|---|---|---|---|
| MAX | After O→1 | [0, 0, 0] | MAX(0, 0, 0) | 0 |
| MAX | After O→2 | [+1, 0, 0] | MAX(+1, 0, 0) | +1 |
| MAX | After O→3 | [+1, 0, 0] | MAX(+1, 0, 0) | +1 |
| MAX | After O→7 | [+1, 0, 0] | MAX(+1, 0, 0) | +1 |
| MIN | Root | [0, +1, +1, +1] | MIN(0, +1, +1, +1) | 0 |
Why can O force a draw at position 1? When O plays at position 1, it blocks X's main diagonal threat (1-5-9). This prevents X from achieving any immediate winning combinations, forcing all subsequent moves to result in draws.
O's best move: Position 1 is clearly optimal, achieving a draw (0) while all other moves {2, 3, 7} allow X to win (+1). This demonstrates how a single strategic move can change the game's outcome.
Optimize the search while maintaining the same result (6 points)
Game outcome: 0 (Draw)
Update: α = MAX(-∞, 0) = 0
α = 0, β = +∞Game outcome: 0 (Draw)
No change to α (still 0)
No change to boundsGame outcome: 0 (Draw)
No change to α (still 0)
X chooses MAX = 0Branch 1 result: 0
Update β: β = MIN(+∞, 0) = 0
Current bounds: α = 0, β = 0
Game outcome: +1 (X wins)
Since +1 > β = 0, MIN won't choose this branch
β-cutoff: prune remaining X moves🚫 PRUNED!
Since X already found +1 > β = 0
MIN won't explore this branch furtherBranch 2 result: +1 (pruned after first move)
Since β = 0 (MIN's current best from Branch 1), and X can immediately get +1 in branches 3 and 4 by playing position 1, both branches can be entirely pruned:
X's first move would be position 1 → +1
🚫 ENTIRELY PRUNED!
Since +1 > β = 0, MIN rejects this branchX's first move would be position 1 → +1
🚫 ENTIRELY PRUNED!
Since +1 > β = 0, MIN rejects this branch| Step | Node | α | β | Action | Pruned? |
|---|---|---|---|---|---|
| 1 | Root | -∞ | +∞ | Initialize | No |
| 2 | O→1, X→2 | 0 | +∞ | Evaluate leaf: 0 | No |
| 3 | O→1, X→{3,7} | 0 | 0 | Complete branch: 0, β = 0 | No |
| 4 | O→2, X→1 | 0 | 0 | Evaluate leaf: +1 > β | Yes (β-cutoff) |
| 5 | O→3 | 0 | 0 | X would get +1 > β immediately | Yes (entire branch) |
| 6 | O→7 | 0 | 0 | X would get +1 > β immediately | Yes (entire branch) |
Efficiency gain: 67% reduction in leaf node evaluations while producing the identical result (0)!
In this specific game state, pruning is particularly effective because:
Understanding real-world game AI principles
This exercise demonstrates principles used in real game AI systems: