Games and adversarial search

Minimax and alpha-beta pruning

Computes minimax values on a game tree, steps through minimax and alpha-beta search with α, β, and pruning, and backs up utility tuples in games with more than two players.

  • Lecture reference: Games and Adversarial Search · slides 9–13
  • Lecture reference: Games and Adversarial Search · slides 14–23
  • Lecture reference: Games and Adversarial Search · slides 24–25

Game tree 13 nodes · 9 terminal · depth 2

To move at the root

Uniform tree: b = 3, d = 2.

Alpha-beta on the two-ply game. The same decision without expanding every node: after A21 = 2 the second MIN node is worth at most 2 < 3, so A22 and A23 are pruned. The third MIN node goes ≤14, ≤5, then 2.

Lecture reference: Games and Adversarial Search · slides 14–19
Edit tree
Random tree

Search Alpha-beta

Algorithm

Move ordering sorts each node’s children by their minimax value before searching: best first is perfect ordering. The tree is drawn in the order searched.

A cutoff needs evaluation values on the internal nodes of a level, written in braces: {5}[3 12 8].

Step 1 of 35
Alpha-Beta-Search(root): v = Max-Value(root, −∞, +∞).

Game tree Alpha-beta

A1A11A12A13A2A21A22A23A3A31A32A3331282461452
  • Current node
  • Not reached yet

Counts at this step

Nodes visited
0 of 13
Terminal utilities
0 of 9
Subtrees pruned
0

Pseudocode Alpha-beta pruning

Function action = Alpha-Beta-Search(node)
v = Max-Value(node, −∞, ∞)(current step)
return the action from node with value v
Function v = Max-Value(node, α, β)
if Terminal(node) return Utility(node)
v = −∞
for each action from node
v = Max(v, Min-Value(Succ(node, action), α, β))
if v ≥ β return v
α = Max(α, v)
end for
return v
Function v = Min-Value(node, α, β)
if Terminal(node) return Utility(node)
v = +∞
for each action from node
v = Min(v, Max-Value(Succ(node, action), α, β))
if v ≤ α return v
β = Min(β, v)
end for
return v

Open calls

None.

Lecture reference: Games and Adversarial Search · slide 22

With focus in the tool: ← → previous and next step, Home End first and last step, Space play or pause.

Pruning and move ordering whole search

SearchNodes visitedTerminal utilitiesSubtrees pruned
Minimax13 of 1390
Alpha-beta, given order11 of 1372
Alpha-beta, best moves first9 of 1354
Alpha-beta, worst moves first13 of 1390

Uniform tree, b = 3, d = 2: minimax looks at bd = 9 terminal nodes; alpha-beta with perfect ordering at b⌈d/2⌉ + b⌊d/2⌋ − 1 = 5. With perfect ordering, the time to find the best move is reduced to O(bm/2) from O(bm). Lecture reference: Games and Adversarial Search · slide 23

From the slides

Minimax value and strategy

Lecture reference: Games and Adversarial Search · slides 10–11
  • Minimax value of a node: the utility (for MAX) of being in the corresponding state, assuming perfect play on both sides.
  • Minimax strategy: choose the move that gives the best worst-case payoff.
  • Minimax(node) is Utility(node) if node is terminal, the maximum of Minimax(Succ(node, action)) over the actions if MAX is to move, and the minimum if MIN is to move.

Optimality of minimax

Lecture reference: Games and Adversarial Search · slide 12
  • The minimax strategy is optimal against an optimal opponent.

More general games

Lecture reference: Games and Adversarial Search · slide 13
  • More than two players, non-zero-sum: utilities are tuples.
  • Each player maximizes their own utility at their node.
  • Utilities get propagated (backed up) from children to parents.

Alpha-beta pruning

Lecture reference: Games and Adversarial Search · slides 20–23
  • α is the value of the best choice for the MAX player found so far at any choice point above node n; β is the value of the lowest-utility choice found so far for the MIN player.
  • As the loop goes over n’s children, the MIN-value at n decreases. If it drops below α, MAX will never choose n, so n’s remaining children can be ignored.
  • Pruning does not affect the final result.
  • The amount of pruning depends on move ordering: search should start with the “best” moves (highest value for MAX, lowest value for MIN). For chess: captures first, then threats, then forward moves, then backward moves; “killer moves” from other branches of the tree can also be remembered.
  • With perfect ordering, the time to find the best move is reduced to O(b^(m/2)) from O(bᵐ): the depth of search is effectively doubled.

Evaluation functions

Lecture reference: Games and Adversarial Search · slide 24
  • Cut off search at a certain depth and compute the value of an evaluation function for a state instead of its minimax value.
  • The evaluation function may be thought of as the probability of winning from a given state or the expected value of that state.
  • A common evaluation function is a weighted sum of features: Eval(s) = w₁ f₁(s) + w₂ f₂(s) + … + wₙ fₙ(s). For chess, wₖ may be the material value of a piece (pawn = 1, knight = 3, rook = 5, queen = 9) and fₖ(s) the advantage in terms of that piece.
  • Evaluation functions may be learned from game databases or by having the program play many games against itself.

Cutting off search

Lecture reference: Games and Adversarial Search · slide 25
  • Horizon effect: the value of a state may be estimated incorrectly by overlooking an event just beyond the depth limit, for example a damaging move by the opponent that can be delayed but not avoided.
  • Quiescence search: do not cut off search at positions that are unstable (for example, when an important piece is about to be lost).
  • Singular extension: a strong move that should be tried when the normal depth limit is reached.

Questions from the slides

What if your opponent is suboptimal?

Lecture reference: Games and Adversarial Search · slide 12
Show answer

Why are the leaves 4 and 6 never looked at?

Lecture reference: Games and Adversarial Search · slides 16–20
Show answer

How much does the move ordering change?

Lecture reference: Games and Adversarial Search · slide 23
Show answer

Can cutting off the search change the decision?

Lecture reference: Games and Adversarial Search · slides 24–25
Show answer