Part I · Chapter 3

Adversarial search: Minimax, α-β pruning & Expectimax

By the end of this page you will be able to take any small game tree, compute its minimax, α-β and expectimax values by hand, name the action the agent should play, say exactly which branches get pruned and why, and explain what breaks when your model of the opponent is wrong.

Essentials

How to pick a move when someone else moves next — and when you cannot search to the end.

Everything below is the explanation and the practice. If you are short on time, read this box, then go to the problems.

Why games, and what changes from Chapter 1

In search and informed search the world sat still while you thought, and the answer was a sequence: Left, Left, Up, Right. Now another agent is choosing actions too, and it chooses after seeing what you did. A fixed sequence of moves is worthless: your second move has to depend on what the opponent just played. That one change — a second decision-maker interleaved with yours — is what "adversarial" means, and it changes the type of the answer.

Where the uncertainty comes from

An opponent is only one source of uncertainty; the lecture lists the others, all handled by the same machinery:

That last bullet is the one that matters. Chess hides nothing — no dice, no noise, the whole board is visible — and yet no machine and no human will ever play it perfectly. Computational limits produce uncertainty that is, from the agent's point of view, indistinguishable from randomness. Half of this chapter (evaluation functions, depth limits, pruning) exists only because of that.

Seventy-five years of game AI, in one screen

Untestable, but each milestone names an idea you meet again. ("Ply" = one player's move.)

Intuition

What changed across all three was never "we found the true minimax value," but one of: search deeper for the same money (α-β); judge a non-final position better (evaluation functions); or replace a hand-written judgement with a learned or sampled one (Samuel, MCTS). Those three levers are the whole chapter.

Classifying games along five axes

Before writing an algorithm, work out which game you are in. Five independent questions:

Figure 1a · The five axes, with real games at each pole
AxisOne poleOther poleWhy it matters to the algorithm
Deterministic vs stochastic Deterministic — chess, checkers, Go, tic-tac-toe, Connect 4 Stochastic — backgammon, Monopoly, Tetris, poker, Yahtzee Randomness adds chance nodes: you need expectation, not max/min.
Perfect vs imperfect information Perfect — chess, Go, backgammon (dice are random but public) Imperfect — poker, bridge, Stratego, Battleship, StarCraft With imperfect information a "state" is a belief over states; plain minimax is not enough.
Number of players One — 8-puzzle, Sudoku, Rubik's cube (this is just Chapter 1 search) Two — chess; Three or more — Catan, Hearts, Diplomacy Three or more players means values become tuples, one per player.
Turn-taking vs simultaneous Turn-taking — chess, checkers, Go, Monopoly Simultaneous — rock-paper-scissors, StarCraft, soccer, sealed-bid auctions If moves are simultaneous there may be no best deterministic move; you need randomised strategies.
Zero-sum vs general-sum Zero-sum — chess, Go, poker for money General-sum — Diplomacy, prisoner's dilemma, driving, negotiation Zero-sum lets you track a single number instead of one per player.
What to notice: these axes are independent. Backgammon is stochastic and perfect-information; Stratego is deterministic and imperfect-information. Do not collapse "random" and "hidden" into one idea.
Figure 1b · The classic 2×2: chance versus visibility
Perfect informationImperfect information
Deterministic chess, checkers, Go, Othello, tic-tac-toe
→ minimax + α-β
Battleship, Stratego, Kriegspiel
→ reason over belief states
Stochastic backgammon, Monopoly, Tetris
→ expectimax / expectiminimax
poker, bridge, Scrabble
→ both problems at once
What to notice: this course lives almost entirely in the top-left cell, then takes one step down into the bottom-left with expectimax. The right column is where poker research and modern economics-of-information sit.

Zero-sum versus general games

Definition

A game is zero-sum if the players' utilities are exactly opposed: for every terminal state $s$, $\text{Utility}(s,\text{P}_1) + \text{Utility}(s,\text{P}_2) = 0$. (Any constant sum works identically — "zero-sum" is the conventional name.) A general game puts no such constraint on the utilities; each agent simply has its own.

Why care about this technicality? Because player two's utility carries no information that player one's doesn't already carry: it is just the negative. So instead of a vector of utilities per node, you can label every node with a single number — player one's utility — and describe both players with two words:

One number, two opposite preferences. That is the entire reason the algorithm is called mini-max and not something with a subscript per player.

General games are qualitatively different, not just messier. With independent utilities you get cooperation, indifference, competition, shifting alliances — two players can find a move that helps them both at a third's expense without ever communicating. See generalized minimax: the single number becomes a tuple again.

The standard game formulation

The course focuses on "standard" games: deterministic, fully observable, two-player, turn-taking, zero-sum — one corner of the five-axis space. The rest of this chapter is what you do when you fall out of it.

Definition

A standard game is the tuple:

Compare line by line with the Chapter 1 search problem: $s_0$, $\text{Actions}$, $\text{Result}$ are identical. Two things change. $\text{Player}(s)$ is new, and the goal test has been replaced by a terminal test plus a number — terminating isn't the point, terminating well is, so we carry a real-valued utility instead of a boolean.

The output is a policy, not a plan. Belabour this.

From the notes: "Our goal is to calculate a contingent plan, also called a strategy or policy, which recommends a move for every possible game state." Three words for one object — contingent plan = strategy = policy — and the important word is contingent.

In Chapter 1 the solution to the 8-puzzle was a list, [Up, Left, Left, Down], that you could write on a napkin and hand to someone. Try that in chess. You write [e4, Nf3, Bc4, Qh5, Qxf7#], your opponent plays something other than the moves the napkin silently assumed, and by move two the list is nonsense — possibly not even legal. It failed not because the moves were bad but because it was the wrong type of object.

Analogy

A sequence of actions is a recipe: do step 1, step 2, step 3 in order. A policy is a chess opening book: "after 1.e4 e5 2.Nf3, if Nc6 then Bb5; if Nf6 then Nxe5; if d6 then d4…" — an answer prepared for every branch, including branches that never happen. Where the analogy strains: a real opening book covers sensible moves and shrugs at nonsense, while a policy is total, defined at every reachable state.

Formally a policy is a function $\pi : S \to A$ with $\pi(s) \in \text{Actions}(s)$ at every state where it is your turn. Its size is on the order of the number of reachable states, not the length of a path — which is why a game solution is exponentially bigger than a search solution, and why the algorithms below work hard at not writing it down. Minimax computes the policy implicitly: it hands you the values of the children of wherever you are, you take the argmax, and doing that every turn executes the policy without ever storing it. You meet $\pi$ again with exactly this meaning at MDPs and reinforcement learning.

Your opponent makes a move you thought was terrible and never planned for. What does a correct policy do?
Why: "Contingent" means total. Minimax assumes optimal play when it computes values, but the object it defines is still a move for every state — if the opponent blunders, you are in a state whose value you can compute and whose best action you can take, and it will be at least as good as the value you were guaranteed. The failure mode of a wrong opponent model is losing value (see modelling assumptions), never having no move at all.

Minimax: the value of a state under optimal play

Definition

The minimax value of a state is the utility (to MAX) of that state assuming both players play optimally from there on. Equivalently: the best outcome the player to move can guarantee, no matter what the opponent does.

$$ V(s) \;=\; \begin{cases} \text{Utility}(s) & \text{if } \text{Terminal-Test}(s)\\[4pt] \max_{a \in \text{Actions}(s)} V(\text{Result}(s,a)) & \text{if } \text{Player}(s) = \text{MAX}\\[4pt] \min_{a \in \text{Actions}(s)} V(\text{Result}(s,a)) & \text{if } \text{Player}(s) = \text{MIN} \end{cases} $$

Read the symbols: $V(s)$ is a single number, the value of state $s$ to MAX; $\text{Result}(s,a)$ is the child you reach by playing $a$; the $\max$ and $\min$ range over the legal actions at $s$. Nothing here is approximate — it is a definition by recursion on the game tree, bottoming out at terminal states.

Note the word guarantee — the strongest claim in this chapter. If minimax says a state is worth $+4$ to you, some strategy of yours gets at least 4 against every possible opponent, and against an optimal one you cannot get more: a floor you can always reach and a ceiling a good opponent can impose.

Drawing the tree

States are nodes, actions are branches. Conventionally, as in the slides:

Common mistake

Every number in the tree is written from MAX's point of view. A leaf labelled $-2$ does not mean "MIN scores 2." It means MAX scores $-2$, and therefore (zero-sum) MIN scores $+2$. MIN's value of any node is just the negation of the printed number. Students who start silently flipping signs at MIN nodes get every problem wrong; MIN minimises the printed number, and that is already MIN acting in its own self-interest.

The worked example from the notes

The blue MAX player moves first and chooses Left, Center, or Right. Then the red MIN player picks one of its two replies, trying to make the resulting number as small as possible. The six leaves are $3, 12 \mid 4, 6 \mid 15, 2$.

Figure 2 · Minimax on the notes' example — values propagate up from the leaves
MAX to move (you) Left Center Right 4 3 4 2 Jump Hide Jump Run Hide Run 3 12 4 6 15 2
Blue upward triangle = MAX node (takes the max of its children). Red downward triangles = MIN nodes (take the min). Squares = terminal utilities, always stated from MAX's point of view. Highlighted edges are the moves each player would actually make — the principal variation. What to notice: the 15 is the biggest number on the board and it is completely irrelevant, because MIN will never let MAX have it.

Working from the leaves upward:

Key idea

The minimax value at the root is $4$ — but the number 4 is not the answer. The agent cannot "play a 4." It must select an action. The answer is Center, the action whose child carries the value 4.

$$\hat{a} \;=\; \argmax_{a \in \text{Actions}(s_0)} V(\text{Result}(s_0,a)), \qquad V(s_0) = \max_{a} V(\text{Result}(s_0,a))$$

The value $V$ and the decision $\hat a$ are computed by the same sweep; one is the max, the other is the argmax. Exams ask for the action. Give the action.

The generic pseudocode

Straight from the notes. Two functions: one that picks the move at the root, one recursive routine that computes a value.

function max_decision(state):
    return the action in state.actions that gives
           the max value( state.result(action) )

function value(state):
    if state.is_leaf:
        return state.value
    if state.player is MAX:
        return max over value(state.result(a)) for a in state.actions
    if state.player is MIN:
        return min over value(state.result(a)) for a in state.actions

Three things to note: there is exactly one recursive function, dispatching on whose turn it is (α-β will force us to split it into max_value/min_value); the base case is is_leaf, i.e. Terminal-Test; and max_decision returns an action while value returns a number — the type distinction from the Key idea box, made concrete in code.

The same skeleton with a chance case bolted on is expectiminimax, used in the expectimax section:

function value(state):
    if state.is_leaf:
        return state.value
    if state.player is MAX:
        return max over value(state.result(a)) for a in state.actions
    if state.player is MIN:
        return min over value(state.result(a)) for a in state.actions
    if state.player is CHANCE:
        return sum over P(s) * value(s) for s in state.next_states

One extra branch. That is the whole difference between minimax and expectiminimax.

Guided problem 1Compute the minimax value and name the action

A MAX root has three actions A, B, C. Each leads to a MIN node. The MIN nodes' children are terminal:

Root actionMIN node's terminal children
A−1, 8, 4
B7, 3
C6, 6, 20

(a) What is the minimax value at the root? (b) Which action should MAX play? (c) MAX plays your answer and MIN, being careless, replies with the move that leads to the largest leaf in that subtree instead. What does MAX actually score, and does that contradict anything?

Step 1 — What kind of node is each, and in what order do I evaluate?

Leaves have their values given. The three interior nodes are MIN nodes — the opponent moves there — so each takes the minimum of its children. The root is a MAX node and takes the maximum of the three MIN values. Always evaluate bottom-up: you cannot know the root until you know its children.

Step 2 — Evaluate the three MIN nodes

$V(A) = \min(-1, 8, 4) = -1$. The 8 and the 4 are irrelevant; MIN will play the $-1$.

$V(B) = \min(7, 3) = 3$.

$V(C) = \min(6, 6, 20) = 6$. The 20 is a trap for the greedy eye — MIN will never allow it.

Step 3 — Evaluate the root

$V(\text{root}) = \max(-1,\; 3,\; 6) = 6$, achieved by the child reached through action C.

Answer & the takeaway

(a) The minimax value is $\mathbf{6}$. (b) MAX plays $\mathbf{C}$. Not "6" — C.

(c) If MIN carelessly plays toward the 20, MAX scores 20. This contradicts nothing. Minimax guarantees at least the minimax value; it is a lower bound on what you get, and a suboptimal opponent can only hand you more. The guarantee is one-sided.

Takeaway: notice that the tree contains the numbers 8 and 20, both far larger than 6, and neither is reachable against a competent opponent. The size of the numbers in a subtree tells you nothing. Only the value that survives the alternating min/max filter matters.

What minimax costs, and bounded rationality

Minimax as written is exhaustive depth-first search of the game tree with an arithmetic operation on the way back up, so its complexity is DFS's.

Proof

Time: $O(b^m)$. Let $b$ be the branching factor (legal moves per state) and $m$ the maximum depth of the tree in plies. The root generates $b$ children; each of those generates $b$, giving $b^2$ at depth 2; by induction depth $k$ holds $b^k$ nodes. Every node must be visited, because a node's value depends on all of its children (the max or min is over the complete set). Total work:

$$1 + b + b^2 + \cdots + b^m \;=\; \frac{b^{m+1}-1}{b-1} \;=\; \Theta(b^m)$$

The sum is dominated by its last term — the bottom level alone contains more nodes than all the levels above it combined (for $b \ge 2$). So the exponent is what matters and constants are irrelevant.

Space: $O(bm)$. DFS holds only the current root-to-leaf path in memory, which is $m$ nodes deep. At each node on that path we must remember its generated-but-not-yet-explored siblings so we can continue the loop after the recursive call returns — that is at most $b$ children per level. Hence $b$ items on each of $m$ levels: $O(bm)$. Note it is $b \times m$, not $b^m$: memory is polynomial while time is exponential. That asymmetry is exactly why we use DFS here instead of BFS.

Plug in chess

For chess, $b \approx 35$ and $m \approx 100$. So the tree has on the order of

$$35^{100} \approx 10^{154}$$

nodes, against roughly $10^{80}$ atoms in the observable universe. Exact solution of chess is not "hard", it is physically impossible. And yet humans play chess well, examining perhaps a hundred positions per move — not with a secret polynomial algorithm but with a good approximate evaluation and a good sense of which few moves are worth looking at.

Definition

Bounded rationality (Herbert Simon, 1957) — the observation that real decision-makers, human or machine, do not optimise. They are limited in the information they have, in the time available, and in their own ability to compute. So rationality must be redefined relative to those limits: a bounded-rational agent satisfices, searching until it finds an option good enough rather than provably best.

This is not just an excuse for approximation. "A rational agent maximises expected utility" is vacuous when the maximisation cannot be performed, so Simon treats the cost of deliberating as part of the problem: not "what is the optimal move?" but "what is the best move I can identify with the computation I can afford?" Every technique below — depth limits, evaluation functions, pruning, sampling — answers that second question. Chess engines are not failed exact solvers; they are successful bounded-rational agents.

Resource limits: bounded lookahead and the horizon

The problem: in a realistic game you cannot search to the leaves. The recursion in value() bottoms out at is_leaf, and it never gets there before your clock runs out.

Solution 1: bounded lookahead. Two changes to the algorithm:

  1. Search only to a preset depth limit, also called the horizon.
  2. When you hit that depth on a non-terminal position, call an evaluation function $\text{EVAL}(s)$ and pretend the number it returns is the utility.

The change to the code is two lines: pass a depth counter down, and replace if state.is_leaf: return state.value with if state.is_leaf or depth == 0: return EVAL(state).

Common mistake

The guarantee of optimal play is gone. Depth-limited minimax no longer computes the minimax value; it computes the minimax value of a different, truncated game whose payoffs are your evaluation function's guesses. Everything proved above about guaranteed outcomes evaporates. This is not a small caveat — it means a depth-limited engine can be talked into a bad position by anything that hides the consequences just past its horizon.

Figure 3 · Depth-limited search: the tree is cut off at the horizon and EVAL takes over
4 MAX −2 4 MIN −1 −2 4 9 EVAL depth limit / horizon — search stops here ???? everything below the horizon is invisible to the search
What to notice: the numbers −1, −2, 4, 9 are not utilities of finished games. They are EVAL's opinions about unfinished positions. The MIN row takes min(−1,−2) = −2 and min(4,9) = 4; the root takes max(−2,4) = 4 and plays right. If EVAL is wrong about any of those four positions, the root's decision can be wrong, and nothing in the algorithm will notice.

The arithmetic that sets the depth

The slides work a concrete budget, and you should be able to redo it for any numbers on an exam:

Depth 4 is two moves each, and the slides' verdict is "not so good" — a club player looks further. Exactly: $d = \log_{35}(10^6) = 6/\log_{10}35 \approx 6/1.544 \approx 3.9$. Hold on to this number; α-β pruning will double it.

Depth matters

Two claims from the slides, in order of importance:

  1. Evaluation functions are always imperfect. If yours were perfect it would return the true minimax value, you would search depth 1, and the game would be solved. It isn't and you can't.
  2. Deeper search ⟹ better play (usually). EVAL's errors at the frontier get filtered on the way up through many layers of max and min: a position that merely looks good at depth 2 has had six more plies of the opponent's best objections applied to it by depth 8. ("Usually" is a real hedge — pathological trees exist where deeper minimax is worse, because it propagates the extreme of a set of noisy estimates. beyond syllabus)
Key idea

This is the tradeoff between complexity of features and complexity of computation. With a fixed budget of nodes per move, a richer evaluation function (more features, slower per call) costs you depth; a crude fast one buys depth. Neither extreme wins: an EVAL that only counts material is fast but blind, and one that is nearly the true minimax value is so slow you see one ply. You meet this tradeoff again as bias–variance and model capacity in Part II.

Evaluation functions

Evaluation functions score non-terminals in depth-limited search: "this game isn't over — how good does it look for MAX?" The ideal one returns the position's actual minimax value, which would make bounded lookahead exact — but computing that is the problem we were avoiding, so the ideal defines the target, not a method. In practice the standard form is a weighted linear sum of features:

$$\text{EVAL}(s) \;=\; w_1 f_1(s) + w_2 f_2(s) + \cdots + w_n f_n(s)$$

Naming the symbols: $f_i(s)$ is the $i$-th feature, a number computed cheaply from the board; $w_i$ is its weight, saying how much it matters and in which direction; $\text{EVAL}(s)$ is the resulting score, positive for "good for MAX."

The classic chess example: $w_1 = 9$ with $f_1(s) = (\text{number of white queens} - \text{number of black queens})$. The feature is a difference, so it is automatically zero-sum-symmetric and goes negative when black is ahead, and the weight 9 is the queen's value in pawn units. A full material term is $9\Delta Q + 5\Delta R + 3\Delta B + 3\Delta N + 1\Delta P$, plus positional features: pawn structure, king safety, centre control, mobility, rook on an open file.

Example

Evaluation for Pacman. An agent scoring only "current game score" stalls, because a dot two steps away and a dot five steps away look identical inside the horizon. Useful features: game score (positive); negative distance to the nearest food (the heuristics of the last chapter returning as features); food pellets remaining (negative); distance to the nearest non-scared ghost (positive, usually capped — 30 squares away is not 10× better than 3); distance to the nearest scared ghost (negative, you chase it); capsules left (negative).

The last two have opposite signs on the same underlying measurement, which is why a single "ghost distance" feature fails. Redundant features with tuned weights are fine in a linear EVAL; it is missing features that kill you.

What a bad evaluation function does to you

The most famous failure mode is the horizon effect. beyond syllabus Your engine is losing a bishop in three plies, unavoidably — but it can throw away a pawn to check the king and delay the capture past its depth limit. The truncated tree then says "sacrifice the pawn, the position looks fine," so the engine sheds pawn after pawn to push the inevitable just beyond where it can see. EVAL is not wrong about any position it is asked about; it is never asked about the one that matters. The standard fix is quiescence search: at a position with captures pending, extend along forcing moves until things settle, then evaluate. The lesson generalises: a bounded agent's blind spot is exactly where an adversary will aim.

Your chess engine gets twice as fast. Which is not a sensible way to spend the speedup?
Why: Answering faster is worth nothing unless you are losing on the clock — the strength of a bounded-rational agent is set by how much computation it uses, not by how fast it finishes. The other three all convert speed into playing strength, and choosing between them is exactly the feature-complexity vs computation-complexity tradeoff.

Generalized minimax: non-zero-sum and multiplayer games

If the game is not zero-sum, or has more than two players, the single-number trick fails: you cannot recover players 2 and 3's utilities from player 1's. So you stop trying.

Definition

Generalized minimax. For an $n$-player game:

Crucially the node inherits the whole tuple of the winning child, not just the component that was maximised — because the players above still need to know what they get if play goes down here.

Two-player zero-sum is the special case $u_2 = -u_1$, where "player 2 maximises $u_2$" is literally "player 2 minimises $u_1$" and the second component is redundant. The interesting consequence of the general case: cooperation and competition arise dynamically, without being programmed in. In the tree below players 1 and 2 have identical payoffs everywhere, so they behave like partners against player 3 for free.

Figure 4 · Generalized minimax with three players — every node carries a tuple
8,8,1 8,8,1 7,7,2 0,0,7 8,8,1 7,7,2 0,0,8 1,1,6 0,0,7 9,9,0 8,8,1 9,9,0 7,7,2 0,0,8 0,0,7 P1: max u₁ P2: max u₂ P3: max u₃ terminal utility tuples (u₁, u₂, u₃)
What to notice: player 3 (violet row) picks purely on the third number and hands the whole tuple up. The highlighted path is what actually gets played. Player 1 ends up with 8 even though tuples containing 9 exist — those 9s sit behind choices that belong to players 2 and 3.

Walking Figure 4 node by node

Player 3's row compares third components: $(1,1,6)$ vs $(0,0,7)$ ⟹ $(0,0,7)$; $(9,9,0)$ vs $(8,8,1)$ ⟹ $(8,8,1)$; $(9,9,0)$ vs $(7,7,2)$ ⟹ $(7,7,2)$; $(0,0,8)$ vs $(0,0,7)$ ⟹ $(0,0,8)$ — the entire tuple of the winner moves up each time, and player 3 is indifferent to what it costs the others. Player 2's row compares second components: $(0,0,7)$ vs $(8,8,1)$ ⟹ $(8,8,1)$; $(7,7,2)$ vs $(0,0,8)$ ⟹ $(7,7,2)$. Player 1 at the root compares first components: $(8,8,1)$ vs $(7,7,2)$ ⟹ root value $(8,8,1)$, so player 1 plays Left.

Players 1 and 2 never negotiated, yet both steered toward $(8,8,1)$ and away from player 3's preferred leaves: an alliance emergent from self-interest, because their payoffs happen to align here. Change one leaf and it dissolves, with nothing in the algorithm changing — the coalition structure is a consequence of the numbers, not an input.

Common mistake

Do not maximise every component, and do not propagate only the component that was maximised. Node 2 in player 3's row is $(8,8,1)$, not $1$ and not $(9,9,1)$. The tuple travels intact.

Alpha-beta pruning

Minimax visits every node, but the worked example already showed that most of them do not matter: once MIN's left subtree revealed a 3, the rest of that subtree was irrelevant. α-β pruning is the systematic version, and it computes exactly the same root value as minimax while often skipping most of the tree.

Definition

Two numbers are carried down the recursion along the current path:

$\alpha$ only ever increases as you go down a path; $\beta$ only ever decreases. The interval $[\alpha, \beta]$ is the window of values that could still matter at the root. If a node's value provably falls outside the window, the rest of that node is not worth computing.

What the cutoff test actually means

This is the part everybody memorises and nobody understands, so here it is in slow motion. Consider a MIN node $n$ in the middle of being evaluated. Two facts: (i) MIN takes the minimum over $n$'s children, so $n$'s value can only go down as more children are examined — whatever it ends up as, it is $\le$ anything seen so far at $n$; (ii) somewhere on the path above there is a MAX node that already has an alternative worth $\alpha$.

So if the running value at $n$ reaches $v \le \alpha$, then $n$'s final value is $\le v \le \alpha$, and the MAX node above is comparing "at most $\alpha$" (through $n$) against "$\alpha$, guaranteed" (what it already holds). MAX is never coming down here, and the remaining children can only lower $n$ further. Stop and return $v$ immediately.

The mirror image at a MAX node $n$: its value can only go up, so if the running $v \ge \beta$ then $n$'s final value is $\ge \beta$, the MIN node above already has an option worth $\beta$, and MIN will never come down here either. Stop.

The exact pseudocode

From the slides, verbatim. Note that α-β does need the two cases written separately, because the cutoff test and the bound update are mirror images:

α: MAX's best option on path to root
β: MIN's best option on path to root

def max-value(state, α, β):
    initialize v = -∞
    for each successor of state:
        v = max(v, value(successor, α, β))
        if v ≥ β
            return v            # cutoff: MIN above won't allow this node
        α = max(α, v)
    return v

def min-value(state, α, β):
    initialize v = +∞
    for each successor of state:
        v = min(v, value(successor, α, β))
        if v ≤ α
            return v            # cutoff: MAX above won't come down here
        β = min(β, v)
    return v

Line by line for max-value: v is the best child value so far, starting at $-\infty$ so the first child always improves it; we recurse into each successor passing the current window down; after updating v we test v ≥ β and quit if our value has reached the level MIN can avoid; otherwise we raise α, because if MAX chooses this node it has secured at least v and every deeper node should know.

Common mistake

The order of the three statements inside the loop is not negotiable: update v, then test the cutoff, then update the bound. And do not mirror the bounds wrongly — updating $\alpha$ inside min-value instead of $\beta$ is the classic bug. In max-value you test against $\beta$ and update $\alpha$. In min-value you test against $\alpha$ and update $\beta$. You always test against the other player's bound and update your own.

Two tiny examples, to drill the tests

max-value cutoff

We are at a MAX node that was called with β = 10. Its first child returns 10, so $v = 10$. Test: is $v \ge \beta$? $10 \ge 10$ — yes, return immediately. The second child (which happens to be worth 100) is never examined.

Why: the MIN node above already has a move worth 10, and this node is worth at least 10 and can only grow, so MIN takes its 10 elsewhere and the 100 is unreachable. The cutoff fires on equality — a tie is enough, since we only need MIN to have an option at least as good.

min-value cutoff

We are at a MIN node called with α = 10, whose children are 10, 100, 2 left to right. Child 1: $v = 10$; is $10 \le 10$? Yes — cutoff, return 10. The 100 and the 2 are never examined.

Why: MAX already holds 10 above, so this node, worth at most 10, gains MAX nothing. And look what we skipped: the 2, which was this node's true value. We returned 10 when the true value is 2. That is allowed, and it is the subject of the properties section below.

The classic worked example — step it yourself

A MAX root with three MIN children. Their leaves, left to right, are $[3, 12, 8]$, $[2, \cdot, \cdot]$, $[14, 5, 2]$. (The dots are real numbers; the point of the exercise is that we never find out what they are.) Press Step and read the log line each time — it says exactly what the algorithm is doing and why.

Figure 5 · Interactive α-β stepper — the classic [3,12,8] [2,·,·] [14,5,2] tree
Gold outline = the node currently being worked on. Faded, dashed = pruned: generated but never examined. Each internal node shows v on its left and its current α/β window on its right. Leaves show ? until they are actually evaluated.

The same traversal in words

  1. Root (MAX) starts with $\alpha = -\infty$, $\beta = +\infty$, $v = -\infty$.
  2. Node A (MIN), called with $(-\infty, +\infty)$. Leaves 3, 12, 8. After 3: $v = 3$, is $3 \le -\infty$? No, so $\beta \leftarrow 3$. After 12: $v = \min(3,12) = 3$. After 8: $v = 3$. Nothing prunes here — with $\alpha = -\infty$ nothing can prune, since MAX has secured nothing yet. A returns 3.
  3. Back at the root: $v = \max(-\infty, 3) = 3$. Is $3 \ge +\infty$? No. So $\alpha \leftarrow 3$. MAX has now secured 3. This single fact is what powers every prune that follows.
  4. Node B (MIN), called with $(\alpha=3, \beta=+\infty)$. First leaf: 2. $v = 2$. Test: $2 \le \alpha = 3$? Yes — cut off. Return 2 without looking at B's other two children: B is worth at most 2, MAX already has 3, so B's remaining children are irrelevant regardless of their values.
  5. Back at the root: $v = \max(3,2) = 3$. $\alpha$ stays 3.
  6. Node C (MIN), called with $(\alpha=3, \beta=+\infty)$. Leaf 14: $v = 14$; is $14 \le 3$? No; $\beta \leftarrow 14$. Leaf 5: $v = 5$; $5 \le 3$? No; $\beta \leftarrow 5$. Leaf 2: $v = 2$; $2 \le 3$? Yes — cut off and return 2. (Here the cutoff saves nothing, because 2 was C's last child anyway. A cutoff on the final child is free but useless.)
  7. Root: $v = \max(3,2) = 3$. Done. Root value 3, and the action is the one leading to A — the leftmost move.
Key idea

Leaves never examined: B's second and third children — two of nine, skipped because MAX had secured 3 and B had shown it could be held to 2. Their values are genuinely irrelevant: set them to $\pm 10^6$ and the root value is still 3 and the root move is still Left. If a $+10^6$ could change the answer, the algorithm would not have been allowed to skip it — that is the soundness theorem below.

Properties of α-β: what it does and doesn't guarantee

Proof

Theorem. α-β pruning has no effect on the minimax value computed for the root.

Sketch, by induction on the tree. Claim: a call value(n, α, β) returns the exact minimax value $V(n)$ whenever $\alpha < V(n) < \beta$; and when it returns early it returns some $v$ that is on the correct side of the window ($v \le \alpha$ when the true value is $\le \alpha$, or $v \ge \beta$ when the true value is $\ge \beta$).

Base case: a leaf returns its utility with no window involved. Inductive step at a MIN node $n$: the loop computes running minima of exact child values (by induction, as long as those children were called inside a window containing their values). If the loop finishes, $v = \min_i V(c_i) = V(n)$ exactly. If it exits early at child $k$ with $v \le \alpha$, then the true $V(n) = \min_i V(c_i) \le v \le \alpha$, so the returned $v$ is an upper bound on the true value that is still $\le \alpha$ — and the MAX parent, which is comparing against something it has already secured worth $\alpha$, takes $\max(\alpha, \text{something} \le \alpha) = \alpha$ either way. The early return therefore cannot change the parent's choice. MAX nodes are symmetric.

At the root we call with $\alpha = -\infty, \beta = +\infty$, and no finite value lies outside that window, so the root always runs its loop to completion with exact children. Hence the root value is exact. $\blacksquare$

Common mistake

The theorem is about the root only. Values computed at interior nodes can be wrong — and the min-value example above is a live case: we returned 10 for a node whose true minimax value is 2. The returned number is a bound, not a value. Consequences that bite in practice: (1) if you ask for "the minimax value of this interior node" from an α-β run, you may get a bound; (2) an engine that stores α-β results in a transposition table must record whether each entry is exact, a lower bound, or an upper bound. On an exam, if asked for the value at a pruned node, the honest answer is "α-β returns $x$ here, which is only a bound — the true value could be lower."

Move ordering changes everything

The order of generation matters: more pruning is possible if good moves come first. Re-run the classic example with node A's leaves in the order $[8, 12, 3]$ and less gets pruned; put B's 2 last and B's cutoff never fires at all. In the worst case (worst possible ordering) α-β prunes nothing and costs $O(b^m)$, exactly like plain minimax.

But we cannot order moves by their values — computing the values is the whole problem. So we guess, using cheap heuristics: try captures first in chess, try the move that was best at the previous depth, try killer moves that caused cutoffs in sibling nodes.

That "best at the previous depth" trick is why iterative deepening helps: search to depth 1, then 2, then 3, each pass cheap relative to the next (the last level dominates the node count) and each leaving behind a good first move for the next. The re-searching looks wasteful and is overwhelmingly repaid by the extra pruning. It is also anytime — when the clock runs out you have a complete answer from the last finished depth.

Proof

With perfect ordering, time drops to $O(b^{m/2})$.

Suppose at every node the best move really is generated first. To establish the root's value $v$ we need two things, and the tree we must examine is exactly the union of the evidence for them.

To prove the root is worth at least $v$, we exhibit a strategy for MAX: at each MAX node, one move (the good one) — we need not look at the others, because we are proving existence. At each MIN node, we must check all $b$ replies, because the claim is "whatever MIN does, we still get $v$." Alternating, that is $1 \times b \times 1 \times b \times \cdots$ over $m$ levels, i.e. $b^{m/2}$ leaves.

To prove the root is worth at most $v$, the symmetric argument: all $b$ moves at MAX nodes, one refutation at each MIN node — another $b^{m/2}$ leaves.

Total $\Theta(b^{m/2}) = \Theta\!\left((\sqrt{b})^{\,m}\right)$. The effective branching factor becomes $\sqrt{b}$. Since the exponent $m$ is halved for the same node budget, the solvable depth doubles. $\blacksquare$

Redo the chess budget with this. Still $10^6$ nodes per move, still $b \approx 35$, but now $\sqrt{35} \approx 5.92$:

$$5.92^{\,d} = 10^6 \;\Longrightarrow\; d = \frac{6}{\log_{10} 5.92} = \frac{6}{0.772} \approx 7.8 \approx 8$$

Or directly: $b^{m/2} = 35^{4} \approx 10^6$ gives $m = 8$. 1M nodes/move ⟹ depth 8, which the slides call "respectable." Same hardware, same evaluation function, four extra plies — purely from refusing to examine nodes that cannot matter.

True or false: α-β pruning is an approximation that trades accuracy for speed.
Why: α-β is exact. It prunes only subtrees it has proved cannot affect the root, which is why the theorem holds for any move ordering; ordering affects only how much gets pruned, never correctness. The approximations in a real engine come from the depth limit and the evaluation function, not from α-β. And it certainly does not examine every node — skipping nodes is the entire point.
Guided problem 2Which branches are pruned in a left-to-right traversal?

This is the question the lecture posed as a poll and never answered, so here is a tree of our own, answered completely. Root is MAX, the next row is MIN, the next row is MAX, and the bottom row is terminal. Traverse strictly left to right, depth-first.

R (MAX) M1 M2 XaXbXcXd 5 3 6 9 1 2 8 4
Leaves, left to right: 5, 3 (under Xa), 6, 9 (under Xb), 1, 2 (under Xc), 8, 4 (under Xd).

(a) Which leaves and subtrees are pruned? (b) Give $\alpha$ and $\beta$ at every node when it is entered. (c) What is the root value and the root move?

Step 0 — First, compute the plain minimax answer so you can check yourself

Xa $= \max(5,3) = 5$. Xb $= \max(6,9) = 9$. Xc $= \max(1,2) = 2$. Xd $= \max(8,4) = 8$.

M1 $= \min(5,9) = 5$. M2 $= \min(2,8) = 2$. Root $= \max(5,2) = \mathbf{5}$, via the left branch.

Keep 5 in your pocket. α-β must reproduce it.

Step 1 — Descend the left spine: R → M1 → Xa

R entered with $\alpha = -\infty$, $\beta = +\infty$; $v = -\infty$.

M1 entered with $\alpha = -\infty$, $\beta = +\infty$; $v = +\infty$.

Xa entered with $\alpha = -\infty$, $\beta = +\infty$; $v = -\infty$.

Leaf 5: $v = 5$. Cutoff test at a MAX node is $v \ge \beta$: $5 \ge +\infty$? No. Update $\alpha \leftarrow \max(-\infty, 5) = 5$ locally inside Xa.

Leaf 3: $v = \max(5,3) = 5$. $5 \ge +\infty$? No. Xa finishes and returns 5.

Nothing prunes yet — as always at the very start, because MAX has secured nothing ($\alpha=-\infty$) and MIN has secured nothing ($\beta=+\infty$).

Step 2 — M1 absorbs 5, then enters Xb with a tightened window

Back at M1: $v = \min(+\infty, 5) = 5$. Cutoff test at a MIN node is $v \le \alpha$: $5 \le -\infty$? No. Update $\beta \leftarrow \min(+\infty, 5) = 5$.

Meaning: MIN has now secured 5 on this path. MIN can guarantee the value here is no more than 5.

Xb is entered with $\alpha = -\infty$, $\beta = \mathbf{5}$.

Step 3 — The first prune, at a MAX node

Inside Xb: $v = -\infty$. Leaf 6: $v = 6$. Cutoff test: $v \ge \beta$, i.e. $6 \ge 5$? Yes — return 6 immediately.

Leaf 9 is pruned. Never examined.

In words: Xb is a MAX node, so its value can only climb from 6. MIN, sitting at M1, already has an option worth 5. MIN will never hand MAX a node worth 6 or more when it can hand over 5 instead. So whatever the 9 is — 9, or 900 — it changes nothing.

Back at M1: $v = \min(5, 6) = 5$; $5 \le -\infty$? No; $\beta$ stays 5. M1's children are exhausted, so M1 returns 5. (Exact, incidentally: its true value is 5.)

Step 4 — The root secures 5, and M2 gets a much tighter window

Back at R: $v = \max(-\infty, 5) = 5$. $5 \ge +\infty$? No. Update $\alpha \leftarrow 5$.

This is the moment that matters. MAX has secured 5. Every remaining node in the tree now has to beat 5 to be worth a single further node expansion.

M2 is entered with $\alpha = \mathbf{5}$, $\beta = +\infty$; $v = +\infty$.

Xc is entered with $\alpha = 5$, $\beta = +\infty$; $v = -\infty$. Leaf 1: $v = 1$; $1 \ge +\infty$? No; $\alpha \leftarrow \max(5,1) = 5$ (unchanged). Leaf 2: $v = \max(1,2) = 2$; $2 \ge +\infty$? No. Xc returns 2. Note that Xc could not prune anything: a MAX node prunes against $\beta$, and $\beta$ here is still $+\infty$.

Step 5 — The second prune, at a MIN node, killing a whole subtree

Back at M2: $v = \min(+\infty, 2) = 2$. Cutoff test: $v \le \alpha$, i.e. $2 \le 5$? Yes — return 2 immediately.

The entire Xd subtree is pruned: node Xd and both its leaves, 8 and 4. Three nodes, never generated.

In words: M2 is a MIN node, so its value can only fall from 2. MAX at the root already holds 5. MAX will never choose a move worth at most 2 over one worth 5. Whatever is in Xd — including the 8, which is bigger than the root value — is unreachable, because MIN gets to choose between Xc and Xd and would obviously take Xc's 2.

Back at R: $v = \max(5, 2) = 5$. Loop over. Root returns 5.

Answer & the takeaway

(a) Pruned: leaf 9 (cutoff inside Xb, a MAX-node cutoff against $\beta$), and the whole subtree Xd → {8, 4} (cutoff at M2, a MIN-node cutoff against $\alpha$). Four of eight leaves examined... five, actually: 5, 3, 6, 1, 2 examined; 9, 8, 4 skipped.

(b) Windows on entry:

Nodeα on entryβ on entryReturnedTrue value
R (MAX)−∞+∞55 ✓ exact
M1 (MIN)−∞+∞55 ✓ exact
Xa (MAX)−∞+∞55 ✓ exact
Xb (MAX)−∞569 — only a lower bound
M2 (MIN)5+∞22 ✓ (exact here by luck)
Xc (MAX)5+∞22 ✓ exact
Xd (MAX)never entered

(c) Root value 5; MAX plays the left move, toward M1. Matches Step 0's plain minimax. ✓

Takeaway: look at the Xb row. α-β reported 6 for a node whose true value is 9. The theorem promised nothing about interior nodes and delivered nothing — and the root is still exactly right. Also notice that both prunes happened after a value was secured on the path above: the first prune needed M1's $\beta = 5$, the second needed R's $\alpha = 5$. No securing, no pruning. That is why move ordering (getting a big value secured early) is worth so much.

Expectimax: games with chance, and opponents who aren't optimal

Minimax rests on one assumption: the other node is a minimiser. Two very common situations break it.

As the notes put it: making worst-case assumptions about stochastic or suboptimal opponents leads to poor decisions. Not merely conservative ones — if you believe every unlikely disaster is certain, you refuse opportunities that are nearly free.

Probability refresher

Definition

A random variable represents an event whose outcome is unknown. A probability distribution is an assignment of weights to the possible outcomes, and probabilities over all possible outcomes sum to one.

The course's example: traffic on the freeway. The random variable is $T$ = whether there's traffic; the outcomes are $T \in \{\text{none}, \text{light}, \text{heavy}\}$; the distribution is

$$P(T = \text{none}) = 0.25, \qquad P(T = \text{light}) = 0.50, \qquad P(T = \text{heavy}) = 0.25$$

Check the normalisation: $0.25 + 0.50 + 0.25 = 1$. Always check — if the weights don't sum to one you forgot an outcome. Capital $T$ is the variable; lower-case values like "light" are its outcomes, and $P(T=t)$ reads "the probability that $T$ takes the value $t$."

Expected value

Definition

The expected value of a function of a random variable is the average of that function's values, weighted by the probability of each outcome:

$$\E_X\big[f(X)\big] \;=\; \sum_x P(X = x)\, f(x)$$

Symbols: $X$ is the random variable; $x$ ranges over all its possible outcomes; $P(X=x)$ is the weight of outcome $x$; $f(x)$ is the number you care about when outcome $x$ happens. The subscript on $\E_X$ says which variable we are averaging over.

The airport example. Let $f(\text{traffic})$ be the time it takes to get to the airport:

Traffic $T$nonelightheavy
Probability $P(T=t)$0.250.500.25
$f(t)$ = travel time20 min30 min60 min
$$\E_T[f(T)] = \sum_t P(T=t) f(t) = 0.25 \times 20 \;+\; 0.50 \times 30 \;+\; 0.25 \times 60$$ $$= 5 \;+\; 15 \;+\; 15 \;=\; \mathbf{35 \text{ minutes}}$$

Two observations. $35$ is not a possible outcome at all — an expectation is a summary, not a prediction — and it sits above the median outcome (30), pulled up by the heavy-traffic tail, so expectations are sensitive to rare extremes. The pessimist answers 60, the optimist 20, expectimax 35: three answers to three different questions.

The expectimax node rules

We model chance as a player in the game tree: instead of $s'$ being the deterministic result of action $a$, it is one of several outcomes, each with a probability. Chance nodes are drawn as circles, and the three node types read:

Key idea

$$\text{MAX nodes:}\quad V(s) = \max_{a} V(s'), \qquad s' = \text{result}(s,a)$$ $$\text{MIN nodes:}\quad V(s) = \min_{a} V(s'), \qquad s' = \text{result}(s,a)$$ $$\text{CHANCE nodes:}\quad V(s) = \sum_{s'} P(s')\, V(s')$$

Same tree, same recursion, one new kind of node. A chance node does not choose — it averages. And notice the chance rule is the expected-value formula from above, with $f$ replaced by "the value of the resulting state."

Names: expectimax = MAX + CHANCE (a random world, no adversary — Tetris); expectiminimax = MAX + MIN + CHANCE (adversary and dice — backgammon); minimax = MAX + MIN (chess). Same code, different node types present.

The worked example

Three actions — Left, Center, Right — each leading to a chance node, with expected values $7$, $7$ and $8$, so the answer is Right. The notes' figure didn't survive into the text, so the probabilities and leaves below are recovered from the slide version of the example rather than invented; they reproduce $7, 7, 8$ exactly.

Figure 6 · Expectimax — circles are chance nodes, edge labels are probabilities
Left Center Right 1/41/41/2 1/21/2 1/32/3 8 MAX: pick the biggest expectation 778 12 8 4 8 6 12 6 ¼(12) + ¼(8) + ½(4)= 3 + 2 + 2 = 7 ½(8) + ½(6)= 4 + 3 = 7 ⅓(12) + ⅔(6)= 4 + 4 = 8
What to notice: Left contains the joint-largest leaf (12) and is not chosen; Right also contains a 12 but backs it with a 6 at two-thirds weight and wins. Chance nodes (circles) have no preference at all — they are not trying to help or hurt you. Compare Figure 2, where the same picture with triangles instead of circles would give a very different answer.

The arithmetic, written out:

Key idea

We select the action leading to the highest expected value, not the highest individual outcome. Figure 6's biggest number, 12, sits under both Left and Right and is the reason for neither answer. Right wins because its worst outcome (6) is decent and carries most of the weight. Expectimax rewards the shape of the whole distribution, not its best point.

Common mistake

Running a min or a max at a chance node. A chance node is not a player, so it never chooses: its value always lies between its smallest and largest child, strictly inside unless one outcome has probability 1. A chance value outside that range is an arithmetic error, and the usual cause is probabilities that don't sum to one.

Guided problem 3Expectimax, and how it disagrees with minimax

A MAX root has three actions. Each leads to a chance node:

ActionOutcome 1Outcome 2
Left$p = \tfrac12$, value 14$p = \tfrac12$, value 4
Center$p = \tfrac14$, value 20$p = \tfrac34$, value 0
Right$p = \tfrac12$, value 8$p = \tfrac12$, value 6

(a) Compute each chance node's value and the root's expectimax decision. (b) Now suppose you were wrong: those are not chance nodes but a hostile opponent choosing between the two outcomes. Redo it as minimax. (c) Which action does the "chase the biggest number" heuristic pick, and how does it do under each model?

Step 1 — Sanity-check the distributions

Left: $\tfrac12 + \tfrac12 = 1$ ✓. Center: $\tfrac14 + \tfrac34 = 1$ ✓. Right: $\tfrac12 + \tfrac12 = 1$ ✓. Good — these are genuine distributions. (Do this first, every time. A missing outcome is the single most common source of a wrong expectimax answer.)

Step 2 — Evaluate the chance nodes

$V(\text{Left}) = \tfrac12(14) + \tfrac12(4) = 7 + 2 = \mathbf{9}$.

$V(\text{Center}) = \tfrac14(20) + \tfrac34(0) = 5 + 0 = \mathbf{5}$.

$V(\text{Right}) = \tfrac12(8) + \tfrac12(6) = 4 + 3 = \mathbf{7}$.

Each value sits between its node's smallest and largest child, as it must.

Step 3 — The root under expectimax

$V(\text{root}) = \max(9, 5, 7) = \mathbf{9}$, so play Left.

Step 4 — The same tree under minimax

Now the outcomes are an opponent's choices and the probabilities are ignored entirely:

$V(\text{Left}) = \min(14,4) = 4$. $V(\text{Center}) = \min(20,0) = 0$. $V(\text{Right}) = \min(8,6) = 6$.

$V(\text{root}) = \max(4, 0, 6) = \mathbf{6}$, so play Right.

Answer & the takeaway

(a) Chance values $9, 5, 7$; expectimax plays Left, value 9.

(b) Minimax values $4, 0, 6$; minimax plays Right, value 6.

(c) "Chase the biggest number" picks Center, because a 20 is sitting there. Center is the worst action under both models — worst expectation (5) and worst worst-case (0). A single large outcome at low probability is a trap under every sane decision rule.

Takeaway: the same tree, the same numbers, two different answers, and neither algorithm is wrong. They answer different questions because they encode different beliefs about who or what controls those nodes. Left is right if the outcomes really are coin flips; Right is right if something is choosing them against you. Choosing between the two is a modelling decision made before any search happens — which is the subject of the last section.

Can you prune a chance node?

The slides raise the question — "Expectimax pruning?" over a tree with leaves 3, 12, 9, 2 — and leave it hanging. Here is the answer.

In general, no: you cannot prune at a chance node without bounds on the utilities. The reason is structural. α-β works because a MIN node's running value can only go down and a MAX node's can only go up. Those are monotone one-sided guarantees, and a one-sided guarantee is exactly what lets you say "this can never beat what I already hold."

A chance node has no such property. With two equally likely outcomes and the first evaluated at 3, all you know is that the node is worth $\tfrac12(3) + \tfrac12(V_2) = 1.5 + 0.5 V_2$, and with $V_2$ unconstrained that is any number at all — the second outcome could be $+10^9$ and drag the average anywhere. Averages are not monotone in the outcomes you have seen so far.

Bound the utilities and it changes. beyond syllabus If every leaf lies in $[L, U]$, the best possible completion assigns $U$ to everything unseen and the worst assigns $L$:

$$\underbrace{\sum_{\text{seen}} P(s')V(s') + \sum_{\text{unseen}} P(s')\,L}_{\text{lower bound}} \;\le\; V(\text{chance}) \;\le\; \underbrace{\sum_{\text{seen}} P(s')V(s') + \sum_{\text{unseen}} P(s')\,U}_{\text{upper bound}}$$

If the upper bound already falls at or below $\alpha$, MAX will never come here and you may stop. That is *-minimax (star1/star2 pruning, Ballard 1983), which backgammon engines use; it needs a known finite range for utilities and prunes far less than α-β, because the bounds are loose.

Intuition

α-β prunes because an adversary is predictable at the extreme: MIN will pick the worst thing for you, so one bad option condemns a node. No single outcome condemns a chance node, because the others vote too. Adversaries are, in this narrow sense, easier to reason about than dice.

Modelling assumptions: know your opponent

Everything above assumed you knew which kind of node you were looking at. What if you get that wrong? Take the slides' tree: a MAX root whose left option leads to a node with children $\{10, 10\}$ and whose right option leads to one with children $\{9, 100\}$.

Same numbers, opposite decisions, and the gap is enormous. The slides name the two failure modes:

Dangerous pessimism

Assuming the worst case when it's not likely. Minimax against a merely random world: you pass up the right branch's expected 54.5 to collect a guaranteed 10, because you treated a coin flip as an enemy. You are never destroyed, but you leave enormous value on the table, permanently.

Dangerous optimism

Assuming chance when the world is adversarial. Expectimax against a real opponent: you take the right branch expecting 54.5 and the opponent, who was never rolling dice, hands you the 9. In a real game those 9s are the losses, and a competent opponent steers toward exactly the outcomes your model called unlikely, so you are punished for the optimism over and over.

Analogy

The minimax driver. For a self-driving car, the worst case of driving anywhere is a fatal collision and the worst case of staying in the driveway is zero — so a minimax driver never leaves the driveway. Real driving needs expectimax over a behaviour model, with hard minimax-style safety constraints bolted on where worst-case treatment is deserved.

The 2×2 you should memorise

The lecture demo ran depth-4 Pacman against a depth-2 ghost: +500 for a win, −500 for a loss, −1 per move, 5 games per cell. The slides ask which pair is worst and which is best, and move on — so here are the numbers and the answer.

Figure 7 · Assumed opponent (rows) × actual opponent (columns)
Actual: minimax (optimal) ghostActual: random ghost
Pacman assumes optimal
(minimax)
Won 5/5, avg 493
model correct — optimal, guaranteed
Won 5/5, avg 464
dangerous pessimism: safe, but 39 points of timidity
Pacman assumes random
(expectimax)
Won 1/5, avg −303
dangerous optimism — the disaster cell
Won 5/5, avg 503
model correct — exploits the weak opponent
Answer to the slide's question: the worst pair is expectimax Pacman vs a minimax ghost (won 1 of 5, average −303 — it walks into ghosts it assumed would wander off). The best is expectimax Pacman vs a random ghost (average 503). What to notice: the diagonal — correct model — is always good. Off-diagonal, the two errors are wildly asymmetric: pessimism against a random world costs ~39 points; optimism against a real adversary costs ~800 and most of the wins.
Key idea

The two mistakes are not symmetric, and that asymmetry is the practical lesson of the chapter. Pessimism costs you upside; optimism costs you the game. Not knowing your opponent, err toward minimax, then shift toward expectimax with a learned model as evidence accumulates that they are weak. Both are errors of modelling, not of search: the search ran perfectly in all four cells.

Figure 8 · Interactive — one dial between minimax and expectimax

Your opponent plays the optimal (minimising) move with probability $p$, and otherwise picks uniformly at random. Safe leads to a node with outcomes {6, 6}; Risky leads to one with outcomes {0, 20}. Slide $p$ from "pure dice" to "pure adversary" and watch the right answer flip.

What to notice: Safe is worth 6 no matter what, because both its outcomes are 6 — an action with no variance is immune to your opponent model. Risky is worth $p\cdot 0 + (1-p)\cdot 10 = 10(1-p)$. They cross at $p = 0.4$. Getting $p$ wrong by a little near the crossover costs almost nothing; getting it wrong from 0 to 1 costs 6 points out of 6. This is what "know your opponent" means quantitatively.
You are writing a poker bot and you know your opponent is a weak, predictable amateur. Which is the better design?
Why: minimax gives you a guarantee against the best possible opponent, which is the wrong opponent to prepare for here. Against a weak player, minimax plays safe lines that forgo the value sitting in their mistakes (the "dangerous pessimism" cell, −39 points in the Pacman table). Expectimax with an accurate model exploits them. The catch, always: if your model of them is wrong and they are actually strong, you land in the −303 cell. Exploitation is a bet on your model.

Summary and what carries forward

The through-line: games require decisions when optimality is impossible. Every technique here responds to that.

The obstacleThe responseWhat it costs you
Someone else moves after youMinimax over the game tree; the answer is a policy, not a planThe tree is exponential, $O(b^m)$ time
The tree is too big to finishBounded lookahead to a depth limit; bounded rationalityThe optimality guarantee is gone
Non-terminal positions have no utilityEvaluation function — weighted linear sum of featuresImperfect; blind spots at the horizon
Wasting time on irrelevant subtreesα-β pruning, with move ordering from iterative deepeningNothing at the root — it is exact; interior values become bounds
Dice, cards, weak opponentsChance nodes and expectimax / expectiminimaxThe worst-case guarantee is replaced by an average; pruning gets hard
Three players, or non-opposed utilitiesGeneralized minimax with utility tuplesNo single value to reason about; alliances become emergent and unstable

Games force efficient use of computation — α-β exists because the budget is finite — and they have produced ideas that outlived them: reinforcement learning out of checkers (Samuel's self-play evaluation tuning), iterative deepening out of chess engineering, Monte Carlo tree search out of Go, and solution methods for partial-information games out of poker. The frontier is not solved: video games present much greater challenges, with $b = 10^{500}$, $|S| = 10^{4000}$ and $m = 10{,}000$.

Intuition

Where this goes next. The chance-node rule and the max rule together,

$$V(s) = \max_a \sum_{s'} P(s' \mid s,a)\, V(s')$$

are one small step from the Bellman equation for a Markov decision process:

$$V(s) = \max_a \sum_{s'} P(s' \mid s,a)\big[R(s,a,s') + \gamma V(s')\big]$$

The differences: rewards arrive along the way rather than only at the end, a discount $\gamma$ keeps infinite games finite, and states repeat so you iterate to a fixed point instead of recursing down a tree. The $\max$, the $\sum P(\cdot)$ and the argmax that turns a value into a policy are all already on this page. beyond syllabus

Which of these statements is false?
Why: the bound is $O(b^{m/2})$ — the exponent is halved, not the total. That is an astronomically bigger saving than halving the work: for $b=35, m=8$ it is the difference between $35^8 \approx 2.3\times10^{12}$ and $35^4 \approx 1.5 \times 10^6$. Halving the exponent doubles the depth you can reach; halving the work would buy you almost nothing (depth $4.8$ instead of $4$). The other four statements are all true.
Example

Thirty-second self-test before you close the tab. Without scrolling: (1) What does minimax return, a number or an action? (2) What do $\alpha$ and $\beta$ each mean in one sentence? (3) Which bound do you test against inside min-value, and which do you update? (4) Why can't you prune a chance node? (5) Which is the more expensive modelling error, pessimism or optimism? If any of those made you hesitate, that is the section to reread.