Documentation

CslibFrontier.GameTheory.PerfectInformation

Finite two-person games of perfect information #

A two-person game of perfect information (PerfectInfoGame) is given by its legal positions, the finite sequences of moves played so far, together with the player to move at each position and the victor of each finished play. The positions form a tree in the sense of descriptive set theory (Mathlib's Descriptive.tree: a set of finite sequences closed under prefixes) that contains the empty sequence, the initial position. The game is over at a position that no legal move continues (PerfectInfoGame.IsOver). Players are true (the first player) and false (the second); the player to move (turn) is an arbitrary function of the position, so alternating play is the case turn x = decide (Even x.length). Each position may have any set of legal moves, finite or not.

A strategy for player b (PerfectInfoGame.Strategy) chooses a legal move at every position that some legal move continues; only its choices at positions where b is to move matter. A play follows the strategy when every move made at such a position is the strategy's choice, and the strategy is winning when every finished play that follows it is won by b.

PerfectInfoGame.CanWin is backward induction: G.CanWin b k x says that from position x, player b can force a win when at most k further moves are played.

Main results #

The source's finiteness is "an a priori upperbound n on the number of moves after which the game is over and one of the two players is declared the victor — there are no draws" (printed p. 89 / PDF p. 105). It is the hypothesis ∀ x ∈ G.tree, x.length ≤ n, and the absence of draws is the type Bool of winner.

References #

structure Cslib.GameTheory.PerfectInfoGame (M : Type u_1) :
Type u_1

A two-person game of perfect information. Its legal positions are the finite sequences of moves played so far, starting from the empty sequence; the player to move and, on finished plays, the victor are functions of the position. Players are true (the first player) and false (the second).

  • tree : ↥(Descriptive.tree M)

    The legal positions: the sequences of moves played so far, closed under prefixes.

  • nil_mem : [] ∈ self.tree

    The initial position, before any move, is legal.

  • turn : List M → Bool

    The player to move at a position.

  • winner : List M → Bool

    The victor of a finished play; there are no draws.

The game is over at the position x when no legal move continues it.

A strategy for player b: a legal move at every position that some legal move continues. Only its choices at the positions where b is to move matter.

  • move (x : List M) : (∃ (a : M), x ++ [a] ∈ G.tree) → M

    The move chosen at a position that some legal move continues.

  • move_mem (x : List M) (h : ∃ (a : M), x ++ [a] ∈ G.tree) : x ++ [self.move x h] ∈ G.tree

    The chosen move is legal.

A sequence of moves follows the strategy σ of player b when every move made at a position where b is to move is the move σ chooses there.

A strategy of player b is winning when b wins every finished play that follows it.

Backward induction: G.CanWin b k x says that player b can force a win from the position x when at most k further moves are played. A finished position is won by its victor. At an unfinished one, b needs one move to a position from which b can force a win when b is to move, and every move must lead to such a position otherwise. With no move left (k = 0) the position is judged by its victor.

theorem Cslib.GameTheory.PerfectInfoGame.canWin_iff_of_isOver {M : Type u_1} {G : PerfectInfoGame M} {b : Bool} {k : ℕ} {x : List M} (hx : G.IsOver x) :
G.CanWin b k x ↔ G.winner x = b
theorem Cslib.GameTheory.PerfectInfoGame.not_canWin_iff {M : Type u_1} {G : PerfectInfoGame M} {b : Bool} {k : ℕ} {x : List M} :
¬G.CanWin b k x ↔ G.CanWin (!b) k x

Determinacy of backward induction: at every position and depth, exactly one player can force a win.

theorem Cslib.GameTheory.PerfectInfoGame.Strategy.follows_append_singleton {M : Type u_1} {G : PerfectInfoGame M} {b : Bool} {σ : G.Strategy b} {x : List M} {a : M} (hx : σ.Follows x) (ha : G.turn x = b → ∀ (h : ∃ (a : M), x ++ [a] ∈ G.tree), a = σ.move x h) :
σ.Follows (x ++ [a])
theorem Cslib.GameTheory.PerfectInfoGame.Strategy.IsWinning.canWin {M : Type u_1} {G : PerfectInfoGame M} {b : Bool} {σ : G.Strategy b} (hσ : σ.IsWinning) {n : ℕ} (hn : ∀ x ∈ G.tree, x.length ≤ n) (k : ℕ) (x : List M) :
x ∈ G.tree → σ.Follows x → n ≤ x.length + k → G.CanWin b k x

Under a move bound n, a winning strategy of b lets b force a win by backward induction from every legal position that follows it, with enough moves left.

theorem Cslib.GameTheory.PerfectInfoGame.exists_isWinning_iff_canWin {M : Type u_1} {G : PerfectInfoGame M} {b : Bool} {n : ℕ} (hn : ∀ x ∈ G.tree, x.length ≤ n) :
(∃ (σ : G.Strategy b), σ.IsWinning) ↔ G.CanWin b n []

Under a move bound n, player b has a winning strategy exactly when backward induction to depth n from the initial position says that b can force a win.

theorem Cslib.GameTheory.PerfectInfoGame.exists_isWinning_iff_not_exists_isWinning {M : Type u_1} {G : PerfectInfoGame M} {b : Bool} {n : ℕ} (hn : ∀ x ∈ G.tree, x.length ≤ n) :
(∃ (σ : G.Strategy b), σ.IsWinning) ↔ ¬∃ (τ : G.Strategy !b), τ.IsWinning

Under a move bound, player b has a winning strategy exactly when the other player has none.

theorem Cslib.GameTheory.PerfectInfoGame.exists_isWinning {M : Type u_1} {G : PerfectInfoGame M} {n : ℕ} (hn : ∀ x ∈ G.tree, x.length ≤ n) :
(∃ (σ : G.Strategy true), σ.IsWinning) ∨ ∃ (σ : G.Strategy false), σ.IsWinning

Zermelo's theorem Arora and Barak, Chapter 4, Exercise 8: in every two-person game of perfect information with an a priori bound n on the number of moves after which the game is over and one of the players is declared the victor, one of the two players has a winning strategy. By exists_isWinning_iff_not_exists_isWinning, exactly one of them has one.