Mathwords logoMathwords

Combinatorial Game Theory — Definition, Formula & Example

Combinatorial game theory is the study of two-player games where players alternate moves, every move is visible, and nothing is left to chance, such as Nim, Go endgames, or Dots and Boxes. Its goal is to work out who wins with perfect play, and how, by giving each position an algebraic value.

A combinatorial game is a two-player game of perfect information with no chance moves. Players, called Left and Right, alternate turns, and every play ends after finitely many moves. Under the normal play convention, the player who cannot move loses. A game is impartial if both players always have the same moves available; otherwise it is partizan. In general, every position falls into one of four outcome classes: N (the next player to move wins), P (the previous player wins), L (Left wins no matter who starts), or R (Right wins no matter who starts). In an impartial game under normal play, classes L and R cannot occur, so every position is either N or P. The Sprague–Grundy theorem says each such impartial position is equivalent to a single Nim heap whose size is its Grundy value.

Key Formula

G(P)=mex⁡{G(Q):Q is an option of P},G(A+B)=G(A)⊕G(B)\mathcal{G}(P) = \operatorname{mex}\{\mathcal{G}(Q) : Q \text{ is an option of } P\}, \qquad \mathcal{G}(A + B) = \mathcal{G}(A) \oplus \mathcal{G}(B)
Where:
  • G(P)\mathcal{G}(P) = Grundy value of position P. These rules hold only for impartial games under normal play, where P is a P-position exactly when its Grundy value is 0
  • QQ = An option of P, meaning any position reachable from P in one move
  • mex⁡\operatorname{mex} = Minimum excludant: the smallest nonnegative integer not in the set, so mex{0, 1, 3} = 2
  • A+BA + B = Disjunctive sum: two games played side by side, where each turn you move in exactly one of them
  • ⊕\oplus = Nim-sum: add the numbers in binary without carrying (bitwise XOR)

Worked Example

Problem: Two piles hold 4 and 7 counters. On your turn, you remove 1 or 2 counters from one pile. The player who cannot move loses. Should you move first or second?
Step 1: Find the Grundy value of a single pile of n counters. A pile of 0 has no options, so its value is 0. Each larger pile has options n − 1 and n − 2, so take the mex of their values. The values repeat 0, 1, 2, which matches n mod 3.
n01234567G(n)01201201\begin{array}{c|cccccccc} n & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\ \hline \mathcal{G}(n) & 0 & 1 & 2 & 0 & 1 & 2 & 0 & 1 \end{array}
Step 2: The two piles form a disjunctive sum, so combine their values with the nim-sum.
G(4)⊕G(7)=1⊕1=0\mathcal{G}(4) \oplus \mathcal{G}(7) = 1 \oplus 1 = 0
Step 3: A value of 0 means a P-position, so the second player wins. The strategy is to always move back to nim-sum 0. For example, if your opponent takes 1 from the 7-pile, the piles are 4 and 6. You then take 1 from the 4-pile, which leaves 3 and 6.
G(3)⊕G(6)=0⊕0=0\mathcal{G}(3) \oplus \mathcal{G}(6) = 0 \oplus 0 = 0
Answer: Move second. The position (4, 7) has Grundy value 0, so whoever moves first loses against perfect play.

Why It Matters

Combinatorial game theory gives exact winning strategies for games that would take a computer far too long to search move by move. Berlekamp used it to solve late-stage Go endgames, and its sums of games led Conway to the surreal numbers. It also shows up in algorithm design courses and programming contests, where Grundy values solve many game problems quickly.

Common Mistakes

Mistake: Adding Grundy values with ordinary addition. In the example, 1 + 1 = 2 would wrongly suggest the first player wins.
Correction: Combine game components with the nim-sum (binary addition without carrying), so 1 ⊕ 1 = 0. Also note that mex and the nim-sum apply only to impartial games under normal play. Partizan games need Conway's more general values.

Related Terms

  • Game Theory — Broader field, which mostly studies payoffs rather than move sequences
  • Prisoner's Dilemma — Simultaneous-move payoff game, unlike alternating perfect-information games
  • Graph Theory — Models game positions as vertices of a directed move graph
  • Number Theory — Supplies modular patterns seen in subtraction-game Grundy values
  • Surreal Number — Number system that grew out of game values