Tic-tac-toe
Plays tic-tac-toe against a minimax, alpha-beta, or depth-limited player, shows the minimax value of every move and the game tree below the position, counts the nodes minimax and alpha-beta visit under different move orderings, and scores cut-off positions with a weighted evaluation function.
- Lecture reference: Games and Adversarial Search · slide 6
- Lecture reference: Games and Adversarial Search · slides 10–11
- Lecture reference: Games and Adversarial Search · slides 21–25
Game
Squares 1–9 row by row. Click a square, or move with the arrow keys and press Enter.
Minimax value 0: a draw with perfect play by both sides.
Every move has the same value, so none is marked best. Values are for MAX (X): +1 X wins, 0 draw, −1 O wins, with perfect play by both sides. X picks the largest value, O the smallest; ties go to the first square.
Game tree below the current position
Each board shows its minimax value, backed up from the terminal states: MAX takes the largest child value, MIN the smallest. Heavier edges and frames mark the best children; the shaded square is the move just played. Click a child board to play its move. Lecture reference: Games and Adversarial Search · slides 10–11
Search statistics nodes visited
From the empty board
- Minimax 549,946255,168 terminal states
- Alpha-beta, square order 18,2973.3% of minimax · 7,330 terminal · 4,237 cutoffs
- Alpha-beta, center, corners, edges 7,2751.3% of minimax · 2,893 terminal · 2,156 cutoffs
- Alpha-beta, best move first 2,3120.42% of minimax · 781 terminal · 1,045 cutoffs
Move ordering
Pruning does not affect the final result; the amount of pruning depends on move ordering. With perfect ordering the time to find the best move drops from O(bm) to O(bm/2): search depth is effectively doubled.
Lecture reference: Games and Adversarial Search · slide 23The whole game
From the empty board the game tree has 549,946 nodes and 255,168 complete games (131,184 won by X, 77,904 by O, 46,080 drawn), but only 5,478 distinct positions. A transposition table stores each once.
Lecture reference: Games and Adversarial Search · slide 26Evaluation function
Eval(s) = w₁ X₂(s) + w₂ X₁(s) + w₃ O₂(s) + w₄ O₁(s) Lecture reference: Games and Adversarial Search · slide 24
Eval of the current position: 0
| Move | Cutoff 3 | Minimax |
|---|---|---|
| Square 1 (top left) | +3 | 0 (draw) |
| Square 2 (top middle) | +2 | 0 (draw) |
| Square 3 (top right) | +3 | 0 (draw) |
| Square 4 (middle left) | +2 | 0 (draw) |
| Square 5 (center) returned | +5 | 0 (draw) |
| Square 6 (middle right) | +2 | 0 (draw) |
| Square 7 (bottom left) | +3 | 0 (draw) |
| Square 8 (bottom middle) | +2 | 0 (draw) |
| Square 9 (bottom right) | +3 | 0 (draw) |
Depth-limited search visits 586 nodes and scores 504 of them with Eval; with alpha-beta pruning, 167 nodes.
Cutting off search
Horizon effect: a state may be misjudged because of an event just beyond the depth limit, such as a damaging move by the opponent that can be delayed but not avoided. Remedies: quiescence search does not cut off search at unstable positions; a singular extension is a strong move that is still tried when the normal depth limit is reached.
Lecture reference: Games and Adversarial Search · slide 25Weights
In chess, a weight may be a piece’s material value (pawn 1, knight 3, rook 5, queen 9) and its feature the advantage in that piece. Weights can come from game databases or from the program playing many games against itself. Here a win scores ±100: each line counts toward at most one feature, so |Eval| ≤ 8 × 10 and a win always outranks an evaluation.
Lecture reference: Games and Adversarial Search · slide 24Games and adversarial search
Types of game environments
| Deterministic | Stochastic | |
|---|---|---|
| Perfect informationfully observable | Chess, checkers, go | Backgammon, monopoly |
| Imperfect informationpartially observable | Battleships | Scrabble, poker, bridge |
Tic-tac-toe: deterministic, perfect information.
Lecture reference: Games and Adversarial Search · slide 3Alternating two-player zero-sum games
- Players take turns.
- Each terminal state has a utility for each player.
- The sum of both players’ utilities is a constant. Here X gets +1, 0, or −1 and O the negative, so the sum is 0.
Games vs. single-agent search
- The opponent’s moves are not known, so the solution is a strategy (policy): a mapping from each state to the best move in that state.
- The time to make a move is limited, and branching factor, depth, and the number of terminal configurations are huge.
- Chess: branching factor ≈ 35 and depth ≈ 100 give a search tree of 10¹⁵⁴ nodes, against ≈ 10⁸⁰ atoms in the observable universe. Tic-tac-toe: at most 9 moves, 549,946 nodes.
Advanced techniques
- Transposition table to store previously expanded states. This tool keeps minimax values by board: 5,478 distinct positions instead of 549,946 nodes.
- Forward pruning to avoid considering all possible moves.
- Lookup tables for opening moves and endgames.
Chess playing systems
| System | Depth | Strength |
|---|---|---|
| Baseline 200 million node evaluations per move (3 min), minimax with a decent evaluation function and quiescence search | 5-ply | ≈ human novice |
| Baseline + alpha-beta the same budget with alpha-beta pruning | 10-ply | ≈ typical PC, experienced player |
| Deep Blue 30 billion evaluations per move, singular extensions, an evaluation function with 8000 features, large databases of opening and endgame moves | 14-ply | ≈ Garry Kasparov |
| Hydra (ca. 2006) 36 billion evaluations per second, advanced pruning techniques | 18-ply | ≈ better than any human alive? |