Algorithmic Game Theory · Lecture Notes
Chapter 2: Games and Representations
To study a situation as a game, one must first describe it precisely: who is playing, what each player can choose, who knows what, and what each outcome is worth to whom. These notes begin with the basic concepts that answer these questions. They then present the two ways of writing down a game, the matrix (normal form) and the tree (extensive form), and classify games along six dimensions. Through the Prisoner's Dilemma and six classic 2×2 games they show the difference between equilibrium and efficiency. The guess-two-thirds game, combinatorial games, and sequential games show how the theory meets algorithms: minimax, the XOR rule for Nim, and backward induction. For minimax to be usable on large trees one needs alpha-beta pruning, move ordering, and depth-limited search, which are worked out in detail on tic-tac-toe and Connect Four.
Learning outcomes
- Concepts
- Define player, strategy, payoff, information, rationality, and common knowledge on a worked example.
- Representation and classification
- Use the normal form (matrix) and the extensive form (tree); tell games apart by timing, agreements, total payoff, symmetry, information, and horizon.
- Equilibrium and efficiency
- Explain the Nash equilibrium intuitively; show that Betray is dominant in the Prisoner's Dilemma and that the equilibrium is not Pareto optimal.
- Classic games
- Find the pure equilibria of six classic 2×2 games using best responses; interpret their conflict and coordination structure.
- Algorithms
- Explain level-k reasoning; solve small games by hand and in code with minimax and the XOR strategy for Nim.
- Sequential games
- Find the subgame perfect equilibrium by backward induction; interpret non-credible threats and the difference between finite and infinite horizons.
- Game-tree search
- Apply minimax and alpha-beta pruning by hand and in code; explain the effect of move ordering, the evaluation function, and the horizon effect.
2.1Core concepts
The parts that make up a game look simple, but every later computation rests on their definitions. If a concept is missing or wrongly defined, for example if strategy is confused with action, all the later computations come out wrong. For this reason the concepts are first made concrete on a small game and then written down formally.
2.1.1A first game: guess two-thirds of the average
Everyone in a class secretly writes down a number between 0 and 90. The number may be an integer or a decimal. The average of all the guesses is computed, and two-thirds of that average is taken as the target. The player whose guess is closest to the target wins; if several players are equally close, the prize is shared. This is the guess-two-thirds-of-the-average game.
What makes the game interesting is that the right answer depends on what others will write. Someone thinking alone might say: "If the numbers are spread randomly between 0 and 90, the average will be 45, and two-thirds of 45 is 30; so I will write 30." But if others reason the same way, most people will write 30; then the average will be close to 30 and the target close to 20. Someone who anticipates this writes 20. Each step is a reply to what the others thought one step earlier.
Figure 2.1 shows the guesses of eight players on a number line. The guesses sum to 360, so the average is 360 / 8 = 45. The target is two-thirds of 45, that is, 30. The player who wrote exactly 30 is the green dot and wins. Had the eight guesses been different, the average and the target would have been different too. The winning number comes not from the rules of the game but from the choices the players make together.
This small game contains almost all the questions of the chapter. Who are the players? What options does each player have? What does each choice earn whom? Do the players know how smart the others are? If "everyone is very smart", which number wins? In a real classroom, which number wins? The first four of these questions concern the definition of the game, the last two its solution. The solution is given in detail in Section 2.6.
2.1.2What is game theory?
Game theory is a mathematical tool for studying situations in which decision makers are engaged in strategic interaction. Strategic interaction can be summed up briefly: one player's best decision depends on what the other does, and the other's best decision depends on the first's. In a single-person decision problem the decision maker plays only against nature or chance. In a game, on the other side are other decision makers who think for themselves and look after their own interests.
The decision makers are called players or agents. A player may be a person, a company, a country, a piece of software, or a network device. Game theory tries to explain how players behave and how the outcome takes shape. In doing so it assumes that players are rational and act according to their own interests. The exact meaning of this assumption is spelled out in Section 2.1.5.
The theory is widely used in economics, political science, biology, psychology, and computer science. Three example areas show what kinds of questions it answers:
- Economics: Price competition between firms, auctions, and bargaining. A firm's price takes on meaning only relative to its rival's price.
- Computer networks: Selfish routing, in which every packet or every driver chooses its own path. If everyone picks the fastest path, that path may become congested.
- Artificial intelligence: Multi-agent systems, game-playing programs, and learning agents. A chess program cannot choose a move without taking the opponent's best reply into account.
Algorithmic game theory adds two questions from computer science to classical game theory. The first concerns computation: how hard is it to compute the equilibrium of a game, and which algorithm does it? The second concerns design: how can one design rules, that is, algorithms, protocols, and auctions, that give good outcomes among selfish agents? These two questions are taken up again at the end of the chapter, in Section 2.10.
2.1.3A short history
Game theory began early in the twentieth century with mathematical questions about games such as chess. By the middle of the century it had become one of the basic tools of economics. By the end of the century it had met computer science and turned into algorithmic game theory. Table 2.1 shows the main stops on this journey.
| Year | Development |
|---|---|
| 1913 | Zermelo: in finite games of perfect information such as chess, either one side can force a win or both sides can force a draw. |
| 1928 | von Neumann: the minimax theorem for two-player zero-sum games. |
| 1944 | von Neumann and Morgenstern, Theory of Games and Economic Behavior: game theory becomes a field of its own. |
| 1950 | Nash: every finite game has an equilibrium in mixed strategies. In the same year the Flood–Dresher experiment is run at RAND, and Tucker tells the Prisoner's Dilemma story. |
| 1961 | Vickrey: in a second-price auction, bidding truthfully is dominant. |
| 1994 | Nobel Prize in Economics to Nash, Harsanyi, and Selten. |
| 1999 | Koutsoupias–Papadimitriou (the ratio of the worst equilibrium to the optimum, later named the Price of Anarchy) and Nisan–Ronen (algorithmic mechanism design): algorithmic game theory is born. |
| 2006 | No fast method is known for finding a Nash equilibrium in general games: the problem (exact equilibrium for two players, approximate equilibrium for many players) belongs to the class of hard problems called PPAD-complete (Daskalakis–Goldberg–Papadimitriou; two players: Chen–Deng). |
| 2012, 2020 | Nobel Prizes: Roth and Shapley (stable matching, market design); Milgrom and Wilson (auction design). |
The dates in the table separate three periods. The years 1913–1944 are the period in which the mathematical foundations of the theory were laid. Zermelo's chess result and von Neumann's minimax theorem are the two great results of this period; both come back later: Zermelo in these notes (Section 2.2.8 and Section 2.7.1), the minimax theorem in Chapter 3 (Section 3.6.4). The years 1950–1994 are the period in which the theory spread to general games and to economics. Nash's equilibrium concept stands at its center. After 1999, two questions from computer science, "how hard is it to compute an equilibrium?" and "how are good rules designed?", moved to the center of the theory.
The birth of the Prisoner's Dilemma also appears in this table. In 1950 at RAND, Merrill Flood and Melvin Dresher had two people play the same game repeatedly, to test whether players behaved as the theory predicts. In the same year Albert Tucker described the structure of this game with a story about two prisoners, and the game became known by that name. The story is told in detail in Section 2.4.2.
2.1.4The components of a game
A game is a situation in which players interact and each one's choice affects everyone's payoff. To write a situation down as a game, six questions must be answered. Table 2.2 lists these six components and their notation.
| Component | Meaning | Notation or example |
|---|---|---|
| Players | The persons or institutions that make decisions. | N = {1, …, n} |
| Actions / strategies | The set of actions each player can choose. | Si = {Rock, Paper, Scissors} |
| Payoff | The value of each outcome to a player; it depends on everyone's choice. | ui(s1, …, sn) |
| Information | Who knows what, and when? Is the opponent's move observed? | chess ≠ poker |
| Rules and order | Simultaneous or sequential? The rules that link payoffs to actions. | normal / extensive form |
| Outcome | Results from all the players' choices taken together. | s = (s1, …, sn) |
The letter i in the notation means "any player". Si is the set of strategies available to player i; ui is the function that computes player i's payoff. The choices of all the players go into the payoff function, not only player i's. This is exactly what strategic interaction is: a player cannot determine their own payoff alone.
The guess-two-thirds game in a class of 30 students breaks down into its components as follows:
- Players: the 30 students in the class, N = {1, …, 30}.
- Strategies: for each student, all numbers between 0 and 90, Si = [0, 90]. This set is infinite, because decimals are allowed.
- Outcome: a list of 30 numbers, s = (s1, …, s30).
- Payoff: the average and the target are computed from the list. Those closest to the target share the prize equally; the others get 0. Student i's payoff depends on the whole list.
- Information: everyone knows the rules, but nobody sees the numbers the others write.
- Rules and order: everyone writes at the same time (secretly); the game is simultaneous.
This description also shows that the game is too large to draw as a matrix: each player has infinitely many strategies. Even so, the game is completely specified, and it is solved in Section 2.6.
2.1.5Players, rationality, and common knowledge
Game theory makes three assumptions about the players. All three can be stated in plain language, but each has a subtle side.
- Rationality: Each player makes the choice that maximizes their own expected utility, given their beliefs about what the others will do.
- Self-interest: A player follows their own utility function. Other people's payoffs matter only if they enter the player's own utility.
- Common knowledge: A piece of information is common knowledge if everyone knows it, everyone knows that everyone knows it, everyone knows that this too is known to everyone, and this chain continues forever.
Two words in the definition of rationality matter. The first is "given their beliefs". A player does not know for certain what the others will do; they have a guess about it, that is, a belief. A rational player makes the best choice given this belief. If the belief is wrong the outcome may be bad, but the choice is still rational. The second is "expected utility". When the outcome is uncertain, the player weighs the utilities of the possible outcomes by their probabilities and adds them up. This computation is carried out in detail in Section 2.1.8.
The self-interest assumption is often misunderstood. Rational does not mean selfish. A utility function may include concerns for fairness, altruism, or reputation. Someone who voluntarily donates part of their earnings is rational if they derive utility from donating. The theory says only this: a player tries to do the best they can at whatever they care about. What is cared about is written into the utility function. The outcome, in turn, is the product of an interaction that no single player controls.
The common-knowledge assumption is the most abstract of the three; its effect is clearly visible in the guess-two-thirds game. Figure 2.2 shows which guesses each level of knowledge eliminates in this game.
At level 1 there is only the knowledge that "everyone is rational". Since the average can be at most 90, the target is at most 60. Writing a number above 60 is never better than writing 60; a rational player does not write above 60. At level 2 everyone knows this: someone who knows that nobody will exceed 60 concludes that the average is at most 60 and the target at most 40. At level 3 the upper bound drops to 26.7. Each level adds one more "everyone knows" and multiplies the upper bound by 2/3. Common knowledge is this chain continuing forever, and in the end only 0 remains. This computation is carried out in code in Section 2.6.3.
- "It is enough for everyone to know." Everyone being rational is different from the rationality of everyone being common knowledge. At level 1 everyone is rational, yet only the range above 60 is eliminated. Reaching the result 0 requires infinitely many levels.
- "A rational player never reduces their own money." A utility function may include concerns other than money. Rationality means maximizing one's own utility; what the utility consists of varies from person to person.
2.1.6Actions and strategies
In everyday language "action" and "strategy" are used interchangeably. In game theory the two are different, and the difference matters especially in sequential games.
An action is a single move a player can make at one decision point. A strategy is the plan of action a player chooses. In sequential games a strategy is a complete plan that says what the player will do in every possible situation they may face.
A list containing one strategy from each player is called a strategy profile: s = (s1, …, sn). The profile determines the outcome of the game.
In a simultaneous game each player decides once, without seeing the other. In this case strategy and action are the same thing: in Rock-Paper-Scissors "Rock" is both an action and a strategy. The difference appears when a player decides after seeing the other's move. Then the player's plan must contain a separate reply for every move they might see.
In Figure 2.3, F2 sees F1's price and responds. F2 has two decision nodes: one where F1 said 100 TL, the other where F1 said 120 TL. At each node it chooses one of two actions (100 or 120). A strategy means making a choice at each of the two nodes. So F2 has 2 · 2 = 4 strategies: (100, 100), (100, 120), (120, 100), and (120, 120), although it has only 2 actions. For example, the strategy (120, 100) says: "If F1 says 100, I say 120; if F1 says 120, I say 100."
The general rule is this: if a player has k decision nodes and chooses among m actions at each, the number of strategies is mk. If F2 had 3 nodes, the number of strategies would be 2 · 2 · 2 = 8. This number grows exponentially with the number of nodes. For this reason writing large sequential games as matrices is impractical; the tree representation (Section 2.2.6) is far smaller.
A student first decides whether to come to class. The teacher sees whether the student came and, in both cases, chooses between "assign homework" and "do not assign homework". If homework is assigned, the student says "do it" or "don't". The numbers of strategies of the teacher and the student are found as follows:
- The teacher's decision nodes: "student came" and "student did not come". Two nodes with two actions each: 22 = 4 strategies.
- The student's decision nodes: the start (come / don't come), "I came and homework was assigned", and "I did not come and homework was assigned". Three nodes with two actions each: 23 = 8 strategies.
- One strategy of the student is, for example: (come; if homework is assigned after coming, do it; if homework is assigned after not coming, don't). The plan also covers the situation "I did not come and homework was assigned", which the student will never actually face.
The observation in the last item is important: a strategy makes a choice even for situations that are never reached. This detail becomes decisive when we examine non-credible threats in sequential games (Section 2.8.2).
A strategy rests on expectations about the others' behavior. When choosing a plan, a player predicts what the others will do. Besides this prediction, how the player makes the choice also matters. There are two kinds of strategy:
- Pure strategy: choosing a single plan with certainty. Example: "always Rock".
- Mixed strategy: a probability distribution over pure strategies. The player decides which pure strategy to play by rolling a die. Example: (Rock 1/3, Paper 1/3, Scissors 1/3).
A mixed strategy may look odd at first: why would a rational person leave the decision to a die? The answer is that in some games being predictable loses. In Rock-Paper-Scissors, a player who always says Rock loses every time once the opponent notices. Playing at random leaves no pattern for the opponent to exploit. This idea is shown with numbers in Section 2.2.3.
2.1.7Payoffs and utility functions
A payoff is the value a player obtains, and it depends on the strategy profile chosen by all the players. The function that measures payoff is called the utility function and is written ui for player i. Players choose their strategies to maximize their payoffs.
A payoff may be money, points, or a level of satisfaction. Sometimes a payoff is the negative of something bad: for costs such as years in prison or waiting time, less is better, so the payoff is written as −(years in prison). In this way the rule "larger is better" holds in all games. With mixed strategies the outcome is uncertain, so the player computes the expected payoff.
Figure 2.4 shows why a payoff is a function of a profile. Player 1 always chooses the same action, Paper. But the payoff is +1, 0, or −1 depending on the opponent's choice. The payoff therefore depends not on Paper alone but on the pair (Paper, opponent's action). In notation: u1(Paper, Rock) = +1, u1(Paper, Paper) = 0, u1(Paper, Scissors) = −1.
If the opponent plays each of the three actions with probability 1/3, the expected payoff of Paper is computed as follows. The payoff of each possible outcome is multiplied by its probability and the products are added:
E[u1(Paper)] = ⅓ · (+1) + ⅓ · 0 + ⅓ · (−1) = 0
If the opponent played Rock more often, say (Rock ½, Paper ¼, Scissors ¼), the computation would change: ½ · 1 + ¼ · 0 + ¼ · (−1) = ¼. The expected payoff of Paper would be positive, because Paper beats Rock. The expected payoff depends on both the player's own choice and the opponent's probabilities.
2.1.8Ordinal and cardinal utility
Utility numbers can be used in two different senses. This difference determines which computations are meaningful.
Ordinal utility tells only the order of preference. If Ayşe's preferences are Opera ≻ Football ≻ Home (≻ means "is preferred to"), this order can be written as 3, 2, 0 or as 30, 20, 0; both carry the same information.
Cardinal utility, in contrast, also carries the size of the differences; it is also known as von Neumann–Morgenstern utility. Because uncertain outcomes are compared by expected utility, the numbers themselves matter.
With ordinal utility, changing the numbers without disturbing the order changes nothing. Even if 30, 20, 0 is written instead of 3, 2, 0, Ayşe still prefers Opera to Football and Football to staying home. Pure-strategy analysis, dominance, and pure equilibria look only at the question "which is better?", so they are not affected by such a change.
When uncertainty comes in, the situation changes. A lottery is an uncertain option written with the probabilities of its possible outcomes. "Opera with probability ½, Home with probability ½" is a lottery. The value of a lottery is the sum of the utilities of the outcomes weighted by probabilities, and this sum depends on the size of the numbers.
Ayşe must decide between two options: Football for sure, or the lottery ½ Opera + ½ Home. For three different utility assignments, the decision is computed in Table 2.3.
| Utility (Opera, Football, Home) | Lottery | Football for sure | Choice |
|---|---|---|---|
| (3, 2, 0) | ½·3 + ½·0 = 1.5 | 2 | Football |
| (3, 1, 0): same order | ½·3 + ½·0 = 1.5 | 1 | Lottery |
| 2u + 1 = (7, 5, 1) | ½·7 + ½·1 = 4 | 5 | Football |
- In the first row the lottery gives 1.5 and Football for sure gives 2. Since 2 > 1.5, Ayşe chooses Football.
- In the second row the preference order is the same (Opera ≻ Football ≻ Home); only the utility of Football has dropped from 2 to 1. The lottery is still 1.5, but Football for sure is now 1. Since 1.5 > 1, the decision switches to the lottery.
- In the third row every utility of the first row has been multiplied by 2 and increased by 1: (3, 2, 0) → (7, 5, 1). The lottery gives 4 and Football for sure gives 5; the decision is Football, as in the first row.
Conclusion: even if the order stays the same, the lottery decision can change when the numbers change (rows 1 and 2). By contrast, a transformation of the form a · u + b (a > 0) preserves the decision (rows 1 and 3). This is because under such a transformation every expected value transforms in the same way: ½(2·3 + 1) + ½(2·0 + 1) = 2 · 1.5 + 1 = 4. The difference between the two options is simply multiplied by a, and since a > 0 its sign does not change.
- "A payoff of 4 is twice as good as a payoff of 2." This reading is meaningful only for cardinal utility. If the numbers show only the order, 4 is better than 2, but how much better is unknown.
- Using ordinal numbers in a mixed-strategy computation. The expected-payoff computation assumes that the utilities are cardinal (vNM). If only the order is known, one settles for pure-strategy analysis.
2.1.9Information: who knows what?
What the players know about the game, the payoffs, and the moves made directly affects strategy and outcome. In chess both players see the whole board. In poker the opponent's cards are hidden. This difference explains why playing well in the two games demands very different skills.
In a game tree, information is shown by an information set. An information set is a set of decision nodes that the player to move cannot tell apart. In the tree these nodes are joined by a dashed line. Because the player does not know which node they are at, they must choose the same action at every node in the set.
Figure 2.5 puts the three situations side by side. On the left every node is an information set by itself; player 2 sees player 1's choice and replies accordingly. In the middle player 2's two nodes are in the same information set. Player 1 has made a choice, but player 2 decides without seeing it; this is the same as the two players deciding at the same time. On the right, the first move is made by Nature: whether the hand is strong or weak is a chance event. Player 1 sees their own hand, player 2 does not. Player 2 sees that player 1 has bet but does not know whether the hand is strong or weak.
A game is a game of perfect information if every information set consists of a single node, that is, if each player sees all past moves when deciding. A game in which at least one information set contains more than one node is a game of imperfect information.
Perfect information means seeing the past, not knowing the future. A chess player does not know the opponent's next move, but sees every move played up to that point. This is why chess is a game of perfect information. Perfect information is also different from complete information, which means that everyone knows everyone's payoff functions. This distinction is taken up in Section 2.3.2.
2.1.10Poker and bluffing
In Texas Hold'em poker each player has two hidden cards. In the middle are face-up cards that everyone can see, and each player tries to form the best hand by combining their hidden cards with the face-up ones. The opponent's hidden cards are not visible: the information is private. Even a player with a strong hand tries to guess the opponents' hands from their bets.
In this game the opponent's behavior, betting or waiting, carries information about their hand. A player who bets only with strong hands is easy to read: when they bet, the others fold; when they wait, the others attack. A bluff is sending a misleading signal to hide the strength of one's hand: betting with a weak hand too.
From the game-theoretic point of view, a bluff is a mixed strategy. Betting with a weak hand with a certain probability prevents the opponent from reading the player. If the probability is too low, the player is still read; if it is too high, the opponent starts calling every bet and bluffs become costly. The right probability is the point at which the opponent is indifferent between calling and folding. Computer poker programs play by computing such equilibria. A program called Libratus won a long series of matches against four professional players in 2017.
The poker example shows how information changes the structure of a game. In chess the notion of "the best move" is meaningful, because everything is open. In poker there is no single best move; the best behavior is a mixture that says what to do, and with what probability, in which hand.
2.2Representing games
There are two basic ways to write down a game. The normal form writes the game as a table, that is, a matrix; it is natural when players decide at the same time. The extensive form draws the game as a tree; it shows the order of moves and who knows what at each point. The same game can be written in both ways.
2.2.1Normal form
A normal-form game (also called a strategic-form game) G = (N, (Si), (ui)) consists of three components:
- N = {1, …, n}: the set of players.
- Si: the strategy set of player i.
- ui : S1 × … × Sn → ℝ: the utility function of player i. It assigns a real number to every strategy profile.
A strategy profile s = (s1, …, sn) contains one strategy from each player. The set of all profiles is written S1 × … × Sn.
The "×" sign in the definition is the Cartesian product: the Cartesian product of two sets is the set of all ordered pairs formed by one element of the first set and one element of the second. For example, if S1 = {Top, Bottom} and S2 = {Left, Right}, then S1 × S2 = {(Top, Left), (Top, Right), (Bottom, Left), (Bottom, Right)}. Each pair is a strategy profile. The definition of the utility function ui : S1 × … × Sn → ℝ says: ui takes a profile as input and returns a number. The input is the choice of all players, not only that of player i.
In a two-player game the normal form is written as a payoff matrix. The rows are the strategies of player 1 and the columns those of player 2. Each cell holds two numbers: first the row player's payoff, then the column player's, that is, (u1, u2). This order does not change anywhere in these notes.
Figure 2.6 makes this reading concrete. The game is written G = (N, S1, S2, u1, u2) with N = {1, 2}. There are four profiles, and each is a cell. The highlighted cell (Top, Right) = (1, 2) means: when player 1 chooses Top and player 2 chooses Right, player 1 earns one unit and player 2 earns two. Player 1 can choose only the row; player 2's column determines which cell the game lands in.
In the game of Figure 2.6, the values of the two utility functions for the four profiles are:
- u1(Top, Left) = 4, u2(Top, Left) = 3.
- u1(Top, Right) = 1, u2(Top, Right) = 2.
- u1(Bottom, Left) = 3, u2(Bottom, Left) = 1.
- u1(Bottom, Right) = 2, u2(Bottom, Right) = 4.
If player 1 knew that player 2 would play Left, they would choose Top (4 > 3). If they knew player 2 would play Right, they would choose Bottom (2 > 1). So player 1's best choice depends on player 2; the table alone does not say "player 1 should play this". This dependence is the starting point of the best-response concept in Section 2.4.1.
The normal form models situations in which players decide simultaneously, or decide without knowing each other's choice. Two firms announcing their prices in sealed envelopes on the same day is an example. What matters is not time but information: even if one decides in the morning and the other in the evening, the game is simultaneous if the one deciding in the evening does not see the morning decision.
2.2.2Rock-Paper-Scissors in normal form
In Rock-Paper-Scissors (RPS), two players (n = 2) simultaneously choose Rock, Paper, or Scissors. Rock beats Scissors, Scissors beats Paper, Paper beats Rock. The winner gets +1, the loser −1, and in a tie both get 0.
In the matrix of Figure 2.7, the diagonal cells (Rock, Rock), (Paper, Paper), (Scissors, Scissors) are ties: (0, 0). In the other cells one player wins and the other loses. For example (Paper, Rock) = (1, −1): the row player beats Rock with Paper. In every cell the two numbers sum to 0.
Looking carefully at the matrix, one more thing becomes visible: in no cell are both players content with their choice. One of them always wants to change. In the cell (Rock, Scissors) = (1, −1) the column player wins by switching to Paper. In the cell (Paper, Paper) = (0, 0) each player can win by switching alone to Scissors. None of the nine cells passes this "nobody wants to change" test. This observation says that RPS has no equilibrium in pure strategies. The equilibrium concept is defined in Section 2.4.1.
2.2.3Choosing a strategy in Rock-Paper-Scissors
What rule should a player who plays RPS over and over follow? Three possible rules can be compared.
1. Random choice. In each round every symbol is chosen with probability 1/3. This strategy cannot be exploited at all: whatever the opponent does, the expected payoff is 0. For example, if the opponent always says Rock, the player's payoff is 0 with probability 1/3 (Rock), +1 with probability 1/3 (Paper), and −1 with probability 1/3 (Scissors); the average is 0. The same computation can be repeated for every choice of the opponent.
2. Choice based on the past. "If the opponent said Rock last round, say Paper this round." This rule wins against an opponent who plays in patterns. But the rule is itself a pattern. If the opponent notices it, they can beat the player by saying Rock last round and Scissors this round.
3. An unbalanced mixed strategy. For example, Paper half of the time and Scissors half of the time.
The player plays ½ Paper, ½ Scissors. The expected payoff against each of the opponent's three pure options is computed separately (from the opponent's point of view):
- If the opponent says Rock: −1 against Paper, +1 against Scissors. Expected ½ · (−1) + ½ · (+1) = 0.
- If the opponent says Paper: 0 against Paper, −1 against Scissors. Expected ½ · 0 + ½ · (−1) = −½.
- If the opponent says Scissors: +1 against Paper, 0 against Scissors. Expected ½ · (+1) + ½ · 0 = +½.
If the opponent always says Scissors, their expected payoff is +1/2 and the player's is −1/2. This mixture can be exploited. The player is unpredictable, since nobody knows in which round they will say Paper; but because they never choose Rock, Scissors is safe against them.
Comparing the three rules contains a lesson: even in a simple game the choice of strategy matters. Being unpredictable is not enough; one must be unpredictable with the right probabilities. In RPS the right probabilities are 1/3 each, and they guarantee 0 against any opponent.
2.2.4Zero-sum games
A two-player game is zero-sum if the payoffs sum to zero in every strategy profile: u1(s) + u2(s) = 0 for every s. If the sum is a constant other than zero, the game is constant-sum; the same analysis applies to such games.
In a zero-sum game one player's gain is the other's loss. RPS, Matching Pennies, and chess (with +1 / 0 / −1 scoring) are zero-sum. A game in which one point is divided between two players is also constant-sum: if one gets 0.7, the other gets 0.3. By contrast, the Prisoner's Dilemma and price competition are not zero-sum; in these games the total payoff varies with the outcome.
In a zero-sum game a single matrix suffices, because the column player's payoff is the negative of the row player's. The row player wants to increase their payoff; the column player wants to decrease the row player's payoff. Two natural criteria then arise. Maximin: the row player looks at the worst case of each row and chooses the row whose worst case is best. Minimax: the column player looks at the best outcome the row player can get in each column and chooses the column that makes it smallest. Minimax search in a game tree (Section 2.7.2) is the algorithm that applies the same idea, from the leaves to the root, in a sequential game.
Figure 2.8 shows this shorthand. The table at the top lists both payoffs; the matrix A below lists only the row player's payoff. The column player's payoff in each cell is the negative of the number in A. This shorthand cannot be used in games that are not zero-sum, since there one player's payoff cannot be derived from the other's.
In Matching Pennies, A = [[1, −1], [−1, 1]]. Maximin and minimax in pure strategies are found as follows:
- The row player's worst outcome in each row: in the Heads row min(1, −1) = −1, in the Tails row min(−1, 1) = −1. Maximin = max(−1, −1) = −1.
- The column player looks at the row player's best outcome in each column: in the Heads column max(1, −1) = 1, in the Tails column max(−1, 1) = 1. Minimax = min(1, 1) = 1.
- Maximin (−1) and minimax (1) are not equal. Two players using pure strategies can each guarantee themselves only the worst case.
The gap between the two values shows that the game has no pure "stable point". When we move to mixed strategies (½–½), both players guarantee an expected 0 and the gap closes. The minimax theorem that von Neumann proved in 1928 says that in mixed strategies these two values are equal in every finite zero-sum game.
In a zero-sum game there is no common interest; the game is pure competition. In games that are not zero-sum there can be outcomes in which everyone wins or everyone loses. Cooperation and competition coexist; communication and negotiation can change the outcome. Trade negotiations and climate agreements are games of this kind: if an agreement is reached both sides gain, and if not both lose.
2.2.5The price competition game
Two firms sell a similar product in the same market and set their prices at the same time: 100 TL or 120 TL. The cheaper one captures the customers; if both charge the high price, the profit margin stays high. Table 2.4 gives the profits in units.
| F1 \ F2 | 100 TL | 120 TL |
|---|---|---|
| 100 TL | (5, 5) | (8, 1) |
| 120 TL | (1, 8) | (6, 6) |
If both say 100 TL, each earns 5; if both say 120 TL, each earns 6 units of profit. If one says 100 and the other 120, the cheaper one gets most of the customers and earns 8; the expensive one earns only 1.
From Firm 1's point of view, the two cases are examined separately:
- If Firm 2 says 100 TL: Firm 1 earns 5 with 100 and 1 with 120. Since 5 > 1, 100 is better.
- If Firm 2 says 120 TL: Firm 1 earns 8 with 100 and 6 with 120. Since 8 > 6, 100 is again better.
- Whatever the other side does, 100 TL earns more. Such a strategy is called a dominant strategy.
- Since the game is symmetric, the same computation holds for Firm 2: 100 TL is dominant for it too.
The outcome is (100, 100), and each firm earns 5. Yet (120, 120) would have given both 6. The individually best choice leads both to a worse outcome.
This structure is that of the Prisoner's Dilemma, which is examined in detail in Section 2.4. The price competition game is not zero-sum: the sums in the cells are 10, 9, 9, and 12. The cell with the largest sum is (120, 120), but the players cannot reach it.
2.2.6Extensive form
The normal form does not show who plays first. In sequential interactions (chess, bargaining, market entry) the order matters: the second mover decides after seeing the first mover's move. The natural way to write such situations is the game tree.
The extensive form is a game tree that shows the order of decisions and who knows what at each point. The parts of the tree are:
- Root: the node where the game starts.
- Decision node: a point at which a player decides; the player to move is written on the node.
- Branch: an action.
- Leaf (terminal node): the point at which the game ends; each player's payoff is written there.
- Information set: nodes that the same player cannot tell apart (joined by a dashed line).
In Figure 2.9 the root is the Entrant's decision node. If the Entrant says "Stay out", the game ends: the Entrant earns 0 and the Incumbent keeps the market alone and earns 2. If the Entrant says "Enter", it is the Incumbent's turn. If the Incumbent says "Fight", a price war hurts both: (−1, −1). If the Incumbent says "Share", they split the market: (1, 1). The tree shows the order and who moves at each decision point. The solution of this game is given in Section 2.8.2.
2.2.7From normal form to game tree
A simultaneous game can also be drawn as a tree. For this the tree uses an information set. The conversion, using the price competition game (Table 2.4), goes step by step as follows:
- Root: Firm 1's decision. Each branch is an action: 100 TL or 120 TL.
- Second level: at the end of each branch there is a decision node for Firm 2. It also chooses 100 or 120.
- Leaves: there are four paths, and each corresponds to a cell of the matrix. For example the path 100–120 is the cell (8, 1).
- Information set: because the two firms set their prices at the same time, F2 does not see F1's choice. F2's two nodes are placed in the same information set with a dashed line.
The tree in Figure 2.10 describes exactly the same game as the matrix. The tree draws F1 first, but this is not a time order; the information set says that F2 does not know F1's choice. Putting F1 at the bottom and F2 at the top instead would give the same game.
If the information set is removed, the game changes. Then F2 decides after seeing F1's price: the game is now sequential.
In the game of Figure 2.11 the leaves are the same, but the number of strategies of F2 has changed. In the simultaneous game F2 had two strategies (100 or 120), because it could not tell its two nodes apart and had to choose the same thing at both. In the sequential game the two nodes are separate and F2 has four strategies (Figure 2.3). Information directly changes the strategy set.
The sequential price game is solved from the end backward in the tree of Figure 2.11:
- If F1 said 100, F2's options are: 5 with 100, 1 with 120. F2 says 100; the node's value is (5, 5).
- If F1 said 120, F2's options are: 8 with 100, 6 with 120. F2 says 100; the node's value is (1, 8).
- F1, knowing this, compares: 5 with 100, 1 with 120. F1 says 100.
The outcome is again (100, 100) = (5, 5). F2's strategy is (100, 100), the plan "I say 100 whatever F1 says". The reason the order does not change the outcome in this game is that 100 is dominant for both players. In games without a dominant strategy, the order can change the outcome.
2.2.8Chess is an extensive-form game
Chess is the best-known example of the extensive form. Two players move in turn; each move is a branch and each position is a node. The game has perfect information: both players see the board and all past moves. The result is a win, a loss, or a draw. A draw can arise from stalemate, from threefold repetition of a position, or from the fifty-move rule.
In 1913 Ernst Zermelo proved a basic result for games of this kind.
In a two-player, finite game of perfect information with no chance moves, either one player can guarantee a win, or both players can guarantee at least a draw.
The theorem says that the result of chess is "determinate": if both sides play without error, either White wins, or Black wins, or the game ends in a draw. But which one it is remains unknown, because the tree is so large. Figure 2.12 shows this size. After the first two plies there are 400 positions. With about 30 options per ply on average and games lasting dozens of moves, the number of games in the whole tree is about 10120. This number is far larger than the number of atoms in the observable universe (about 1080).
For this reason chess programs search only part of the tree. The search stops at a certain depth, the positions there are scored by an evaluation function, and unnecessary branches are pruned (minimax and pruning). The trees of small games such as tic-tac-toe, Nim, and "Don't Say 21" can be solved completely. These games are solved in Section 2.7.
2.3Classifying games
Games are very diverse; instead of studying each one separately it is useful to group them by shared properties. The group a game falls into determines which solution method to use. For example, a sequential game of perfect information is solved by backward induction; a simultaneous game is solved on the matrix with best responses.
2.3.1Six dimensions
Six questions are asked to classify a game. Each question is a dimension, and each dimension has two ends. Table 2.5 gives the six dimensions, the question asked in each, and an example for each end.
| Dimension | One end | Other end | Question asked | Example |
|---|---|---|---|---|
| Timing | Simultaneous | Sequential | Do I play after seeing the opponent's move? | sealed-bid offer / market entry |
| Agreements | Cooperative | Non-cooperative | Can binding agreements be made? | joint venture / Prisoner's Dilemma |
| Total payoff | Zero-sum | Non-zero-sum | Is one player's gain the other's loss? | penalty kick / climate agreement |
| Symmetry | Symmetric | Asymmetric | Is the game the same if the players swap places? | Stag Hunt / Battle of the Sexes |
| Information | Perfect information | Imperfect information | Do I see all past moves? | Connect Four / poker |
| Horizon | Finite | Infinite | Does the game have a definite end? | Centipede / ongoing price competition |
Timing. In a simultaneous game the players decide without seeing each other's choice; a sealed-bid auction is an example. In a sequential game one player moves after seeing the other's move; in the market entry game the Incumbent decides after seeing that the Entrant has entered. As seen in Section 2.2.7, the difference between the two kinds is an information set.
Agreements. In a cooperative game, players can make binding agreements: a promise can be enforced from outside, for example by a contract and a court. In a non-cooperative game there is no such enforcement; players may talk, but a promise is not binding. The unit of analysis also differs between the two kinds. In a cooperative game the question is: which group, that is, which coalition, acts together, and how does it share the payoff? The Shapley value and the core answer this question. In a non-cooperative game the unit of analysis is the single player and the central concept is the Nash equilibrium. The name "non-cooperative" does not mean that players never cooperate: cooperation can arise, but only if it is in each player's own interest.
Total payoff. In a zero-sum game (Section 2.2.4) one player's gain is the other's loss; a penalty kick is an example: a goal is a gain for the kicker and a loss for the goalkeeper. In a climate agreement there are outcomes in which everyone wins or everyone loses.
The symmetry and horizon dimensions call for a short formal definition. The information dimension was defined in Section 2.1.9: in Connect Four both players see the whole board; in poker the opponent's cards are hidden.
2.3.2Complete information, symmetry, and horizon
Complete information is a notion separate from perfect information. Under complete information everyone's payoff function is known to everyone: each player knows what the others want and how much. If this is not known, the game has incomplete information. In an auction each bidder does not know the value the others place on the item; this is a case of incomplete information. Games of incomplete information are modeled as Bayesian games: each player's unknown attribute is thought of as drawn from a probability distribution.
The difference between the two notions can be summed up as follows. Perfect information is about moves: who played what in the past? Complete information is about the game itself: what are everyone's payoffs? Chess has both perfect and complete information. Rock-Paper-Scissors has complete information (the payoffs are known to everyone) but not perfect information (the moves are made simultaneously).
A two-player game is symmetric if the two players' strategy sets are the same and, for every a, b,
u1(a, b) = u2(b, a)
holds. That is, the payoff depends not on who plays, but only on which strategy is played against which.
The equality in the definition must be read carefully: what the row player gets when the row player plays a and the column player plays b must equal what the column player gets when the roles are swapped (row plays b, column plays a). In the matrix this means that the first number in cell (a, b) equals the second number in cell (b, a).
The price competition game (Table 2.4) is checked against the definition of symmetry. Four equalities are needed:
- u1(100, 100) = 5 and u2(100, 100) = 5: equal.
- u1(100, 120) = 8 and u2(120, 100) = 8: equal.
- u1(120, 100) = 1 and u2(100, 120) = 1: equal.
- u1(120, 120) = 6 and u2(120, 120) = 6: equal.
All four equalities hold, so the game is symmetric. In Battle of the Sexes, by contrast, (Opera, Opera) = (3, 2): u1(Opera, Opera) = 3 ≠ u2(Opera, Opera) = 2. The definition fails at the first step; the game is asymmetric.
The horizon is how many rounds the game lasts. A game with a finite horizon has a definite end; the Centipede game (Section 2.8.5) ends in four moves. A game with an infinite horizon has no predetermined last round; two firms setting prices anew every month is such a game. With an infinite horizon, future payoffs are weighted by a discount factor δ ∈ (0, 1), and the player's total payoff is written as:
U = u0 + δ u1 + δ2 u2 + … = Σt δt ut
Here ut is the payoff in round t. If δ is small, the future matters little: the player is impatient. If δ is close to 1, the future matters almost as much as the present. δ has a second interpretation as well: the probability that the game continues for one more round after each round. In this reading δt is the probability that the game reaches round t.
A player earns 1 unit each round and δ = 0.9. The total payoff is computed as follows:
- The first few terms: 1 + 0.9 + 0.81 + 0.729 + …
- This is a geometric series. Let the sum be S. If S = 1 + δ + δ2 + …, then δS = δ + δ2 + …. Subtracting the two equations gives S − δS = 1, that is, S = 1 / (1 − δ).
- For δ = 0.9, S = 1 / 0.1 = 10.
Even if infinitely many rounds are played, the total is finite, because the weight of distant rounds shrinks steadily. Ten units one period from now are worth 0.9 · 10 = 9 units today. This formula is used to compute when cooperation survives in the infinitely repeated Prisoner's Dilemma (Section 2.8.8).
2.3.3Classifying a game
The six dimensions are independent of each other; a game is placed separately on each one. For chess the six answers are: sequential (players move in turn), non-cooperative (there are no binding agreements), zero-sum (if one wins the other loses), not symmetric (White moves first; the rules, however, are the same for both sides), perfect information (the board is open), and finite (the draw rules prevent the game from lasting forever).
Three games from this chapter are classified along the six dimensions:
| Dimension | Rock-Paper-Scissors | Prisoner's Dilemma | Market entry |
|---|---|---|---|
| Timing | Simultaneous | Simultaneous | Sequential |
| Agreements | Non-cooperative | Non-cooperative | Non-cooperative |
| Total payoff | Zero-sum | Non-zero-sum | Non-zero-sum |
| Symmetry | Symmetric | Symmetric | Asymmetric (different roles) |
| Information | Imperfect | Imperfect | Perfect information |
| Horizon | Finite (one round) | Finite (one round) | Finite |
Simultaneous games require an information set in the tree and therefore do not have perfect information. In the market entry game, by contrast, the Incumbent decides after seeing that the Entrant has entered; every information set is a single node. The sums of the outcomes in this game are 2, −2, and 2; since the sum is not constant, the game is not zero-sum. Because the Entrant and the Incumbent have different options and payoffs, the game is asymmetric.
- Confusing perfect information with complete information. Perfect information concerns past moves, complete information concerns payoff functions. RPS has complete information but not perfect information.
- "If they can talk, the game is cooperative." Talking is not enough; the agreement must be binding. Even if the prisoners promise each other before the interrogation, the game remains a non-cooperative game.
- Checking symmetry by looking only at the diagonal. It is not enough for the two numbers in the (a, a) cells to be equal; the off-diagonal cells (a, b) and (b, a) must also match crosswise.
2.4Equilibrium and the Prisoner's Dilemma
Writing down a game is not the same as solving it. The "solution" of a game is a prediction of which strategies the players will choose. The most basic solution concept of game theory is the Nash equilibrium. The concept stays at an intuitive level here; the Prisoner's Dilemma then shows that equilibrium and efficiency are different things.
2.4.1Best response and Nash equilibrium
The strategies of the players other than player i are written s−i. With s−i fixed, the strategy that gives player i the highest payoff is called a best response.
A profile in which everyone's strategy is a best response to the others' strategies is called a Nash equilibrium and is written s*. At equilibrium nobody wants to deviate unilaterally (Nash, 1950).
The definition can be read as a "regret test". After the game is played, each player asks themselves: "If I had known what the others did, would I change my choice?" If everyone's answer is "no", the profile is a Nash equilibrium. If a single player's answer is "yes", it is not.
In a two-player matrix, best responses and equilibria can be visualized with arrows. From each cell an arrow is drawn in the direction in which one of the players wants to deviate. A cell from which no arrow leaves is an equilibrium.
The arrows in Figure 2.13 are found for the four cells as follows:
- (120, 120) = (6, 6): if F1 switches to 100 it gets 8 (8 > 6), an upward arrow. If F2 switches to 100 it gets 8, a leftward arrow. Two arrows leave.
- (100, 120) = (8, 1): if F2 switches to 100 it gets 5 (5 > 1), a leftward arrow. If F1 switches to 120 it gets 6 (6 < 8); F1 does not deviate.
- (120, 100) = (1, 8): if F1 switches to 100 it gets 5 (5 > 1), an upward arrow. F2 does not deviate (6 < 8).
- (100, 100) = (5, 5): if F1 switches to 120 it gets 1 (1 < 5); if F2 switches to 120 it gets 1. No arrow leaves.
The only equilibrium is (100, 100). Deviation arrows flow into the equilibrium and none flows out of it.
What the Nash equilibrium says is this: with the others fixed, deviating does not pay; nobody regrets. An equilibrium is a self-sustaining situation. What the Nash equilibrium does not say is that the equilibrium is good for everyone. In price competition (120, 120) would have given both firms 6; the equilibrium gives 5 each. The Prisoner's Dilemma has the same structure. Here the intuition behind the concept and its use in the classic examples are enough.
2.4.2The Prisoner's Dilemma: story and matrix
Two suspects, Sam and John, are interrogated in separate rooms and cannot talk to each other. Each has two options: stay silent, or betray the partner by confessing. Table 2.7 gives the sentences in the four cases.
| Case | Sam | John |
|---|---|---|
| Both stay silent | 1 year | 1 year |
| Sam confesses, John stays silent | free | 3 years |
| Sam stays silent, John confesses | 3 years | free |
| Both confess | 2 years | 2 years |
For consistency of terminology, two names are fixed. Cooperation means cooperating with the accomplice, that is, staying silent. Betrayal means confessing (cooperating with the police). In short, the two strategies are written "Silent" and "Betray".
Years in prison are bad; fewer is better. The payoff is written as −(years in prison): a light sentence means a large payoff. Table 2.8 gives the payoff matrix of the game. In each cell the first number is Sam's (row) payoff and the second is John's (column) payoff, and the cells are named a, b, c, d.
| Sam \ John | Silent | Betray |
|---|---|---|
| Silent | a (−1, −1) | b (−3, 0) |
| Betray | c (0, −3) | d (−2, −2) |
The table is read as follows. If both stay silent (cell a), both get −1. If Sam stays silent and John betrays (cell b), Sam gets −3 and John 0: Sam serves 3 years and John goes free. Cell c is the reverse. If both betray (cell d), both get −2. The basic question is this: what happens if each prisoner wants to minimize their own sentence?
2.4.3Why is Betray dominant?
Sam does not know what John will do. So he examines the two cases separately. This method is called case analysis: a best response is found for each possible choice of the opponent.
- Case 1: John stays silent. If Sam stays silent he gets −1 (cell a); if he betrays he gets 0 (cell c). Since 0 > −1, betraying is better.
- Case 2: John betrays. If Sam stays silent he gets −3 (cell b); if he betrays he gets −2 (cell d). Since −2 > −3, betraying is again better.
- Whatever John does, betraying brings Sam a lighter sentence. Betray is a dominant strategy for Sam.
- The game is symmetric; John faces the same dilemma and Betray is dominant for him too.
- Both betray. The outcome is cell d: (−2, −2), that is, two years in prison each.
A strategy si of player i is a (strictly) dominant strategy if it gives strictly more than any other strategy against every possible choice of the others: ui(si, s−i) > ui(si′, s−i) for every si′ ≠ si and every s−i.
If a dominant strategy exists, the player does not have to predict what the other will do. Sam does not need to know John's probabilities; the same answer is best in every case. This is the strongest feature of a dominant strategy: it requires no belief about the opponent.
- "Betray is chosen because it reduces the average sentence." This reasoning is wrong. Betray is better against every choice of John; there is no need to average or to know John's probabilities.
- "Confessing is the best outcome for both." It is not. If both had stayed silent (cell a) they would have got (−1, −1), which is better for both than (−2, −2). The individually best choice makes both worse off.
- Confusing sentences with payoffs. If years in prison are read directly as payoffs, "choosing the larger" would mean choosing 3 years. Never compute without putting the minus sign.
2.4.4The message of the dilemma
The game's only Nash equilibrium is (Betray, Betray) = (−2, −2). This is easy to check: from cell d, if Sam switches to Silent he gets −3, and if John switches to Silent he gets −3; neither deviates. In the other three cells at least one player gains by switching to betrayal. By contrast, (Silent, Silent) = (−1, −1) is better for both. So the equilibrium is worse than an outcome that makes both better off; in the language to be defined in Section 2.4.5, the equilibrium is not Pareto optimal.
The situation does not change even if the prisoners agree before the interrogation. The game is a non-cooperative game: the agreement is not binding. After the promise "we will both stay silent", Sam, believing John will stay silent, betrays and gets 0 (instead of −1). For both of them, breaking the promise pays. Since the promise does not change the payoffs, it does not change the dominant strategy either.
The message of the game is this: everyone behaving rationally in their own interest does not guarantee a good outcome for society. This shows that the idea of the "invisible hand", that behavior pursuing individual interest spontaneously leads to social good, does not always hold.
The structure of the Prisoner's Dilemma appears often in everyday life:
- Price wars: every firm cuts its price, and in the end all profits fall (Table 2.4).
- Arms races: every country arms itself, nobody is safer, and all become poorer.
- Climate agreements: every country wants to avoid the cost of cutting emissions.
- Doping in sport: if everyone dopes, the relative ranking does not change, but everyone's health suffers.
- Overuse of common resources: fishermen catch more even though they know the stock will run out.
There are also ways out of the dilemma. The first is repeated play and reputation: if the same players meet again and again, today's betrayal can be punished tomorrow. The tit-for-tat strategy cooperates in the first round and then copies the opponent's previous move. How cooperation survives under infinite repetition is computed in Section 2.8.8. The second is contract and incentive design: if the payoffs are changed, for example by adding a penalty for betrayal, betrayal stops being dominant. Designing the rules of the game is the subject of mechanism design (Section 2.10.3).
2.4.5Pareto optimality
The Nash equilibrium is a concept of stability. To measure whether an outcome is efficient, a separate concept is needed. The weakest and most common criterion for this is Pareto optimality.
An outcome x Pareto dominates an outcome y if and only if u(x) ≥ u(y) for every player and u(x) > u(y) for at least one player.
An outcome that no outcome Pareto dominates is Pareto optimal: nobody can be made better off without making someone worse off.
In payoff space, the plane in which each outcome is drawn as a point (u1, u2), the definition has an easy visual counterpart. The upper-right quadrant of a point is the region of points that give both players at least as much. If this region contains no other outcome (apart from the point itself), the point is Pareto optimal.
The four outcomes of the Prisoner's Dilemma (S: Silent, B: Betray) are checked one by one:
- (B, B) = (−2, −2): (S, S) = (−1, −1) gives both more (−1 > −2). It is Pareto dominated.
- (S, S) = (−1, −1): to dominate it we would need an outcome that gives both players at least −1 and one of them more. (S, B) = (−3, 0) makes Sam worse off, (B, S) = (0, −3) makes John worse off. It is Pareto optimal.
- (S, B) = (−3, 0): no outcome gives John more than 0; this is the only outcome that gives 0. Nobody can dominate it. It is Pareto optimal.
- (B, S) = (0, −3): by the same reasoning it is the only outcome that gives Sam 0. It is Pareto optimal.
Conclusion: (S, S), (S, B), and (B, S) are Pareto optimal; (B, B), the only Nash equilibrium, is Pareto dominated. The game's equilibrium is the only inefficient outcome among the four.
Pareto optimality does not mean fairness. (S, B) is Pareto optimal, but Sam serves 3 years while John goes free. Pareto optimality says only "nothing is wasted"; it does not look at how the payoff is distributed. An outcome in which one player takes everything and the other nothing can also be Pareto optimal.
Equilibrium (stability) and efficiency are separate questions. The Prisoner's Dilemma shows that the two questions can have different answers: what is stable is not efficient, and what is efficient is not stable. The loss in between is measured by the Price of Anarchy. If years in prison are counted as costs, the total cost at equilibrium is 2 + 2 = 4 years and at the best outcome (S, S) it is 1 + 1 = 2 years; the ratio is 4 / 2 = 2. Selfish behavior doubles the total cost.
2.5Classic 2×2 games
Games in which two players each have two strategies are called 2×2 games. Their matrices consist of only four cells, but these small games represent very different strategic situations: pure conflict, a problem of trust, a problem of meeting, and a contest of nerve. Six classic games cover all of these situations.
2.5.1Six games and their pure equilibria
Table 2.9 writes the six games in a single format. Each row is one game. The column (1, 2) shows the cell where the row player plays their 1st action and the column player their 2nd action; in each cell the row player's payoff is written first, then the column player's.
| Game | Actions (1 / 2) | (1, 1) | (1, 2) | (2, 1) | (2, 2) | Pure Nash equilibria |
|---|---|---|---|---|---|---|
| Matching Pennies | Heads / Tails | (1, −1) | (−1, 1) | (−1, 1) | (1, −1) | none |
| Chicken | Swerve / Straight | (0, 0) | (−1, 1) | (1, −1) | (−10, −10) | (Swerve, Straight), (Straight, Swerve) |
| Battle of the Sexes | Opera / Football | (3, 2) | (0, 0) | (0, 0) | (2, 3) | (Opera, Opera), (Football, Football) |
| Stag Hunt | Stag / Hare | (4, 4) | (0, 3) | (3, 0) | (3, 3) | (Stag, Stag), (Hare, Hare) |
| Pure Coordination | Party / Home | (10, 10) | (0, 0) | (0, 0) | (5, 5) | (Party, Party), (Home, Home) |
| Free Money | Heads / Tails | (1, 1) | (0, 0) | (0, 0) | (0, 0) | (Heads, Heads) strict; (Tails, Tails) weak |
There is a systematic way to find pure equilibria: best-response marking. In each column the row player's largest payoff is marked; this is the row player's best response to that column. In each row the column player's largest payoff is marked; this is the column player's best response to that row. A cell carrying both marks is a cell in which each player's choice is a best response to the other's, that is, a pure Nash equilibrium. If there are ties, all of the tied largest values are marked.
In Chicken, two drivers approach each other on a narrow road. Each either swerves to the side (Swerve) or goes straight (Straight). The marking goes as follows:
- Column "Swerve" (the column player swerves): the row player gets 0 with Swerve and 1 with Straight. Straight is best (1 > 0); a row mark goes on the cell (Straight, Swerve).
- Column "Straight": the row player gets −1 with Swerve and −10 with Straight. Swerve is best (−1 > −10); a row mark goes on the cell (Swerve, Straight).
- Row "Swerve": the column player gets 0 with Swerve and 1 with Straight. Straight is best; a column mark goes on the cell (Swerve, Straight).
- Row "Straight": the column player gets −1 with Swerve and −10 with Straight. Swerve is best; a column mark goes on the cell (Straight, Swerve).
| 1 \ 2 | Swerve | Straight |
|---|---|---|
| Swerve | (0, 0) | (−1*, 1*) |
| Straight | (1*, −1*) | (−10, −10) |
The cells with two marks are (Swerve, Straight) and (Straight, Swerve). The game has two pure equilibria, and in both one driver swerves and the other goes straight. (Straight, Straight) is the worst outcome: a collision.
In Matching Pennies, marking leaves no cell with two marks:
- Column Heads: the row player gets 1 with Heads and −1 with Tails → a row mark on (Heads, Heads).
- Column Tails: the row player gets −1 with Heads and 1 with Tails → a row mark on (Tails, Tails).
- Row Heads: the column player gets −1 with Heads and 1 with Tails → a column mark on (Heads, Tails).
- Row Tails: the column player gets 1 with Heads and −1 with Tails → a column mark on (Tails, Heads).
The row marks are on the diagonal and the column marks are off the diagonal; no cell carries two marks. There is no pure Nash equilibrium. In every cell the losing player wants to deviate, and the deviation arrows trace a cycle.
In Free Money, if both players say Heads each gets one unit; in the other three cells nobody gets anything. Marking requires care with ties:
- Column Heads: the row player gets 1 with Heads and 0 with Tails → Heads is marked.
- Column Tails: the row player gets 0 with Heads and 0 with Tails → a tie; both are marked.
- Row Heads: the column player gets 1 with Heads and 0 with Tails → Heads is marked.
- Row Tails: the column player gets 0 with Heads and 0 with Tails → both are marked.
The cells with two marks are (Heads, Heads) and (Tails, Tails). The two equilibria are of different kinds. (Heads, Heads) is a strict equilibrium: a player who deviates drops from 1 to 0, that is, loses. (Tails, Tails) is a weak equilibrium: a player who deviates goes from 0 to 0; deviating does not gain, but it does not lose either. Heads weakly dominates Tails: it is never worse and is better in at least one case.
The marking for the remaining three games is done the same way. In Battle of the Sexes, (Opera, Opera) = (3, 2) and (Football, Football) = (2, 3) carry two marks; in the off-diagonal (0, 0) cells both players want to move to the meeting point. In Stag Hunt, (Stag, Stag) = (4, 4) and (Hare, Hare) = (3, 3) are equilibria: someone who knows the other is hunting Stag gets 4 from Stag and 3 from Hare; someone who knows the other is hunting Hare gets 0 from Stag and 3 from Hare. In Pure Coordination, (Party, Party) and (Home, Home) are equilibria.
- Thinking one mark is enough. For a cell to be an equilibrium, both players must be playing a best response. In a cell carrying only a row mark, the column player deviates.
- Searching in the wrong direction. The row player's best response is searched within a column (up and down), because the row player can change only their row. The column player's is searched within a row (left and right).
- Looking at the wrong number. For the row player the first number of each cell is compared, for the column player the second.
- Picking one in a tie. All of the tied largest values are marked; otherwise the weak equilibrium in Free Money is missed.
2.5.2Conflict or coordination?
The six games line up on a spectrum according to how much the two players' interests overlap. At one end is Matching Pennies, where interests are completely opposed; at the other end are Pure Coordination and Free Money, where there is no conflict at all.
Matching Pennies: pure conflict. Interests are completely opposed and the game is zero-sum. In every cell the loser deviates. Any predictable tendency of a player is exploited: if the Matcher says Heads a little more often, the Mismatcher shifts to Tails. The only way out is to play at random, that is, the mixed strategy (½–½). The penalty kick is a real-life example of this structure: the kicker and the goalkeeper try to guess each other.
Chicken: anti-coordination. The players want to choose different actions: one must swerve and the other go straight. There are two equilibria, and each favors one driver. Who wins? The one who credibly shows that they cannot back down. For example, a driver who throws the steering wheel out of the window shows that they have no option other than Straight; the other driver's best response is then to swerve. Such behavior is called commitment. Commitment gains by reducing options; in a single-person decision problem reducing options never helps, but in a game it can.
Battle of the Sexes: coordination and conflict together. Two people want to spend the evening together; meeting is a shared interest. But one prefers Opera (3 > 2) and the other Football (3 > 2); where to meet is the conflict. There is no dominant strategy. Solutions are communication ("I'm going to the opera tonight"), convention, or taking turns (opera one week, football the next).
Stag Hunt: a trust dilemma. If two hunters hunt a stag together they get a big reward (4, 4). If one hunts a hare alone, they get 3; the other, chasing the stag, is left empty-handed (0). (Stag, Stag) is both an equilibrium and Pareto optimal. But Hare guarantees 3 in every case: whatever the other does, the hare hunter gets 3. Stag requires trusting the other. The difference from the Prisoner's Dilemma is this: in Stag Hunt cooperation is an equilibrium. Nobody wants to deviate unilaterally from cooperation; the problem is not the wish to deviate but the fear that the other will deviate (Skyrms, 2004).
Pure Coordination: a bad equilibrium is lasting too. There is no conflict of interest: both players prefer to meet at the Party (10 > 5). But (Home, Home) is an equilibrium too: someone who knows the other will stay home gets 0 by going to the party and 5 by staying home. The bad equilibrium sustains itself. Players often head for what is salient, "what will occur to everyone". Thomas Schelling called such choices focal points (Schelling, 1960). For example, two people in a city who have not been told where to meet will often go to the best-known square of the city.
Free Money: a weak equilibrium. (Heads, Heads) is a strict equilibrium: a deviator loses. (Tails, Tails) is a weak equilibrium: deviating does not gain, but it does not lose either. Heads is weakly dominant; a sensible player has no reason to pick Tails. This game shows that the "≥" sign in the definition of the Nash equilibrium sometimes admits implausible equilibria too.
Which of the six games are zero-sum and which are symmetric is checked against the definitions:
- Zero-sum: the total must be 0 in every cell. In Matching Pennies all totals are 0. In Chicken the total of (−10, −10) is −20; the others also have cells whose total differs from zero (e.g. (4, 4) in Stag Hunt). Only Matching Pennies is zero-sum.
- Symmetric: u1(a, b) = u2(b, a) must hold. In Chicken u1(Swerve, Straight) = −1 = u2(Straight, Swerve), u1(Straight, Swerve) = 1 = u2(Swerve, Straight), and the diagonals are equal: it is symmetric. Stag Hunt, Pure Coordination, and Free Money pass the same check.
- Not symmetric: in Battle of the Sexes u1(Opera, Opera) = 3 ≠ 2 = u2(Opera, Opera). In Matching Pennies u1(Heads, Heads) = 1 ≠ −1 = u2(Heads, Heads); one role wants to match and the other to mismatch.
Conclusion: only Matching Pennies is zero-sum; the symmetric ones are Chicken, Stag Hunt, Pure Coordination, and Free Money.
| Game | Structure | Number of pure equilibria | Core problem |
|---|---|---|---|
| Matching Pennies | Pure conflict | 0 | Being unpredictable |
| Chicken | Anti-coordination | 2 | Who will back down? (commitment) |
| Battle of the Sexes | Coordination + conflict | 2 | Where to meet? |
| Stag Hunt | Trust | 2 | Will the other be trusted? |
| Pure Coordination | Purely shared interest | 2 | Avoiding the bad equilibrium (focal point) |
| Free Money | Shared interest, weak equilibrium | 2 | Choosing the weakly dominant strategy |
2.6The guess-two-thirds game
The game at the start of the chapter (Section 2.1.1) can now be solved. The game has two "answers". One is the theory's answer: what happens if everyone is fully rational and this is common knowledge? The other is the practical answer: what is the best guess in a real classroom? The two answers differ.
2.6.1Level-k thinking
Real players do not think infinitely many steps; they stop after a few. One way to model this behavior is level-k reasoning. The model classifies players by how many steps they think.
A level-0 player does not think strategically and writes a random number; on the range 0–90 the average of these guesses is 45. A level-k player (k ≥ 1) assumes that everyone else is level k − 1 and best-responds to this assumption: they write two-thirds of the level-k − 1 guess.
| Level of thinking | Assumption | Guess |
|---|---|---|
| Level 0 | Everyone writes at random, average 45 | — (random) |
| Level 1 | Others are level 0 | 2/3 · 45 = 30 |
| Level 2 | Others are level 1 | 2/3 · 30 = 20 |
| Level 3 | Others are level 2 | 2/3 · 20 ≈ 13.3 |
| Level ∞ | Everyone is fully rational | 0 |
The reasoning "the average will be 45, two-thirds of that is 30" is only level 1. Someone who thinks the others will also say 30 writes a lower number, for example 20. Someone who thinks everyone will write too low may shift back up a little. The level-k guess is in general 45 · (2/3)k, and it approaches 0 as k grows.
The important point is this: the best guess depends on the belief about what level the others think at. If most of the class is level 1, the best response is level 2; thinking further loses. The notion of level should not be confused with the knowledge level (Figure 2.2), which counts the "everyone knows" layers of common knowledge. The level is how many steps a player thinks; the knowledge level is what is known about the players.
2.6.2Code trace: the level-k guess
The Python code below, given a belief about the distribution of levels in the class, computes how far from the target each level will fall.
def guess(k, L0=45): # level-k
g = L0
for _ in range(k):
g = g * 2 / 3
return g
share = {0: 0.3, 1: 0.4, 2: 0.3} # belief
avg = sum(p * guess(k) for k, p in share.items())
target = avg * 2 / 3
for k in range(5):
print(k, round(guess(k), 1),
round(abs(guess(k) - target), 1))The code works as follows:
guess(k, L0=45)returns the guess of a level-kplayer.gstarts at 45, and the loop runsktimes, multiplyinggby 2/3 each time. Fork = 0the loop never runs and 45 is returned: the average of level 0.- The dictionary
shareholds the belief: 30% of the class is level 0, 40% is level 1, 30% is level 2. avgis the expected average: each level's guess is multiplied by that level's share and the products are summed.targetis two-thirds of the average; this is the winning number.- The last loop prints, for each level from 0 to 4, the guess and its distance from the target.
- Level guesses:
guess(0) = 45,guess(1) = 30,guess(2) = 20. - Expected average: 0.3 · 45 + 0.4 · 30 + 0.3 · 20 = 13.5 + 12 + 6 = 31.5.
- Target: 2/3 · 31.5 = 21.
- The distance of each level is listed in Table 2.13.
| k | guess(k) | |guess − target| | Comment |
|---|---|---|---|
| 0 | 45 | 24 | writing the average is far too high |
| 1 | 30 | 9 | the classic "45 → 30" answer, still far |
| 2 | 20 | 1 | closest to the target among the levels examined (the best response is the target itself, ≈ 21) |
| 3 | 13.3 | 7.7 | thinking one level too far loses |
| 4 | 8.9 | 12.1 | the distance grows as the guess nears 0 |
Against this population, the player who writes 20 wins. The player who writes 0, the Nash equilibrium answer, is 21 units away and loses. The best response depends on beliefs.
Figure 2.16 shows the same result on a number line. The target (21) is very close to the level-2 guess (20). Levels 3 and 4 fall to the left of the target, levels 0 and 1 to the right. The location of the target depends on the population: if a larger part of the population were level 0, the target would shift to the right.
2.6.3Iterated elimination
The theory's answer is found by a different method. This method deletes, step by step, the guesses that can never be good.
A strategy is dominated if another strategy gives a better result against every choice of the others. A rational player does not play a dominated strategy. Iterated elimination of dominated strategies means deleting the dominated strategies, then searching for newly dominated ones in the shrunken game, and continuing until no new deletion can be made.
In the 2/3 game the elimination works as follows. Initially every guess is between 0 and 90 and nothing has been eliminated.
- Round 1. The average can be at most 90, so the target is at most 60. Every guess above 60 is never better than writing 60: if the target is below 60, then 60 is closer to it. These guesses are eliminated. (This elimination rests on weak domination: since the prize goes to the winner, 61 sometimes does as well as 60; for example with two players, if the opponent says 90 both win.)
- Round 2. Everyone is rational and everyone knows it: nobody exceeds 60. Average ≤ 60 ⇒ target ≤ 40. Everything above 40 is eliminated.
- Round 3. Average ≤ 40 ⇒ target ≤ 26.7. To take this step one must know that "everyone knows that everyone is rational".
- Rounds 4–6. Average ≤ 26.7 ⇒ target ≤ 17.8; average ≤ 17.8 ⇒ target ≤ 11.9; average ≤ 11.9 ⇒ target ≤ 7.9.
In each round the upper bound is multiplied by 2/3; after k rounds the upper bound is 90 · (2/3)k. The code below repeats this multiplication for six rounds.
hi = 90 # largest possible guess
for t in range(1, 7):
# avg ≤ hi ⇒ target ≤ (2/3)·hi
hi = hi * 2 / 3
print(t, round(hi, 1))
# hi = 90·(2/3)^k → 0 : unique equilibrium, all 0| t | Previous hi | New hi = hi · 2/3 | Meaning |
|---|---|---|---|
| 1 | 90 | 60 | everyone is rational |
| 2 | 60 | 40 | + everyone knows this |
| 3 | 40 | 26.7 | + they know that they know it |
| 4 | 26.7 | 17.8 | one more layer |
| 5 | 17.8 | 11.9 | one more layer |
| 6 | 11.9 | 7.9 | one more layer |
In the code the variable hi holds the "largest meaningful guess". In each round of the loop the inference in the comment line is applied: if the average cannot exceed hi, the target cannot exceed (2/3)·hi. The new hi is this value. The loop stops after 6 rounds, but in theory the process goes on forever.
The upper bound shrinks geometrically: each round it is two-thirds of the previous one. After how many rounds does the bound fall below 1? The inequality 90 · (2/3)k < 1 first holds for k = 12 (90 · (2/3)12 ≈ 0.69; for k = 11 it is ≈ 1.04). But in no finite number of rounds is exactly 0 reached. The process continues forever and the upper bound converges to 0: the only profile that survives iterated elimination is everyone saying 0 (Figure 2.17).
2.6.4The unique Nash equilibrium: everyone picks 0
Iterated elimination leaves the profile in which everyone says 0. That this profile is a Nash equilibrium is checked separately.
Let all n players write 0. The regret test is applied:
- If everyone says 0, the average is 0 and the target is 0. Everyone hits the target exactly and the prize is shared.
- Let one player deviate to x > 0. The total becomes x, the average x/n, and the target 2x/(3n).
- The others' 0 is at distance 2x/(3n) from the target. The deviator's x is at distance x − 2x/(3n) = x(3n − 2)/(3n) from the target.
- For n ≥ 2, 3n − 2 > 2, so the deviator's distance is larger. For example, for n = 10, x = 30 the target is 2; 0 is 2 away from the target and 30 is 28 away.
- The deviating player loses and is also deprived of their share. The deviation is unprofitable; the profile is a Nash equilibrium.
That the equilibrium is unique cannot be derived from iterated elimination: the elimination rests on weak domination, and deleting weakly dominated strategies can also delete some equilibria. Uniqueness is shown directly. Let S be the sum of the others' guesses. If a player writes g = 2S/(3n − 2), the new target is exactly g; the player hits the target exactly.
- In an equilibrium everyone must get a share of the prize: a player with a zero share would hit the target by changing their guess to g and get a share.
- If everyone gets a share, everyone is at the same distance from the target. If this distance is positive, a player who deviates to g wins alone and takes the whole prize that was being shared; this is a profitable deviation.
- What remains is the profile in which everyone is on the target: everyone says the same x and x = (2/3)x, that is, x = 0.
Hence everyone saying 0 is the only equilibrium. Elimination gives the intuitive way of finding this equilibrium, and the direct proof gives its uniqueness.
One detail shows how the rules of the game affect the equilibrium. If only integers were allowed, "everyone says 1" would also be an equilibrium with n ≥ 4 players. Allowing decimal guesses removes this second equilibrium.
Only integers are allowed, and all n players write 1. The average is 1, the target is 2/3, and everyone shares (each gets 1/n of the prize).
- Let one player deviate to 0. The average becomes (n − 1)/n and the target 2(n − 1)/(3n).
- The deviator's distance is 2(n − 1)/(3n); the others' distance is 1 − 2(n − 1)/(3n) = (n + 2)/(3n).
- The deviator wins alone only if 2(n − 1) < n + 2, that is, n < 4. At n = 4 the two distances are equal (6/12 = 6/12) and the prize is again divided among four; the deviation does not raise the payoff. For n > 4 the deviator loses.
- Let one player deviate to 2. The average becomes (n + 1)/n and the target 2(n + 1)/(3n); for n ≥ 2 this number is at most 1. 1 is closer to the target than 2 is; the deviator loses.
So for n ≥ 4, "everyone says 1" allows no profitable deviation and is an equilibrium. With decimal guesses, however, in the situation "everyone says 1" a player deviating to a number such as 0.7 gets closer to the target (with 10 players the target becomes about 0.65; 0.7 is 0.05 away from it and 1 is 0.35 away) and wins alone; the equilibrium is destroyed.
2.6.5Theory and experiment
The theory's answer is 0. But in experiments the winning number is not 0. In the 0–100 version run with Financial Times readers in 1997, the winning guess was 13. In Rosemarie Nagel's laboratory experiments, published in 1995, first-round guesses clustered around 1–2 steps of thinking: most guesses were near the guesses of level 1 or level 2 (Nagel, 1995). As the game was repeated with the same group, guesses came down toward 0.
| Theory: iterated elimination | Largest meaningful guess | Reality: level-k | Guess |
|---|---|---|---|
| start | 90 | level 0 (random, average 45) | 45 |
| step 1 | 2/3 × 90 = 60 | level 1 (others are level 0) | 30 |
| step 2 | 2/3 × 60 = 40 | level 2 (others are level 1) | 20 |
| step 3 | 26.7 | level 3 (others are level 2) | 13.3 |
| step 4 | 17.8 | … | … |
| … | → 0 | level ∞ | 0 |
The two columns answer different questions. The left column shows what each layer of common knowledge eliminates: each step adds one more layer of the assumption "everyone is rational", and the end of infinitely many steps is the unique Nash equilibrium. The right column models what players actually write. The difference between theory and experiment comes from the fact that the assumption "everyone is fully rational and this is common knowledge" does not hold fully in reality. If even a few people write high numbers, the average rises and the player who writes 0 loses.
In this game, determining the Nash equilibrium is not hard: the equilibrium is unique and in pure strategies. What is hard is predicting the best response against real players. To win, one needs to know not 0 but how many steps the class thinks. If the class plays level 1 and the average comes out at 30, the target is 20; level 2 wins.
Let the game be on the range 0–100 with the target "half of the average". Iterated elimination proceeds as follows:
- Average at most 100 ⇒ target at most 50. Everything above 50 is eliminated.
- Average at most 50 ⇒ target at most 25. Everything above 25 is eliminated.
- The next bounds are 12.5; 6.25; 3.125; … In each round the bound is halved.
The upper bound converges to 0 and the unique equilibrium is again everyone saying 0. As long as the multiplier is below 1 (2/3, 1/2, …) the result does not change; only the speed of convergence does. The smaller the multiplier, the faster the bound shrinks.
2.7Combinatorial games
Games such as chess, tic-tac-toe, and Nim share a structure: two players move in turn, everything is open, and there are no dice or cards. These games are the most "algorithmic" corner of game theory: in principle each of them can be solved by sweeping the tree from the end backward. This sweep takes three forms: minimax, backward labeling, and Nim's XOR rule.
2.7.1Combinatorial games and Zermelo's theorem
A combinatorial game has the following properties: two players move in turn; information is perfect; there is no chance; the game ends in a finite number of steps.
Normal play: the player who makes the last move wins; the player who cannot move loses.
Nim is played under normal play: whoever takes the last token wins. In Don't Say 21 the rule is reversed: the player who says 21, that is, who is forced to make the last move, loses. In tic-tac-toe and chess a draw is also possible. Zermelo's theorem (Theorem 2.1) applies to all of these games: in such a game either one player can force a win or both can force a draw.
In some games, who wins can be found without searching the tree at all. Hex is a famous example. In Hex there are no draws: when the board is full, one of the players has necessarily connected their own sides. The strategy-stealing argument works as follows. Suppose the second player has a winning strategy. The first player places a random stone and then, putting themselves in the second player's place, plays that winning strategy. The extra stone on the board never hurts them; if the square the strategy asks for is already occupied, they place another random stone. Thus the first player wins too. Since it is impossible for both players to win at the same time, the assumption is false: the second player has no winning strategy. Since there are no draws, the first player wins. The argument does not say how the first player wins; it only shows that they do.
In combinatorial games every position is of one of two types:
In a game played under normal play, a position is an N-position (next: the player to move wins) if the player to move can guarantee a win, and a P-position (previous: the previous player wins) if they cannot. The labels are determined by two rules:
- Every move from a P-position goes to an N-position.
- At least one move from an N-position goes to a P-position.
The final position, in which no move can be made, is a P-position under normal play: the player to move cannot move and loses.
The logic of the rules is this. If the player to move can send the opponent to a P-position, they do so; whatever the opponent does, it leaves them an N-position again, and each time the player sends the opponent back to P. In the end it is the opponent who cannot move. If all of a player's moves go to N-positions, then whatever they do they leave the opponent a winning position.
In two-heap Nim the heaps contain 1 and 2 tokens. The player to move takes at least one token from a single heap; whoever takes the last token wins. Positions are written (first heap, second heap) and the labels are computed from the leaves to the root (Figure 2.18):
- (0, 0): no move. The player to move loses → P.
- (0, 1) and (1, 0): the single move goes to (0, 0), which is P → N.
- (0, 2): one can go to (0, 1) or to (0, 0). (0, 0) is P → N. The winning move is to take both tokens at once.
- (1, 1): the moves go to (0, 1) and (1, 0); both are N → P.
- (1, 2): the moves are (0, 2) [N], (1, 1) [P], (1, 0) [N]. Since (1, 1) is P → N. The winning move is to take one token from the second heap, leaving (1, 1).
The starting position (1, 2) is N: the first player wins if they play correctly. Computing the labels from the leaves to the root is the special case of minimax that works with win/lose values.
2.7.2Code trace: minimax on a game tree
If the payoff values are numbers rather than just "win / lose", the same idea is carried out by the minimax algorithm. The two players are called MAX and MIN. MAX wants a large value and MIN wants a small one. The numbers at the leaves are MAX's payoff; since the game is zero-sum, MIN's payoff is the negative of that. The value of a node is defined as follows: at a leaf it is the payoff at the end of the game; at a MAX node it is the largest of the children's values, and at a MIN node the smallest.
T = {"A": ["B", "C", "D"], "B": [3, 12, 8],
"C": [2, 4, 6], "D": [14, 5, 2]}
def minimax(n, maxi):
if isinstance(n, int): # leaf
return n
best = float("-inf") if maxi else float("inf")
for c in T[n]:
v = minimax(c, not maxi)
best = max(best, v) if maxi else min(best, v)
return best
print(minimax("A", True))The parts of the code are:
- The dictionary
Tholds the tree. The children of the root A are B, C, D. The children of B, C, D are leaves, represented by integers (int). minimax(n, maxi)returns the value of noden. Ifmaxiis true, it is MAX's turn.- If
isinstance(n, int)is true,nis a leaf and its value is itself; the function returns immediately. beststarts at −∞ for MAX and +∞ for MIN. These values mean "no child seen yet": the first value MAX sees is larger than −∞, and the first value MIN sees is smaller than +∞. (Fixed numbers such as −99 and 99 give wrong results when leaf values exceed these bounds.)- The loop evaluates each child in turn. At a child it is the other player's turn; so the recursive call is made with
not maxi. MAX updatesbestwithmax, MIN withmin.
| Step | Node (to move) | Value seen | best |
|---|---|---|---|
| 1 | B (MIN) | start | +∞ |
| 2 | B | leaf 3 | min(+∞, 3) = 3 |
| 3 | B | leaf 12 | min(3, 12) = 3 |
| 4 | B | leaf 8 | min(3, 8) = 3 → returns B = 3 |
| 5 | A (MAX) | B = 3 | max(−∞, 3) = 3 |
| 6 | C (MIN) | leaves 2, 4, 6 | +∞ → 2 → 2 → 2; C = 2 |
| 7 | A (MAX) | C = 2 | max(3, 2) = 3 |
| 8 | D (MIN) | leaves 14, 5, 2 | +∞ → 14 → 5 → 2; D = 2 |
| 9 | A (MAX) | D = 2 | max(3, 2) = 3 → result 3 |
The notable point in the trace is node D. D's first leaf is 14, which looks attractive to MAX. But D is a MIN node: MIN chooses 2 instead of 14. Knowing this, MAX does not go to D. The value of the game is 3: MAX chooses B and, whatever MIN does, guarantees at least 3 (Figure 2.19). The code looks at all 9 leaves. Alpha-beta pruning can skip some leaves without evaluating them at all: for example, once C's first leaf 2 has been seen, C's value will be at most 2, which is below 3; there is no need to look at C's other leaves.
- Looking for the largest leaf. MAX cannot reach the largest number in the tree (14), because MIN makes the choice in between. Values are computed from the bottom up, at each node from the point of view of the player to move.
- Mixing up the levels. In these turn-taking trees, at the children of a node it is the other player's turn. In the code this is ensured by
not maxiin the recursive call.
2.7.3Tic-tac-toe: the whole tree can be searched
The tree of tic-tac-toe is small. A program that counts all the games finds 255,168 distinct games and 5,478 reachable positions. These numbers are tiny for a computer: the whole tree is searched in less than a second. The minimax values are taken as +1 (X wins), 0 (draw), and −1 (O wins). On the empty board the minimax value is 0: if both sides play without error, the game ends in a draw.
In the position of Figure 2.20, X wins only with the bottom-left square. This move does two things: it blocks O's diagonal (top right – center – bottom left) and at the same time creates two threats. In the left column (X, empty, X) and in the bottom row (X, empty, X) two separate winning threats arise. O can block only one; X completes the other (+1). On every other square, O completes their own diagonal and wins (−1).
In chess a full search is impossible; the tree has about 10120 games. Chess programs work with three techniques: a depth limit (the tree is cut after a certain number of moves), an evaluation function (the position at the cutoff is given a score: piece values, king safety, and so on), and alpha-beta pruning (branches that cannot change the result are skipped). Together these three techniques turn minimax into a strong player even in games where full search is impossible. A minimax tic-tac-toe opponent, in turn, plays by computing the values exactly: it cannot be beaten; the best one can hope for is a draw.
2.7.4Code trace: Don't Say 21
The rule of Don't Say 21 is as follows: two players take turns, starting from 1, saying 1, 2, or 3 consecutive numbers. For example, the first player says "1, 2", the second says "3, 4, 5", the first says "6". Whoever says 21 loses. The state of the game is described by the last number said, c; at the start c = 0.
Each state is labeled W (the player to move wins) or L (the player to move loses). The base state is c = 20: the player to move must say 21 and loses (L). The other states are computed from the end backward: if from a state there is a move that pushes the opponent into an L state, the state is W; otherwise it is L.
TARGET = 21
wins = {TARGET - 1: False} # c=20: lost
for c in range(TARGET - 2, -1, -1):
wins[c] = any(not wins[c + k]
for k in (1, 2, 3) if c + k < TARGET)
keys = [c for c in wins if not wins[c]]
print(sorted(keys))The code works as follows:
- The dictionary
winsholds, for each c, the answer to the question "does the player to move win?"wins[20] = False: the base state. - The loop runs backward over c from 19 down to 0. For each c, saying 1, 2, or 3 numbers leads to the state c + k (without reaching 21;
c + k < TARGET). any(not wins[c + k] …): if at least one move leads to a state that loses for the opponent, c is a winning state.- The list
keyscollects the losing states. These are the numbers a player wants to leave to the opponent: the key numbers.
| c | States reachable | Can push the opponent into L? | Label |
|---|---|---|---|
| 20 | — (must say 21) | no | L |
| 19, 18, 17 | can reach 20 | yes, says 20 | W |
| 16 | 17, 18, 19 (all W) | no | L |
| 15, 14, 13 | can reach 16 | yes, says 16 | W |
| 12 | 13, 14, 15 (all W) | no | L |
| 11, 10, 9 | can reach 12 | yes | W |
| 8 | 9, 10, 11 (all W) | no | L |
| 7, 6, 5 | can reach 8 | yes | W |
| 4 | 5, 6, 7 (all W) | no | L |
| 3, 2, 1 | can reach 4 | yes | W |
| 0 | 1, 2, 3 (all W) | no | L |
The code prints [0, 4, 8, 12, 16, 20]. The L states are the multiples of 4 (Figure 2.21). The starting state c = 0 is L: the first player loses. The second player's strategy is simple: if the opponent says x numbers, they say 4 − x numbers. In this way the total grows by 4 at the end of each round, and the second player always completes to 4, 8, 12, 16, 20. In the end the first player is forced to say 21.
In "Don't Say 16" the rules are the same, but whoever says 16 loses. The key numbers are found by the same method:
- Base state: c = 15 is L; the player to move must say 16.
- 14, 13, 12: 15 can be reached → W. c = 11: 12, 13, 14 are all W → L.
- The pattern continues in steps of 4: the L states are 15, 11, 7, 3.
- c = 0: one can say 1, 2, or 3, and 3 is an L state. The starting state is W.
The first player wins: they say "1, 2, 3" and leave the opponent at 3. Then each time they complete to a multiple of 4 plus 3 (7, 11, 15). When the target number changes, the key numbers shift and the winning player can change. The general rule: if whoever says H loses, the L states are the numbers going back from H − 1 in steps of 4.
2.7.5Nim and Bouton's theorem
In Nim there are several heaps of tokens. The player to move takes at least one token from a single heap (all of it, if they wish). Whoever takes the last token wins. Small positions can be labeled by hand as in Figure 2.18; but as the number and size of heaps grow, the number of positions increases rapidly. In 1901 Charles Bouton found a rule that labels all Nim positions with a single computation.
The bitwise XOR of the heap sizes is called the nim-sum and is written with ⊕. XOR is binary addition without carries: in each bit column the result is 1 if the number of 1s is odd and 0 if it is even.
3 ⊕ 4 ⊕ 5 is computed column by column (Figure 2.22):
- Binary notation: 3 = 011, 4 = 100, 5 = 101 (columns of 4s, 2s, 1s).
- The 4s column: 0, 1, 1 → two 1s, even → 0.
- The 2s column: 1, 0, 0 → one 1, odd → 1.
- The 1s column: 1, 0, 1 → two 1s, even → 0.
- The result is 010 = 2.
A Nim position is a losing position (P) if and only if its nim-sum is 0.
We check the two rules for P- and N-positions (Definition 2.15). The final position (all heaps empty) has nim-sum 0 and is P; this gives the base case.
(1) Every move from a position with nim-sum 0 goes to a position whose nim-sum is not 0. A move changes a single heap: it reduces its size h to a smaller h′. Since h′ ≠ h, the two differ in at least one bit. In that bit column the number of 1s increases or decreases by one, that is, its parity changes. In the previous sum that bit was 0; now it becomes 1. The sum is no longer 0.
(2) From a position with nim-sum x ≠ 0 there is a move to a position with nim-sum 0. Take the leftmost 1 bit of x. The number of 1s in that bit column is odd, so at least one heap of size h has that bit equal to 1. Reduce this heap to h ⊕ x. h ⊕ x is smaller than h: that bit turns from 1 to 0 and the bits further left do not change (because the bits of x to the left of that bit are 0). The move is legal. The new sum is x ⊕ h ⊕ (h ⊕ x) = 0, because any number XORed with itself gives 0.
The positions with sum 0 satisfy the two rules of P, and those with nonzero sum satisfy the two rules of N. Since the labels are determined uniquely from the end backward, the P-positions are exactly those with nim-sum 0. □
The theorem also gives a strategy. In a position whose nim-sum is not 0, the player to move makes the move that makes the sum 0. With each of their moves the opponent, from a position with sum 0, breaks the sum; the player makes it 0 again each time. When all heaps are empty the sum is 0, and it is the player who leaves this position to the opponent, that is, who takes the last token. Many impartial games, in which both players have the same moves, can also be solved by converting them to Nim; the Sprague–Grundy theory is the general way of making this conversion.
2.7.6Code trace: the winning move in Nim
The code below computes the nim-sum in a Nim position and finds the move that makes the sum 0.
heaps = [3, 4, 5]
x = 0
for h in heaps:
x ^= h # nim-sum (XOR)
for i, h in enumerate(heaps):
if h ^ x < h: # can it shrink?
heaps[i] = h ^ x
print("heap", i, ":", h, "->", h ^ x)
break
print(heaps)The first loop starts x at 0 and adds each heap with ^= (XOR assignment). The second loop tries the heaps in order: if h ^ x < h, the heap can be reduced to h ^ x and this move makes the sum 0. When the first suitable heap is found, the move is made and the loop stops with break.
| Step | Operation | Binary | Result |
|---|---|---|---|
| 1 | x = 0 XOR 3 | 000 ⊕ 011 = 011 | x = 3 |
| 2 | x = 3 XOR 4 | 011 ⊕ 100 = 111 | x = 7 |
| 3 | x = 7 XOR 5 | 111 ⊕ 101 = 010 | x = 2 |
| 4 | heap 0: 3 XOR 2 | 011 ⊕ 010 = 001 | 1 < 3 → suitable |
| 5 | heap 0: 3 → 1 | — | [1, 4, 5], sum 0 |
The code prints "heap 0 : 3 -> 1" and [1, 4, 5]: two tokens are taken from the first heap. The choice of this heap is no accident. The leftmost 1 bit of x = 2 is the 2s bit, and 3 (011) also has this bit equal to 1. What happens if the other heaps are tried? 4 ⊕ 2 = 6 and 5 ⊕ 2 = 7 are larger than the heaps; since adding tokens is forbidden, these moves cannot be made. In the new position [1, 4, 5], 1 ⊕ 4 ⊕ 5 = 0 (Figure 2.23).
Let the position be [2, 5, 6], with us to move.
- Nim-sum: 2 ⊕ 5 = 010 ⊕ 101 = 111 = 7; 7 ⊕ 6 = 111 ⊕ 110 = 001 = 1. The sum is 1 ≠ 0: it is a winning position.
- The heaps are tried: 2 ⊕ 1 = 3 (larger than 2, not allowed); 5 ⊕ 1 = 4 (smaller than 5, allowed); 6 ⊕ 1 = 7 (larger than 6, not allowed).
- The only winning move: reduce the second heap from 5 to 4. The new position [2, 4, 6]: 2 ⊕ 4 ⊕ 6 = 010 ⊕ 100 ⊕ 110 = 000.
The only 1 bit of x = 1 is the 1s bit; the only heap with this bit equal to 1 is 5 (101). So there is exactly one winning move.
2.7.7Solved games
Apart from the 2/3 game and the Prisoner's Dilemma, the interactive games of this chapter are two-player, sequential, perfect-information games without chance. By Zermelo's theorem all of them can in principle be solved by backward induction; but the tree is often very large. To "solve" a game means to find the outcome under perfect play (first player wins, second player wins, or draw). Table 2.19 summarizes the known results.
| Game | Outcome under perfect play | How? |
|---|---|---|
| Tic-tac-toe | Draw | The whole tree is searched (minimax) |
| Nim | The player to move wins if the nim-sum ≠ 0 | Bouton's XOR rule (1901) |
| Don't Say 21 | The second player wins | Backward labeling; key numbers are multiples of 4 |
| Connect Four | The first player wins | Solved by computer search in 1988 |
| Hex | The first player wins (no draws) | Strategy stealing; the winning strategy is unknown on large boards |
| Othello (8×8) | Draw | By computer search in 2023 |
| Checkers | Draw | Solved in 2007 (Schaeffer et al., 2007) |
| Chess | Determinate but unknown | Zermelo; tree ≈ 10120 games |
In games such as Mancala, looking a few steps ahead in the move tree gives a player a significant advantage. In Fox and Geese the roles are asymmetric: on one side there is a single fox, on the other many geese; even so, information is perfect. Nine Men's Morris is also a classic strategy game of perfect information. The same principle holds in all of these games: if the game is finite and information is perfect, the outcome is in theory determined; the practical difficulty is the size of the tree.
2.8Sequential games and backward induction
The "from the end backward" idea used in combinatorial games also applies to sequential games whose payoffs are not zero-sum. In these games a new problem arises: some Nash equilibria rest on threats that will never be carried out. The concept of subgame perfect equilibrium solves this problem, and backward induction is the algorithm that finds this equilibrium.
2.8.1Subgames and subgame perfect equilibrium
A subgame is the part of a game tree that starts at a single decision node, contains everything below that node, and does not split any information set.
A subgame perfect equilibrium (SPE) is a strategy profile that forms a Nash equilibrium in every subgame (Selten, 1965).
The condition "does not split an information set" in the definition of a subgame says that the part starting at a node must not disturb what the player knows at that point. If one node of an information set lies inside the part and another outside, the part is not a subgame. In games of perfect information every information set is a single node, so every decision node starts a subgame. The whole game is also a subgame of itself.
Why is a new equilibrium concept needed? The ordinary Nash equilibrium does not look at what happens at nodes of the game that are never reached. A player can frighten the other with a threat they would never actually carry out; since the threat is never tested, the Nash equilibrium cannot catch it. Such a threat is called a non-credible threat. SPE requires players to make the best choice in every subgame, that is, at every node including those not reached. For this reason it rules out non-credible threats.
In finite games of perfect information the SPE is found by backward induction (Kuhn/Zermelo). The algorithm consists of four steps:
- Find the last decision nodes, those connected only to leaves.
- Choose the best branch of the player who decides there: only that player's payoff is compared.
- Replace the node with the payoff vector of the chosen leaf; the node is now a leaf.
- Repeat these steps until the root is reached.
The algorithm processes each node exactly once; its running time is therefore proportional to the size of the tree. If the tree is small the solution is fast. The difficulty in chess lies not in the algorithm but in the size of the tree.
2.8.2Market entry: the non-credible threat
The market entry game (Figure 2.9) is written here with short names: E (the Entrant) chooses first; I (the Incumbent) decides only if E enters.
First the normal form of the game is written. E has two strategies: Enter, Stay out. I has a single decision node and two strategies: Fight, Share (that is, "if E enters I fight" and "if E enters I share"). If E stays out, I's strategy does not affect the outcome.
| E \ I | Fight | Share |
|---|---|---|
| Enter | (−1, −1) | (1, 1) |
| Stay out | (0, 2) | (0, 2) |
The best responses are marked in Table 2.20:
- If I says Fight, Enter gives E −1 and Stay out gives 0 → Stay out. If I says Share, Enter gives E 1 and Stay out gives 0 → Enter.
- If E says Enter, Fight gives I −1 and Share gives 1 → Share. If E says Stay out, both of I's strategies give 2 → both are best responses.
- The cells with two marks: (Enter, Share) and (Stay out, Fight).
The game has two pure Nash equilibria. In the second, I says "if you enter, I will fight", and E, believing this threat, stays out. The threat is never tested; I's payoff is 2 and deviating gains nothing.
Backward induction rules out one of these two equilibria:
- Last node, I: Fight → −1, Share → 1. I chooses Share. The value of I's node is (1, 1).
- Root, E: Stay out → 0, Enter → 1 (knowing that I will share). E chooses Enter.
- SPE: (Enter, Share); the outcome is (1, 1).
(Stay out, Fight) is a Nash equilibrium, but it is not subgame perfect. In the subgame starting at I's node, that is, after E has entered, fighting gives I −1 and sharing gives 1. In this subgame Fight is not a best response. The threat "if you enter, I will fight" is not credible: the moment E enters, I's interest is to share. A rational E foresees this and enters, ignoring the threat.
2.8.3The investment game step by step
A three-stage game shows how backward induction works over several steps. Ayşe (A) invests or does not. If she invests, the entrepreneur Bora (B) either shares the profit or runs off with the money. If Bora runs off, Ayşe either sues or drops the matter. The leaves show the payoffs (Ayşe, Bora): Don't invest (2, 0); Share (3, 3); Run and Sue (1, 1); Run and Drop (0, 4).
- Last decision node (Ayşe, after Bora has run off): Sue 1, Drop 0. Since 1 > 0, Ayşe sues. The value of the node is (1, 1).
- Bora's node: Bora knows that if he runs off he will be sued. Share 3, Run 1 (from the value of the lawsuit node). Since 3 > 1, Bora shares. The value of the node is (3, 3).
- Root (Ayşe): Invest 3, Don't invest 2. Since 3 > 2, Ayşe invests.
Subgame perfect equilibrium: Ayşe's strategy is (Invest, Sue), Bora's strategy is Share; the outcome is (3, 3). Ayşe's strategy also contains the "Sue" component, because a strategy also says what to do at nodes that are not reached. The reason Bora shares is exactly this unreached choice.
Now let the lawsuit be expensive: Ayşe, if she sues, gets −1 instead of 1. The tree is the same; only one leaf has changed, from (1, 1) to (−1, 1). Backward induction is carried out again from the start.
- Last node: Drop 0, Sue −1. Since 0 > −1, Ayşe drops. The value of the node is (0, 4).
- Bora: Run 4, Share 3. Since 4 > 3, Bora runs. The value of the node is (0, 4).
- Root: Invest 0, Don't invest 2. Since 2 > 0, Ayşe does not invest.
The outcome (2, 0) is worse for both than (3, 3). The change of a single leaf has, in a chain, changed the decision at every node.
Figure 2.26 points to a subtle matter. If Ayşe announces the plan "if you run off, I will sue", the profile (Ayşe: Invest, Sue; Bora: Share) is still a Nash equilibrium. In this profile Ayşe gets 3 and Bora gets 3. If Bora runs off he is sued and gets 1; he does not deviate. If Ayşe does not invest she gets 2; she does not deviate. Since the lawsuit node is never reached, Ayşe's choice there does not affect her payoff. But the threat is not credible: if Bora really runs off, Ayşe gets −1 by suing and 0 by dropping, and she drops. Bora knows this. This profile is not a subgame perfect equilibrium.
The lesson here is that making promises is not enough; carrying out the threat must be profitable at that moment. There are ways for Ayşe to make suing profitable: agreeing in advance with a lawyer on a fixed fee, or taking collateral from Bora. Measures of this kind change the payoffs of the game and make the threat credible.
2.8.4Code trace: solve()
Backward induction can be written as a short recursive function. The tree is represented with nested lists: each decision node has the form [name, player, branches]; branches is a list of (move, child) pairs. The leaves are payoff tuples (tuple). Players are indexed 0 and 1: player 1 is index 0, player 2 is index 1.
def solve(d):
if isinstance(d, tuple): # leaf: payoffs
return d
name, player, branches = d
best = None
for move, child in branches:
v = solve(child)
if best is None or v[player] > best[player]:
best, choice = v, move
print(name, choice)
return best
T = ['root', 0, [('Left', ['x', 1, [('a', (3, 1)), ('b', (1, 2))]]),
('Right', ['y', 1, [('c', (2, 1)), ('d', (0, 0))]])]]
print(solve(T))The function works as follows:
- If the node is a tuple it is a leaf, and the payoff vector is returned as is.
- Otherwise the node is unpacked into three parts:
name, the decidingplayer, andbranches. - For each branch the value of the child is computed recursively:
v = solve(child). - In the comparison only the deciding player's payoff is used:
v[player] > best[player]. Because strict greater-than (>) is used, the first branch seen is kept in a tie. - The node's choice is printed and the payoff vector of the chosen branch is returned; the parent node uses this vector like a leaf.
solve(T) and its result. Player 1 chooses at the root, player 2 at nodes x and y; b is chosen at x, c at y, and Right at the root. The outcome is (2, 1).| Step | Node (player) | Branch and value v | Comparison | best, choice |
|---|---|---|---|---|
| 1 | x (1) | a → (3, 1) | no best yet | (3, 1), a |
| 2 | x (1) | b → (1, 2) | v[1] = 2 > 1 | (1, 2), b → "x b" |
| 3 | root (0) | Left → (1, 2) | no best yet | (1, 2), Left |
| 4 | y (1) | c → (2, 1) | no best yet | (2, 1), c |
| 5 | y (1) | d → (0, 0) | v[1] = 0 > 1? no | (2, 1), c → "y c" |
| 6 | root (0) | Right → (2, 1) | v[0] = 2 > 1 | (2, 1), Right → "root Right" |
The program prints "x b", "y c", "root Right", and (2, 1) in turn. Step 2 is important: at x player 2 looks at their own payoff and chooses b (2 > 1). In this way player 1's favorite leaf (3, 1) becomes unreachable. At the root, player 1 compares the true value of Left, (1, 2), with the true value of Right, (2, 1), and chooses Right. The SPE is (Right; b at x, c at y). The b at the unreached node x is also part of the strategy; it is the reason player 1 rejects Left.
2.8.5The Centipede game
The Centipede game was described by Robert Rosenthal in 1981 (Rosenthal, 1981). Two players decide in turn. At each node the deciding player either says "Take" and the current split is carried out, or says "Pass" and the total grows. The total payoff grows as 1 → 2 → 4 → 6 and is 6 at the end. But a player who passes receives less if the opponent takes at the next step.
Reading the leaves in order shows the tension of the game. If player 1 takes at the first node, the outcome is (1, 0). If they pass, player 2 can take at the second node and get (0, 2): for player 2, 2 > 0. If player 2 passes, player 1 can take at the third node with (3, 1). At the fourth node player 2 can take with (2, 4) or pass and go to (3, 3).
Backward induction starts from the last node. Table 2.22 shows the result of the four steps.
| Node | Decides | Take | Value of passing | Decision | Node value |
|---|---|---|---|---|---|
| 4 | Player 2 | (2, 4) | (3, 3) | Take | (2, 4) |
| 3 | Player 1 | (3, 1) | (2, 4) | Take | (3, 1) |
| 2 | Player 2 | (0, 2) | (3, 1) | Take | (0, 2) |
| 1 | Player 1 | (1, 0) | (0, 2) | Take | (1, 0) |
- Node 4, Player 2: Take 4, Pass 3 (the value of passing is (3, 3)). 4 > 3 ⇒ Take; the node's value is (2, 4).
- Node 3, Player 1: Take 3, Pass 2 (the value of passing is (2, 4)). 3 > 2 ⇒ Take; the node's value is (3, 1).
- Node 2, Player 2: Take 2, Pass 1 (the value of passing is (3, 1)). 2 > 1 ⇒ Take; the node's value is (0, 2).
- Node 1, Player 1: Take 1, Pass 0 (the value of passing is (0, 2)). 1 > 0 ⇒ Take; the node's value is (1, 0).
Subgame perfect equilibrium: each player says Take at every node. The game ends at the first move with (1, 0), although (3, 3) was better for both.
Let the rightmost payoff be (5, 5) instead of (3, 3). Backward induction is carried out again:
- Node 4, Player 2: Pass 5 > Take 4 ⇒ Pass; value (5, 5).
- Node 3, Player 1: Pass 5 > Take 3 ⇒ Pass; value (5, 5).
- Node 2, Player 2: Pass 5 > Take 2 ⇒ Pass; value (5, 5).
- Node 1, Player 1: Pass 5 > Take 1 ⇒ Pass; value (5, 5).
Everyone passes and the outcome is (5, 5). The key to solving the game is the last node: the moment player 2 there prefers not to take, the whole chain reverses.
2.8.6Centipede: theory and experiment
Theory. In the SPE each player says Take at every node and the game ends at the first move with (1, 0). There is also a stronger result: in any Nash equilibrium of the game the outcome is the same. The reason is this. If there were a Nash equilibrium in which the game ended after node 1, the player deciding at the node just before where the game ends would want to deviate. For example, if the game ended at node 3 with (3, 1), player 2 at node 2 could have taken and got 2, while passing gives 1. If the game ran to the end with (3, 3), player 2 at node 4 could take and get 4. In every case there is a profitable unilateral deviation; so in every Nash equilibrium the game ends at the first node.
Inefficiency. (3, 3) is better than (1, 0) for both players: the SPE outcome is not Pareto optimal. The loss grows with the number of nodes; in a centipede with a hundred nodes the players sacrifice a large total at the first step.
Experiment. In the laboratory most players do not take at the first node; they pass for a few rounds (McKelvey and Palfrey, 1992). The reason is that backward induction requires rationality to be common knowledge and a long chain of reasoning. Even a small chance that the opponent is somewhat "well-intentioned" makes passing profitable: if the opponent passes one more round, the player can take from a larger pot.
The Centipede game shares its logic with the finitely repeated Prisoner's Dilemma: looking backward from the last round, cooperation unravels. With an infinite horizon, however, cooperation can remain in equilibrium (Section 2.8.8).
2.8.7The Ultimatum game
The Ultimatum game is the simplest model of bargaining (Güth, Schmittberger, and Schwarze, 1982). Ayşe offers Bora x TL out of 10 TL; x is a whole number of TL (0, 1, …, 10). If Bora accepts, the split is (10 − x, x). If he rejects, both get 0.
- Bora's nodes. There is a separate node for each x (11 nodes). If x > 0, accepting gives x and rejecting gives 0; since x > 0, Bora accepts. At x = 0 both accepting and rejecting give 0; Bora is indifferent.
- Ayşe's decision (if Bora rejects 0). Ayşe knows that Bora will accept every positive offer. The positive offer that maximizes her share 10 − x is x = 1. The SPE outcome is (9, 1).
- Ayşe's decision (if Bora accepts 0 too). Ayşe offers x = 0 and gets 10. This is also an SPE; the outcome is (10, 0).
Bora's strategy contains a decision at each of the 11 nodes. Bora therefore has 211 = 2048 strategies.
There is a non-credible threat in this game too. If Bora says "I will reject anything below 4 TL" and Ayşe believes it, Ayşe offers 4. The profile (Ayşe: offer 4; Bora: accept 4 and above, reject below) is a Nash equilibrium: if Ayşe offers less she gets 0, if she offers more she keeps less; Bora's choice at the node actually reached (accept) is best. But when 1 TL is offered, rejecting gives Bora 0 < 1; the threat is not credible and the profile is not subgame perfect.
| Offer (share of the total) | Theory (money only) | In experiments |
|---|---|---|
| Most common offer | the smallest unit | 40–50% |
| Offers below 20% | accepted | about half are rejected |
The experimental results are very different from the theory. Most proposers offer 40–50% of the total; about half of the offers below 20% are rejected. This result should not be read as "players cannot do backward induction". Rejection shows that a concern for fairness enters the utility function: rejecting an unfair offer may be worth more to someone than 1 TL. Proposers foresee this and behave generously (Camerer, 2003). This is an example of the principle in Section 2.1.5: rational does not mean selfish.
2.8.8The infinitely repeated Prisoner's Dilemma
Is cooperation possible if the Prisoner's Dilemma is played repeatedly between the same two players? The answer depends on whether it is known when the game will end. The same one-shot game is repeated; what determines the outcome is the horizon.
Grim trigger strategy: Play Silent in the first round; if the opponent betrays even once, play Betray forever after.
Finite, known horizon. Let the game last 10 rounds, and let this be known. In the last round there is no future and hence no punishment: round 10 is a one-shot Prisoner's Dilemma, and there Betray is dominant. In round 9 the players know what will happen in round 10: whatever they do, both will betray in round 10. So the choice in round 9 has no future either, and round 9 too is like a one-shot game: Betray. Backward induction carries this all the way to the first round. Betray is played in every round; as in the Centipede game, cooperation unravels from the end backward.
Infinite horizon. After each round let the game continue for one more round with probability δ. The game has no known last round. The gain from today's betrayal is weighed against the loss from the permanent punishment in the future. If δ is large enough, that is, if the players are patient or the probability that the game continues is high, deviating is not profitable and cooperation remains in equilibrium.
With Sam and John's payoffs (Table 2.8), let both players play grim trigger. We compute whether a deviation by Sam is profitable.
- Complying. (Silent, Silent) is played every round and Sam gets −1 every round. Total: −1 − δ − δ2 − … = −1 / (1 − δ) (by the formula of Example 2.11).
- Deviating. Sam betrays in one round and gets 0 that round (John is silent). In every later round John betrays; Sam's best reply is also to betray, and he gets −2 every round. Total: 0 + δ(−2) + δ2(−2) + … = −2δ / (1 − δ).
- Comparison. Complying is no worse than deviating if: −1 / (1 − δ) ≥ −2δ / (1 − δ). Multiplying both sides by (1 − δ) > 0: −1 ≥ −2δ, that is, δ ≥ 1/2.
If the probability that the game lasts one more round is at least 1/2, betrayal is unprofitable and two grim trigger strategies together sustain cooperation. For example, at δ = 0.9 complying gives −10 and deviating gives −18.
The punishment is credible, because (Betray, Betray) is an equilibrium of the one-shot game. In the punishment phase no player can gain by staying silent alone: while the opponent betrays, staying silent gives −3 and betraying gives −2. So two grim trigger strategies together form a subgame perfect equilibrium: nobody wants to deviate either in the cooperation phase (when δ ≥ 1/2) or in the punishment phase.
2.8.9Common mistakes in sequential games
- Starting at the root. The first move depends on the response to later moves; the solution always starts from the last decision nodes.
- Looking at the wrong player's payoff. At each node only the number of the player who decides there is compared. In the investment game, at Bora's node the second number is examined.
- Mistaking a strategy for a path. A strategy contains a choice for every node, including unreached ones: Ayşe's strategy is (Invest, Sue), not just "Invest".
- Thinking Nash = subgame perfect. Every subgame perfect equilibrium is a Nash equilibrium; the converse is false. There are Nash equilibria that contain non-credible threats (market entry, ultimatum).
- Solving a simultaneous game as sequential. If moves are not observed (Prisoner's Dilemma), the tree has an information set; backward induction does not apply directly, and the matrix is solved instead.
- Mistaking a promise for commitment. Saying "I will sue" is not enough; carrying out the threat must be profitable at that moment or be bound in advance (contract, collateral).
2.9Minimax and alpha-beta pruning
The definition of the minimax value takes a few lines: at a leaf the outcome of the game, at a MAX node the largest of the children, at a MIN node the smallest. This definition is easily applied by hand on small trees and by computer on tic-tac-toe. The difficulty lies not in the definition but in the size of the tree. Looking one move further ahead multiplies the number of positions to examine by the branching factor. So the strength of game-playing programs depends on their answers to three questions: which branches can be skipped without being read at all, in what order should moves be tried, and, if the tree cannot be descended to the leaves, what value should be given to the positions where it is cut short? Alpha-beta pruning answers the first question, move ordering the second, and the evaluation function with depth-limited search the third.
2.9.1The game tree and its size
In the extensive form a game is written as a tree. In two-player, zero-sum games of perfect information only one player decides at each level of this tree, and a single number suffices to write the payoffs. The vocabulary used for such games is collected in the definition below.
In the game tree of a two-player, zero-sum game of perfect information, each node is a position: the state of the board and whose turn it is. Each edge is a move. The root is the current position; a leaf is a position where the game has ended and has no children. The player to move at the root is called MAX (▲) and the opponent MIN (▽). MAX wants to increase the value and MIN to decrease it. The levels alternate between MAX and MIN; going down one level is a ply, that is, a single move by one player.
Each leaf has a utility, and this number is written from MAX's point of view. Since the game is zero-sum, MIN's utility is its negative.
Figure 2.31 shows how the tree grows. At the root there are 7 empty squares, so X has 7 moves. After each move 6 empty squares remain, so O has 6 replies. After only two plies there are 7 · 6 = 42 positions below the root. The same position can also be reached by different move orders: X playing top-left first and bottom-right second gives the same board as bottom-right first and top-left second. In the tree this position appears as two separate nodes; the tree is a tree of game histories, not of positions.
In tic-tac-toe the utility takes three values: +1 if X wins, 0 for a draw, −1 if O wins (Figure 2.32). O's utility is the negative of X's: uO = −uX. So writing a single number at each leaf suffices. The values of the interior nodes are not known at the start; minimax computes them from the leaves. A judgment such as "the center is a good square" also becomes a number only once the tree is searched down to the leaves: the value of the center is the utility of the leaf reached by best play from both sides after playing in the center.
Two numbers determine the size of the tree.
The branching factor b is the number of legal moves in a position; since it changes during the game, its average or its maximum is often used. The depth d is the length of the game in plies. If every interior node has b children, there are bd leaves at depth d; the size of the tree is roughly bd.
This number is exponential: when the depth increases by one, the work is multiplied by b. In chess b ≈ 35, so looking one more ply ahead multiplies the work by about 35, and looking one more full move (two plies) ahead multiplies it by about 1,225. Table 2.24 compares the trees of four games.
| Game | b | d (plies) | Size of the tree or number of positions |
|---|---|---|---|
| Tic-tac-toe | ≤ 9 | ≤ 9 | 9! = 362,880 upper bound; in reality 255,168 games, 549,946 nodes |
| Connect Four | ≤ 7 | ≤ 42 | 4,531,985,219,092 ≈ 4.5 · 1012 legal positions (Tromp) |
| Chess | ≈ 35 | ≈ 80 | 3580 ≈ 10123; Shannon's (1950) rough estimate ≈ 10120 games |
| Go (19×19) | ≈ 250 | ≈ 150 | ≈ 2.1 · 10170 legal positions (Tromp, 2016) |
The size of the tic-tac-toe tree can be expressed with four different numbers. The difference among the four lies in what is counted in the tree.
- Upper bound. If no game ended early there would be 9 options on the first move, 8 on the second, …, 1 on the last: 9 · 8 · … · 1 = 9! = 362,880 distinct games.
- The actual number of games. Some games end early when a line of three is completed; those games have no continuation. A program that counts all the games finds 255,168 distinct games. Each game is a leaf of the tree.
- Number of nodes. A full minimax search from the empty board visits not only the leaves but every interior node on the way. The number of nodes visited, including the root, is 549,946; of these 255,168 are leaves and the remaining 294,778 are interior nodes.
- Number of distinct positions. Because the same board is reached by different orders, the 549,946 nodes in the tree correspond to only 5,478 distinct positions.
The roughly 100-fold difference between the last two numbers shows that the same positions are searched over and over. This repetition can be eliminated with a memory called a transposition table.
The whole tic-tac-toe tree is searched in under a second. Even in Connect Four, a full search has been possible only with game-specific knowledge and very strong programs. In chess and Go, searching the whole tree is out of the question; the search is stopped at a certain depth and the value of the position there is estimated.
2.9.2The minimax value and a worked solution
The minimax value is the utility MAX will receive at the end of the game, assuming both sides play their best. The definition ties the value of a position to the values of its children; it is therefore recursive.
The minimax value of a position s is defined as follows:
minimax(s) =
utility(s) if s is terminal
max minimax(result(s, a)) if MAX to move
a
min minimax(result(s, a)) if MIN to move
aHere a ranges over the legal moves in s, and result(s, a) is the position after move a. At the root, MAX chooses the move that goes to the child with the largest value.
The search that applies the definition proceeds depth-first: it descends from the root to a leaf, reads the leaf's utility, returns to the node above, and descends into that node's other children. Values rise from the leaves to the root in this order. The value of a node becomes final only when all its children are finished.
The cost of the search is measured in two items. Time: since each node is visited once, O(bd). Memory: only the path from the root to the current node and, along this path, which children of each node have been tried are kept at any moment; this comes to O(b · d). Because memory is this small, the limit of minimax is never memory but time.
In the tree of Figure 2.33, the leaves from left to right are E = [5, 6], F = [7, 4], G = [3, 2], H = [8, 9], I = [4, 1], J = [2, 7]. The value of the root and MAX's move are found from the bottom up, level by level:
- Third level (MAX). Each MAX node takes the largest of its leaves: E = max(5, 6) = 6, F = max(7, 4) = 7, G = max(3, 2) = 3, H = max(8, 9) = 9, I = max(4, 1) = 4, J = max(2, 7) = 7.
- Second level (MIN). Each MIN node takes the smallest of its children: B = min(E, F) = min(6, 7) = 6, C = min(G, H) = min(3, 9) = 3, D = min(I, J) = min(4, 7) = 4.
- Root (MAX). A = max(B, C, D) = max(6, 3, 4) = 6.
The value of the root is 6, and MAX chooses the move to B. The largest leaf in the tree (9) lies below H, but MAX cannot reach it: at C, MIN makes the choice and picks G, that is, 3. The 7 below B is also an unreachable number; at B, MIN chooses E instead of F and holds MAX to 6. The value 6 is the best outcome MAX can guarantee whatever the opponent does.
Minimax is the special case of backward induction for two-player, zero-sum games. In a general sequential game, the player to move at each node maximizes their own payoff. In a zero-sum game the second player's payoff is the negative of the first's, so "the second player maximizes their own payoff" and "minimizes the first player's payoff" are the same thing. This is why the single number in the tree is maximized at MAX levels and minimized at MIN levels.
This also links minimax to the maximin and minimax criteria defined for matrix games (Example 2.7). Maximin is the best value MAX can guarantee alone: maxs mint u(s, t). Minimax is the lowest value to which MIN can hold MAX: mint maxs u(s, t). In simultaneous games such as Matching Pennies these two numbers can differ under pure strategies. In a finite game of perfect information they are always equal, and pure strategies suffice for the equality (Zermelo, 1913; Kuhn, 1953). The minimax value computed in the tree is this common value. The reason is that in perfect information each player sees the opponent's earlier moves when deciding: there is no "what did the opponent choose?" uncertainty of the simultaneous game.
The minimax move is found assuming the opponent plays without error. The guarantees and limits of this assumption are as follows:
- What it guarantees: MAX gets at least the minimax value whatever the opponent does. If the opponent errs, MAX can get more; never less. So the minimax move is the move that maximizes the worst-case payoff.
- What it does not guarantee: It does not find the move that earns the most against a weak opponent. It does not distinguish between two moves of equal value, one of which sets a trap for the opponent and the other does not; it sees both with the same number.
- When there is chance: In games with dice such as backgammon, chance nodes are added to the tree. At a chance node one takes neither the largest nor the smallest value but the probability-weighted average (expectiminimax). Pruning becomes harder in such trees, because to bound an average one has to see most of the children.
2.9.3Code trace: the minimax function
The code below applies the definition to a smaller tree. The root A has three MIN children: B = [3, 5], C = [2, 9], D = [6, 4].
from math import inf
T = {"A": ["B", "C", "D"], "B": [3, 5],
"C": [2, 9], "D": [6, 4]}
def minimax(n, maxi):
if isinstance(n, int): # leaf
return n
best = -inf if maxi else inf
for c in T[n]:
v = minimax(c, not maxi)
if maxi:
best = max(best, v)
else:
best = min(best, v)
return best
print(minimax("A", True))The structure of the code is as follows:
- The dictionary
Tholds the children of each interior node in order. The leaves are integers; whether a node is a leaf is decided by the testisinstance(n, int), and the leaf's utility is returned at once. beststarts at-infat a MAX node andinfat a MIN node. The infinities mean "no child seen yet": whatever the value of the first child, it is larger than −∞ for MAX and smaller than +∞ for MIN, and replacesbest.- The loop tries the children in the order of
T. At a child it is the other player's turn; this is the reason the recursive call is made withnot maxi. - A MAX node updates with
max, a MIN node withmin. When the loop ends, the node's final value is returned.
| Step | Stack | Event | best |
|---|---|---|---|
| 1 | A | root A (MAX) is opened | −∞ |
| 2 | A ▸ B | B (MIN) is opened | +∞ |
| 3 | A ▸ B | leaf 3: min(+∞, 3) | 3 |
| 4 | A ▸ B | leaf 5: min(3, 5); B finishes, returns 3 | 3 |
| 5 | A | B = 3: max(−∞, 3) | 3 |
| 6 | A ▸ C | C is opened; leaves 2 and 9: min(+∞, 2) = 2, min(2, 9) = 2 | 2 |
| 7 | A | C = 2: max(3, 2) | 3 |
| 8 | A ▸ D | D is opened; leaves 6 and 4: min(+∞, 6) = 6, min(6, 4) = 4 | 4 |
| 9 | A | D = 4: max(3, 4); A finishes | 4 |
The program prints 4. Two points in the trace are instructive. First, the root's best rises step by step from 3 to 4: A's value is not final until the last child D is finished. Second, reading C's second leaf, 9, is unnecessary. Once C's first leaf 2 has been seen, C's value will be at most 2, while A has already been guaranteed 3 from B. C will not be chosen whatever 9 is. Minimax does not know this and reads all six leaves. Alpha-beta pruning skips exactly this kind of reading.
2.9.4Nim: minimax, P- and N-positions, and the XOR rule
In Nim, positions are labeled P and N (Definition 2.15): in an N-position the player to move wins, in a P-position the previous player wins. These labels are another way of writing the minimax value. To see this, write the value not from MAX's but from the player to move's point of view: +1 if the player to move wins, −1 if they lose. After a move the turn passes to the opponent, so the child's value is from the opponent's point of view and is read with its sign flipped:
value(s) = −1 if there is no move
value(s) = max −value(result(s, a)) otherwise
aThis is the writing of minimax as a single function and is called negamax. Choosing the smallest at a MIN node is the same as choosing the largest of the negated values; negamax merges the two separate branches with this observation.
The formula repeats the P and N rules word for word. A position with no move is −1, that is, P. A position's value is +1 if and only if at least one child's value is −1; that is, if at least one move goes to a P-position the position is N. If all children are +1 the value is −1; that is, if every move goes to an N-position the position is P. Consequently the correspondence N ⇔ +1 and P ⇔ −1 holds.
| Position | Value to the player to move | Type |
|---|---|---|
| (0, 0) | −1 | P |
| (1, 0) | +1 | N |
| (1, 1) | −1 | P |
| (2, 0) | +1 | N |
| (1, 2) | +1 | N |
| (2, 2) | −1 | P |
| (1, 2, 3) | −1 | P |
The value of the position Nim(1, 3) is found with negamax. There are four moves from the position: taking the single token from the first heap, giving (0, 3), or taking 1, 2, or 3 tokens from the second heap: (1, 2), (1, 1), (1, 0).
- (1, 1): both moves leave (0, 1) or (1, 0). From these one goes to (0, 0), and since (0, 0) = −1, (0, 1) = (1, 0) = +1. (1, 1) = max(−(+1), −(+1)) = −1: P.
- (1, 2) = +1, because it can go to (1, 1): −(−1) = +1. (0, 3) = +1, because one can take all three tokens at once and leave (0, 0). (1, 0) = +1.
- (1, 3) = max(−(0, 3), −(1, 2), −(1, 1), −(1, 0)) = max(−1, −1, +1, −1) = +1.
The position is N, and the only winning move is to take two tokens from the second heap, leaving (1, 1). The nim-sum is 1 ⊕ 3 = 2; the move that makes the sum 0 is 3 ⊕ 2 = 1, that is, reducing the second heap to 1. The two methods find the same move. The full tree contains 28 nodes.
By Bouton's theorem (Theorem 2.2), a Nim position is P if and only if its nim-sum is 0, and the winning move is the move that makes the sum 0. Minimax finds this without knowing any theory, by searching the whole tree. Table 2.27 compares the two methods on five positions.
| Position | XOR | Minimax's winning move | Move making XOR 0 | Full tree |
|---|---|---|---|---|
| (1, 2) | 3 | → (1, 1) | → (1, 1) | 12 nodes |
| (1, 3) | 2 | → (1, 1) | → (1, 1) | 28 nodes |
| (2, 3) | 1 | → (2, 2) | → (2, 2) | 86 nodes |
| (1, 2, 3) | 0 | none: P-position | none | 447 nodes |
| (3, 4, 5) | 2 | → (1, 4, 5) | → (1, 4, 5) | 1,038,768 nodes |
The two methods find the same move in every row; the difference is the cost. The tree of minimax grows exponentially with the number of tokens: a tree of 12 nodes for (1, 2) exceeds a million for (3, 4, 5), with 12 tokens in total. The XOR rule finishes with as many operations as there are heaps. When a game-specific theory is found there is no need to search; when there is no such theory, minimax is the general method that works on every game.
2.9.5Value scales and the depth penalty in tic-tac-toe
In tic-tac-toe the +1 / 0 / −1 scale gives the outcome of the game correctly, but it has a flaw: a fast win and a slow win get the same value. In the position of Figure 2.36 it is X's turn. If X plays the bottom-left square, X completes the left column and wins at once. If X plays the center, X creates two separate threats; O blocks one, X completes the other and wins two moves later. Both moves have the value +1.
When values are equal, the order in which squares are tried decides the choice: in a tie the program keeps the first square it found. If the center is tried first, the program passes up the ready win and prolongs the game. The result does not change, X still wins; but the game is needlessly prolonged, and in a program that is not flawless this leaves room for error. On the losing side the situation is worse: when all moves get −1, the program may choose the move that loses fastest and does not even leave the opponent a chance to err.
The solution is to build into the utility how long the game takes. Let d be the number of moves made since the root. The utility of the leaves is defined as follows:
X wins +(10 − d)
O wins −(10 − d)
draw 0This is called the depth penalty. The earlier a win comes, the larger the value: a win after one move from the root is +9, a win after three moves is +7, and since +9 > +7 the fast win is chosen. The later a loss comes, the larger the value: a loss after two moves is −8, a loss after four moves is −6, and since −6 > −8 the program delays the loss. Since a tic-tac-toe game lasts at most 9 moves, 10 − d is always positive; a win or a loss never crosses to the other side of a draw (0). The penalty changes not the type of the outcome but only the order among outcomes of the same type.
In the position of Figure 2.36, X is on the top left and middle left, O is on the top middle and bottom middle; it is X's turn. The values of the five empty squares are computed on both scales:
- Bottom left. The left column is completed and X wins one move from the root: +1 on the ±1 scale, 10 − 1 = +9 with the penalty.
- Center. X creates two threats: the left column (bottom left) and the diagonal (top left – center – bottom right). O blocks one, and X completes the other on the third move: +1, or 10 − 3 = +7.
- Top right, middle right, bottom right. O has a threat too: the top middle and bottom middle are O's, and the center is empty. If X plays on one of these three squares, O plays the center and completes the middle column. O wins two moves from the root: −1 on the ±1 scale, −(10 − 2) = −8 with the penalty.
On the ±1 scale the bottom left and the center are equal; with the depth penalty the bottom left clearly comes first. The program wins at once.
2.9.6Justifying a move and the value of the empty board
Minimax chooses by numbers alone; it does not say why the choice was made. The justification of the chosen move can be found by asking, in order, what the move accomplishes:
- Does the move complete a line of three? If so, the move wins.
- Does it block a line the opponent would complete in one move? If so, the move blocks.
- Does it create two separate winning threats at once? If so, the move forks: the opponent cannot block both threats.
- If none of these, the sign of the value gives the reason: if positive it forces a win, if zero it holds the draw, if negative it delays the loss.
The two middle positions of Figure 2.37 are examined in detail.
- Block. X is on the top left and top middle, O is at the center; it is O's turn. X has a threat on the top row: if the top right stays empty, X fills it and wins. O playing the top right closes the threat and keeps the value of the game at 0. Each of the other five squares gets +8: if O leaves the top right, X wins on the next move, that is, two moves from the root (10 − 2 = 8). Since O is MIN, it chooses the smallest of the values, 0.
- Fork. X is on the top left and center, O is on the top middle and bottom right; it is X's turn. The middle left and bottom left get +7, the other squares 0. If X plays the bottom left, two threats arise at once: in the left column (top left – middle left – bottom left) and on the diagonal (bottom left – center – top right). O can block only one; X completes the other on the third move: 10 − 3 = +7.
A good tic-tac-toe player can also be written with rules such as "first win, then block, then fork". Minimax knows none of these rules; it finds all of them itself by searching the tree. The rules are specific to the game and do not carry over to another game; the same minimax program, however, works on Connect Four too.
A full minimax search from the empty board gives all nine of X's first moves the value 0 (Figure 2.38). No opening forces a win: if both sides play without error, the game ends in a draw. Since all values are equal, it is not the values but the order in which squares are tried that determines which square X opens with. If the order center, corners, edges is used, the program opens in the center.
Holding the draw is not equally hard for the two sides. If X opens with a corner, only one of O's eight replies, the center, holds the draw; each of the other seven replies has the value +4 (Figure 2.37, the rightmost position). The value +4 shows that X wins six moves from the root, that is, with the fourth X stone: 10 − 6 = 4. An O that answers a corner opening with an edge or another corner inevitably falls into a fork as long as X plays correctly.
2.9.7Alpha-beta pruning: α, β, and the cutoff condition
In the code trace it was seen that C's second leaf was read needlessly. The same situation arises in every tree. In the tree of Figure 2.39, A (MAX) has been guaranteed 3 from its first child B: B = min(3, 12, 8) = 3. C's first leaf is 2. Since C is a MIN node, its value will be at most 2: MIN can find no reason to choose anything larger than 2. And A, holding 3, never chooses C, which gives at most 2. Whatever C's remaining leaves, 4 and 6, are, the value of the root does not change. These two leaves are never read; they are pruned.
In a small tree skipping two leaves may seem unimportant. But in real games a "leaf" is often itself a deep subtree: in chess a single pruned branch saves searching millions of positions. Alpha-beta pruning makes this observation systematic with two numbers.
During the search, on the path from the root to a node:
- α (alpha) is the best value MAX has already guaranteed on this path: MAX's lower bound. It starts at −∞ and grows only at MAX nodes: α = max(α, value).
- β (beta) is the best (smallest) value MIN has already guaranteed on the same path: MIN's upper bound. It starts at +∞ and shrinks only at MIN nodes: β = min(β, value).
Each node takes its interval [α, β] from its parent and passes it unchanged to its children; only the node's value returns to the parent. When α ≥ β at a node, the node's remaining children are not searched: the cutoff condition.
The meaning of the interval is this: if a node's value falls outside the interval [α, β], it does not affect the result at the root. If the value is smaller than α, a MAX node above will not choose this branch, since it has already guaranteed α from another branch. If the value is larger than β, a MIN node above will not choose this branch, since it has already guaranteed β from another branch. When the interval empties, that is, when α ≥ β, there is no region left in which the node's value could be "interesting".
In Figure 2.39 the interval arriving at C is [3, +∞]: α = 3 is the value A has guaranteed from B. When C reads its first leaf, β = min(+∞, 2) = 2. Now α = 3 ≥ β = 2 and C's remaining children are pruned. Pruning happens at a MAX node with the same condition. In the tree of Figure 2.40 the root is MIN and has been guaranteed 6 from B; at the root β = 6 and the interval [−∞, 6] arrives at C. C is a MAX node and its first leaf is 7: α = 7 ≥ β = 6. C gives at least 7; since the root, being MIN, has already guaranteed 6, it will not choose C. C's second leaf 4 is pruned.
| At a MIN node | At a MAX node | |
|---|---|---|
| Updated | β = min(β, value) | α = max(α, value) |
| Cutoff | when β ≤ α | when α ≥ β |
| Meaning | this node gives at most β; the MAX above already guarantees α | this node gives at least α; the MIN above already guarantees β |
| Returned | an upper bound (true value ≤ β) | a lower bound (true value ≥ α) |
Some books call the cutoff at a MIN node an α cutoff and the one at a MAX node a β cutoff: the naming follows which bound caused the cutoff. Both cutoffs are tested with the same inequality; a single line if a >= b therefore suffices in the code.
2.9.8Why pruning does not change the result
Alpha-beta finds the same root value and a best move as minimax (the same move if the move order is the same); it only reads fewer leaves. The truth of this claim is shown by knowing what the numbers returned by interior nodes mean. The number returned by a pruned node may not be the true minimax value; but compared with the true value, which side it stands on is known.
Let the true minimax value of a node be v, and let r be the value returned by alpha-beta when called with the interval [α, β] (α < β). Then:
- if α < v < β, then r = v (exact value);
- if v ≤ α, then r ≤ α (it is known only to be "bad enough");
- if v ≥ β, then r ≥ β (it is known only to be "good enough").
In particular, when the root is called with the interval (−∞, +∞), the returned value is the minimax value of the root.
The proof is by induction on the height of the node. At a leaf r = v and all three cases hold. Consider a MAX node (a MIN node is symmetric). The node tries its children in order and after each child updates α with the largest value returned so far.
As long as there is no cutoff, each child is called with the current interval [α', β] (α' ≥ α). By the induction hypothesis, if a child's true value is greater than α' and less than β, the returned value is exact; if the true value does not exceed α', the returned value does not exceed α' either and does not change the maximum of the node. So every child that could determine the node's maximum is seen with its exact value. If all children finish without a cutoff, the value returned by the node is the true value itself when the true value is greater than α; if the true value does not exceed α, the returned value does not either.
If there is a cutoff, the value returned from a child has reached β. The true value of the MAX node cannot be smaller than the true value of this child, and by the induction hypothesis the true value of this child is not smaller than β. So v ≥ β, and the returned value is not smaller than β either: the third case holds. Whatever the values of the unread children, this result does not change, because they can only increase the value of the MAX node. At the root α = −∞ and β = +∞, so the true value is always inside the interval and the first case applies. □
In everyday language the theorem says this: whatever the true value of a pruned branch, it cannot change the result of the parent's max or min operation. For MAX, a value that cannot exceed α cannot take α's place; for MIN, a value that cannot go below β cannot take β's place. The number returned at interior nodes may be a bound, but the move chosen at the root is still the move minimax chooses.
2.9.9Alpha-beta step by step: a twelve-leaf tree
The twelve-leaf tree solved by hand with minimax (Figure 2.33) is now searched with alpha-beta, trying the children from left to right. Each row is an event: descending into a node, reading a leaf, or a cutoff.
| Step | Node | Event | Value | [α, β] |
|---|---|---|---|---|
| 1 | A (MAX) | the search starts | −∞ | [−∞, +∞] |
| 2 | B (MIN) | the interval comes from A | +∞ | [−∞, +∞] |
| 3 | E (MAX) | leaves 5 and 6 are read: max(5, 6) | 6 | [6, +∞] |
| 4 | B | E = 6: β = min(+∞, 6) | 6 | [−∞, 6] |
| 5 | F (MAX) | the interval comes from B; leaf 7: α = 7 | 7 | [7, 6] |
| 6 | F | α = 7 ≥ β = 6: leaf 4 is pruned | 7 | — |
| 7 | B | F = 7: min(6, 7); B finishes | 6 | [−∞, 6] |
| 8 | A | B = 6: α = max(−∞, 6) | 6 | [6, +∞] |
| 9 | C (MIN) | the interval comes from A | +∞ | [6, +∞] |
| 10 | G (MAX) | leaves 3 and 2 are read: max(3, 2); α stays 6 | 3 | [6, +∞] |
| 11 | C | G = 3: β = min(+∞, 3) | 3 | [6, 3] |
| 12 | C | β = 3 ≤ α = 6: all of H (8 and 9) is pruned | 3 | — |
| 13 | A | C = 3: max(6, 3) | 6 | [6, +∞] |
| 14 | D (MIN) | the interval comes from A | +∞ | [6, +∞] |
| 15 | I (MAX) | leaves 4 and 1 are read: max(4, 1); α stays 6 | 4 | [6, +∞] |
| 16 | D | I = 4: β = min(+∞, 4) | 4 | [6, 4] |
| 17 | D | β = 4 ≤ α = 6: all of J (2 and 7) is pruned | 4 | — |
| 18 | A | D = 4: max(6, 4); the search ends | 6 | [6, +∞] |
The result is the same as minimax: the value of the root is 6, the chosen move A → B. The leaves read are 5, 6, 7, 3, 2, 4, 1; seven of the twelve leaves are read and five are pruned. Three points in the trace deserve attention:
- The 7 returned by F is a bound. F stopped without reading 4; the number it returned carries the information "F is at least 7". In this tree F's true value is also 7 (max(7, 4) = 7), but alpha-beta does not know this and does not need to: what matters for B is that F is larger than 6.
- α does not rise at G and I. The interval [6, +∞] arrives at G; its leaves are 3 and 2, and since max(6, 3) = 6, α does not change. The 3 returned by G is a value below α: the "bad enough" case of Theorem 2.3. C's β drops to 3 and the interval empties.
- Pruning can remove a whole subtree. What is pruned at C, H, is not a single leaf but a subtree with two leaves. In deep trees the pruned subtrees are much larger; the gain comes from here.
2.9.10Code trace: the alpha-beta function
Adding two parameters and three lines to the minimax code gives alpha-beta. The same six-leaf tree is used.
from math import inf
T = {"A": ["B", "C", "D"], "B": [3, 5],
"C": [2, 9], "D": [6, 4]}
def alphabeta(n, a, b, maxi):
if isinstance(n, int): # leaf
return n
best = -inf if maxi else inf
for c in T[n]:
v = alphabeta(c, a, b, not maxi)
if maxi:
best = max(best, v); a = max(a, best)
else:
best = min(best, v); b = min(b, best)
if a >= b:
break # cutoff
return best
print(alphabeta("A", -inf, inf, True))The differences from minimax are:
- The parameters
aandbare α and β. The root is called with-infandinf. The recursive call passes the node's currentaandbto the child. - A MAX node updates
aafter updatingbest, and a MIN node updatesb. The updates are on local variables; in Python, changingainside a function does not change the caller'sa. In this way the interval is passed only downward, automatically. - The line
if a >= b: breakis the pruning: the loop is exited without trying the remaining children.
| Step | Call (incoming a, b) | Event | best | a, b (after) |
|---|---|---|---|---|
| 1 | A (−∞, +∞) | the root is opened | −∞ | −∞, +∞ |
| 2 | B (−∞, +∞) | leaf 3: min; a < b, continue | 3 | −∞, 3 |
| 3 | B | leaf 5: min(3, 5); B finishes, returns 3 | 3 | −∞, 3 |
| 4 | A | B = 3: max; a = 3 | 3 | 3, +∞ |
| 5 | C (3, +∞) | leaf 2: min; b = 2 | 2 | 3, 2 |
| 6 | C | a = 3 ≥ b = 2: break, leaf 9 is not read; returns 2 | 2 | — |
| 7 | A | C = 2: max(3, 2); a stays 3 | 3 | 3, +∞ |
| 8 | D (3, +∞) | leaf 6: min; b = 6; a < b, continue | 6 | 3, 6 |
| 9 | D | leaf 4: min(6, 4); b = 4; a < b; D finishes, returns 4 | 4 | 3, 4 |
| 10 | A | D = 4: max(3, 4); a = 4; A finishes | 4 | 4, +∞ |
The program again prints 4. Five of the six leaves are read; the 9 that minimax read needlessly has been pruned. There is no pruning at D: the interval arriving at D is [3, +∞] and D's value 4 lies inside the interval. D's value is computed exactly and raises the root's value from 3 to 4. This is the first case of Theorem 2.3: if the value is inside the interval, the exact value is returned.
2.9.11Alpha-beta by hand: an eight-leaf tree
When applying alpha-beta by hand, three things are tracked for each interior node: the interval arriving from above, the node's current value, and whether the interval has emptied. The tree in Figure 2.42 shows this trace from start to finish.
First the value of the root is found with minimax: D = max(3, 7) = 7, E = max(9, 1) = 9, B = min(7, 9) = 7; F = max(4, 2) = 4, G = max(6, 8) = 8, C = min(4, 8) = 4; A = max(7, 4) = 7. The value of the root is 7 and MAX chooses B. Then alpha-beta is applied, trying the children from left to right:
- [−∞, +∞] arrives at B, and at D. D (MAX) reads 3 and 7: D = 7. B (MIN) gets β = min(+∞, 7) = 7.
- [−∞, 7] arrives at E. The first leaf is 9: α = 9 ≥ β = 7. E gives at least 9; since B has already guaranteed 7, it will not choose E. Leaf 1 is pruned. B = min(7, 9) = 7.
- At the root α = 7. [7, +∞] arrives at C, and at F. F (MAX) reads 4 and 2: F = 4 (α stays 7, because max(7, 4) = 7).
- At C, β = min(+∞, 4) = 4 ≤ α = 7. C gives at most 4; since the root has already guaranteed 7, it will not choose C. All of G (6 and 8) is pruned.
- Root = max(7, 4) = 7: MAX chooses B.
Five of the eight leaves (3, 7, 9, 4, 2) are read and three (1, 6, 8) are pruned. The result is the same as minimax. The 8 among G's leaves is not a number that could change C's true value: C's value is at most 4, the value of F, and this is below the 7 the root already holds.
Table 2.31 compares minimax and alpha-beta on three small trees and two real games. In every row the root value and the chosen move are the same; what changes is only the number of leaves read or nodes visited. The gain grows as the tree grows: a few leaves in small trees, about 70 times in tic-tac-toe, 189 times at depth 7 in Connect Four.
| Tree | Minimax | Alpha-beta | Root value | Pruned, or order |
|---|---|---|---|---|
| Twelve-leaf tree | 12 leaves | 7 leaves | 6 and 6 | F's 4; all of H and J |
| Tree in the code trace | 6 leaves | 5 leaves | 4 and 4 | C's 9 |
| Eight-leaf tree | 8 leaves | 5 leaves | 7 and 7 | E's 1; all of G |
| Tic-tac-toe, empty board | 549,946 nodes | 7,865 nodes | 0 and 0 | in the order center, corners, edges |
| Connect Four, start, depth 7 | 960,793 nodes | 5,086 nodes | +8 and +8 | in order from the middle outward |
2.9.12Move ordering
How much alpha-beta prunes depends on the order in which children are tried; the value of the root does not depend on the order. In the eight-leaf tree, had C been tried before B, the root would have had to compute C's value exactly, because at that point it holds no lower bound. When the best child is tried first, α and β narrow early and the later siblings are quickly eliminated.
This effect was measured by Knuth and Moore (1975). In a uniform tree of depth d in which every interior node has b children:
- In the best order (at a MAX node the child with the largest value first, at a MIN node the smallest), the number of leaves read is b⌈d/2⌉ + b⌊d/2⌋ − 1 ≈ bd/2.
- In the worst order there is no pruning at all and all bd leaves are read.
The structure of the formula comes from an observation. In the best order, all the children of the nodes on the path from the root to the best child must be opened, because the exact values of these nodes are needed. For the others, a single "refuting" reply below a sibling suffices to show that the sibling is not better. For this reason in half of the levels of the tree only one child is opened and in the other half all children are, and the number of leaves read grows with the half power of b. In the same time one can descend to about twice the depth; in other words, the effective branching factor falls from b to √b.
| d | 35d (no pruning) | Best order |
|---|---|---|
| 2 | 1,225 | 69 |
| 4 | 1,500,625 | 2,449 |
| 6 | 1,838,265,625 | 85,749 |
| 8 | ≈ 2.25 · 1012 | 3,001,249 |
The numbers in the table are computed directly from the formula. For example, for d = 4, 352 + 352 − 1 = 1,225 + 1,225 − 1 = 2,449; for d = 2, 35 + 35 − 1 = 69. At depth 8, while a search without pruning reads more than 2 trillion leaves, alpha-beta in the best order makes do with 3 million leaves. The work of best-order alpha-beta at depth 8 is about twice the work of an unpruned search at depth 4.
The effect is visible in a small tree as well. In a tree of 27 leaves with depth 3 and branching factor 3, 32 + 31 − 1 = 11 leaves are read in the best order; in the worst order there is no pruning at all and all 27 leaves are read. The order changes only the order in which children are tried; the tree is the same tree and the value of the root is the same in every order.
Knowing the best order means already knowing the best move; in practice the order is guessed. There are three sources of good guesses:
- Game knowledge: in Connect Four the middle column, in tic-tac-toe the center and corners, in chess moves that capture a piece first.
- The previous search: the move that an earlier, shallower search found best is tried first.
- Experience at sibling nodes: a move that caused a cutoff in another branch is tried first in this branch too.
In tic-tac-toe the effect of order can be counted directly. Table 2.33 gives the number of nodes visited by full searches from the empty board (with the depth-penalty scale).
| Method | Nodes visited | Root value |
|---|---|---|
| Minimax (order does not matter) | 549,946 | 0 |
| Alpha-beta, squares in order 0–8 (left to right, top to bottom) | 20,866 | 0 |
| Alpha-beta, center first, then corners, then edges | 7,865 | 0 |
| Minimax with a transposition table (each position once) | 5,478 | 0 |
Good ordering reduces the number of nodes by a factor of about 2.7 (20,866 / 7,865); compared with minimax the gain is about 70-fold (549,946 / 7,865). The value scale also affects pruning: the same two alpha-beta searches with the ±1 scale visit 18,297 and 7,275 nodes. The coarser the scale, the more values are equal; equal values satisfy the condition α ≥ β more often, so pruning increases. The depth penalty, in contrast, demands finer ordering and searches more nodes (about 2,600 more in the 0–8 order, about 600 more with good ordering); in return it distinguishes a fast win from a slow one and a late loss from an early one.
2.9.13Connect Four: why full search is impossible
Connect Four is played on an upright board with 7 columns and 6 rows. A player chooses a column and the disc falls to the lowest empty place in that column. The first player to line up four of their discs horizontally, vertically, or diagonally wins; if the board fills up, the game is a draw. The branching factor is at most 7 and the length of the game at most 42 plies. By John Tromp's count the number of legal positions is 4,531,985,219,092, that is, about 4.5 · 1012.
The game was solved in 1988, independently, by James D. Allen and Victor Allis: if the first player starts in the middle column, they can force a win. This solution was found not by brute force but with game-specific rules and very strong search. It is not a job that can be done in a browser in a second. Even a minimax that looks only 7 plies ahead from the starting position visits 960,793 nodes.
When a full search is impossible, the search is stopped at a certain depth. The positions where it stops are not game endings; their utilities are unknown. In their place an evaluation function estimates how good the position is.
2.9.14Depth-limited search and the evaluation function
An evaluation function E(s) gives a position that is not a game ending a score from MAX's point of view: large if the position looks good for MAX, small if it looks bad. Depth-limited search cuts minimax off so that it looks at most d plies ahead:
H(s, d) =
utility(s) if s is terminal
E(s) if d = 0
max H(result(s, a), d − 1) if MAX to move
a
min H(result(s, a), d − 1) if MIN to move
aThe first two lines of the definition together are called the cutoff test: if the game is over or the depth limit has been reached, descending stops. E(s) is not an exact value but an estimate; minimax uses these estimates as if they were leaves and propagates them up to the root. Alpha-beta works the same way: the E values at the limit are read like leaves.
The values of the evaluation function and the values of real game endings should lie in separate ranges. The value of a game ending must be larger than every value E can take (for a win) or smaller (for a loss); otherwise the program may prefer a position that "looks good" to a real win. The utility used here is: if Red (MAX) wins at ply k from the root, +(1000 − k); if Blue (MIN) wins, −(1000 − k); if the board fills, 0. The evaluation function takes at most a few hundred. The depth penalty of tic-tac-toe is present here too: as k gets smaller the value of a win grows, and the later a loss comes the larger the value of the loss.
A simple and effective evaluation function for Connect Four is based on the windows of four on the board. A window is a place made up of four adjacent squares in which a four could be completed. On a 7 × 6 board there are 69 windows: 24 horizontal (4 in each row, 24 over six rows), 21 vertical (3 in each column, 21 over seven columns), and 24 diagonal (12 in each of the two directions). Each window gets a score according to the discs in it.
| Discs in the window | p(w) |
|---|---|
| 3 red + 1 empty | +5 |
| 2 red + 2 empty | +2 |
| 3 blue + 1 empty | −5 |
| 2 blue + 2 empty | −2 |
| both colors, a single disc, or empty | 0 |
The evaluation function adds to the sum of the window scores a bonus for the middle column:
E(s) = Σ p(w) + 3 · (R_mid − B_mid)Here Rmid and Bmid are the numbers of red and blue discs in the middle column. The reason for rewarding the middle column is geometric: a square in the middle column belongs to between 7 and 13 windows, while a square in an edge column belongs to only 3 to 5. A disc in the middle can be part of more fours. A window containing both colors scores 0, because in that window nobody can make a four any more.
Red has played in the middle column (column 4), Blue in the column to its left (column 3), and Red in the column to the right of the middle (column 5); all three discs are in the bottom row. E(s) is computed as follows:
- Horizontal windows of the bottom row. The windows of columns 1–4, 2–5, and 3–6 contain the blue disc together with at least one red disc: 0. The window of columns 4–7 has two red discs (4 and 5) and two empty squares (6 and 7): +2.
- The other windows. All vertical and diagonal windows contain at most one of the discs; a window with a single disc scores 0. Windows containing only the blue disc also have a single disc: 0.
- Middle column. There is one red disc in the middle column: 3 · (1 − 0) = +3.
The total is E(s) = 2 + 3 = +5: the position looks slightly good for Red. The same function also explains the value of a depth-1 search from the empty board: when Red plays the middle column, a single disc scores in no window, only the middle-column bonus remains, and E = +3. A disc in an edge column gets 0. At depth 1 the root value is +3 and the program chooses the middle column.
The code of depth-limited alpha-beta adds to the code for the abstract tree only the cutoff test and move generation:
from math import inf
def alphabeta(s, d, a, b, maxi):
if s.is_over(): # game over
return s.utility() # ±(1000 − k) or 0
if d == 0:
return E(s) # evaluation
best = -inf if maxi else inf
for m in order(s.moves()):
v = alphabeta(s.play(m), d-1, a, b, not maxi)
if maxi:
best = max(best, v); a = max(a, best)
else:
best = min(best, v); b = min(b, best)
if a >= b:
break
return best
def best_move(s, d): # root: MAX
a, top = -inf, None
for m in order(s.moves()):
v = alphabeta(s.play(m), d-1, a, inf, False)
if v > a:
a, top = v, m
return topThe game-specific parts of the code are five: is_over, utility, moves, play, and E. The rest is independent of the game; the same skeleton can be used for tic-tac-toe, Connect Four, or chess. order puts the moves in the order in which they will be tried; in Connect Four this order is from the middle outward: 4, 3, 5, 2, 6, 1, 7. The function best_move keeps at the root not only the value but the move. The α at the root is carried across the root's children: the first child is searched with the full interval, the later ones with the narrowing window [α, +∞], and it is quickly shown that they are no better than the first.
2.9.15The horizon effect
Depth-limited search cannot see events just beyond the limit. This is called the horizon effect. In the tree of Figure 2.45, by the evaluations at the depth limit the position under B looks best with E = +6. Yet one move after that position there is an unavoidable loss (around −1000). Since the search stops at the limit, it does not see this loss and chooses B.
There is a more insidious form of the horizon effect: the program makes meaningless moves that push an unavoidable loss beyond the horizon. In chess, a program that sees that a piece will be lost delays the loss by a few plies by giving pointless checks or sacrificing a pawn. The loss does not disappear; it only becomes invisible because it falls outside the search depth; and, on top of that, the sacrificed pawn is lost too.
There is no complete cure for the horizon effect; there are methods that reduce its effect:
- Increasing the depth: the horizon moves away but does not disappear.
- Quiescence search: if the position at the limit is "active", for example a capture or a threat is in progress, the search continues with only such moves and the position is evaluated when it has calmed down.
- Threat extension: while one side has a threat to win in one move, the search descends one more level.
A program playing Connect Four with depth 1 or 2 cannot see double threats and is easily beaten: the double threat the opponent will set up two moves later lies outside the program's horizon. As the depth is increased, the program starts to see these traps. That the root value goes up and down with depth as +3, 0, +6, 0, +6, 0, +8 is also a consequence of limited vision: at odd depths Red makes the last move at the horizon and at even depths Blue does, and the side making the last move appears in the evaluation with an extra disc.
2.9.16Move ordering, iterative deepening, and the transposition table
The effect of move ordering in Connect Four is measured with searches at different depths from the starting position (Table 2.35).
| Depth | Minimax | Alpha-beta (left to right) | Alpha-beta (middle outward) | Root value |
|---|---|---|---|---|
| 1 | 8 | 8 | 8 | +3 |
| 2 | 57 | 33 | 21 | 0 |
| 3 | 400 | 200 | 76 | +6 |
| 4 | 2,801 | 966 | 175 | 0 |
| 5 | 19,608 | 4,340 | 627 | +6 |
| 6 | 137,257 | 16,409 | 1,285 | 0 |
| 7 | 960,793 | 67,549 | 5,086 | +8 |
Minimax grows roughly as 7d: at depth 1, 8 nodes (the root and seven children), at depth 2, 1 + 7 + 49 = 57, at depth 7, 960,793. At depth 7 alpha-beta visits about 14 times fewer nodes in left-to-right order (960,793 / 67,549) and 189 times fewer in middle-outward order (960,793 / 5,086). The root value is the same in all three methods in every row: the order changes only the cost. Since the middle column takes part in the most fours, good moves are mostly in the middle; when they are tried first, α and β narrow early.
Iterative deepening solves the problem of choosing the search depth in advance. First a search with depth 1 is run, then 2, 3, …; when time runs out, the move of the last completed search is played. At first sight repeating shallow searches seems wasteful, but the repeated work is small: in an exponentially growing tree the last level is larger than the sum of the earlier ones. For b = 7, the total work of all depths is only about 7/6 times the work of the last depth alone:
7 + 7² + … + 7^d ≈ 7^d · (1 + 1/7 + 1/49 + …) = 7^d · 7/6The second gain of iterative deepening is in ordering: the best move of the previous search is tried first in the next. Move ordering thus improves by itself, and the cost of the shallow searches is more than recovered by the pruning gained in the deep search.
A transposition table prevents the same position from being searched over and over. The same position can be reached by different move orders (a transposition). A position is searched once and the result is written into a hash table; when the position is met again the result is read from the table. In tic-tac-toe a full search thus makes do with 5,478 positions instead of 549,946 nodes (Table 2.33). An entry in the table contains: the value, the depth to which the position was searched, whether the value is exact or a lower or upper bound, and the best move. The bound information is needed because of alpha-beta: the value returned from a pruned search may not be exact (Theorem 2.3). Chess programs turn a position into a single number, a hash key, with a method proposed by Zobrist (1970); a move updates this key with a few XOR operations.
The skeleton of strong game-playing programs consists of these parts: iterative deepening, alpha-beta, good move ordering, a transposition table, and a good evaluation function. Real systems use this skeleton in different proportions:
- Deep Blue (1997). IBM's chess computer beat the world champion Garry Kasparov 3½–2½ in a six-game match. It ran parallel alpha-beta on special chess chips and evaluated about 200 million positions per second.
- Chess engines. Programs such as Stockfish still use a search derived from alpha-beta: iterative deepening, a transposition table, and strong pruning methods. Since 2020 the evaluation function has been a neural network (NNUE).
- Go and Monte Carlo tree search. In Go b ≈ 250 and writing a good E(s) is very hard. Monte Carlo tree search (Coulom, 2006; UCT: Kocsis and Szepesvári, 2006) evaluates positions with randomly played games. AlphaGo combined this search with deep neural networks and beat Lee Sedol 4–1 in March 2016.
The common idea of these systems is the same as minimax: looking ahead while assuming the opponent's best reply. What changes is how much of the tree is searched and how the leaves are evaluated.
2.9.17Common mistakes in search algorithms
- Passing α and β in the wrong direction. The interval descends unchanged from parent to child; only the value returns to the parent. An α or β updated in a child is not carried to the parent. MAX updates only α, MIN only β. In the twelve-leaf tree α = 7 at F, but only F's value returns to B; B's interval stays [−∞, 6].
- Counting a pruned branch. The values of pruned leaves are not read; feeding them into a min or max operation in a hand solution is wrong. The number returned by a node that was cut off is also not an exact value but a bound.
- Thinking the root value depends on the order. Move ordering changes only the number of leaves read. If a different order gives a different root value, there is a bug in the code.
- Viewpoint and sign errors. E(s) must always be written from the point of view of the same player (here Red, that is, MAX). If the program is the second player, it chooses the smallest. If negamax is written, the sign is flipped at every level and the evaluation is made from the point of view of the player to move; if the two formulations are mixed up, the program plays for its opponent.
- Forgetting the depth penalty. If all wins get the same value, the program postpones a ready win; and when losing it may choose the fastest loss. The utility must also include how many moves later the win comes.
- Keeping the evaluation on the same scale as game endings. If E(s) can reach the value of a real win, the program may prefer a good-looking position to a sure win. The values of game endings should lie outside every value the evaluation function can take.
- Taking a depth-limited value as exact. H(s, d) is an estimate from a look of d plies. In Connect Four the +8 at depth 7 does not mean "Red wins"; the real outcome of the game is known only by a full search or a proof.
2.10The algorithmic view and mechanism design
Most of the concepts so far belong to classical game theory. But a thread has also emerged throughout the chapter: minimax, backward induction, and Nim's XOR rule are algorithms; in the 2/3 game the elimination is a loop. This place where game theory meets computer science gives rise to the questions of algorithmic game theory.
2.10.1Why is algorithmic game theory "algorithmic"?
Three observations make the algorithmic view necessary.
Size. Even the description of a game grows exponentially. If each of n players has 2 strategies, the number of strategy profiles is 2n. Since each player's payoff must be written for each profile, the matrix contains n · 2n numbers. In a game with 30 players the number of profiles is 230 ≈ 1.07 · 109. A brute-force method that checks all profiles one by one does not scale.
Each bar in Figure 2.46 is many times larger than the one before. In the security example, each choice of 5 targets to protect out of 20 is a strategy; the number of choices is C(20, 5) = 20! / (5! · 15!) = 15,504. These numbers show that most games can be solved only with algorithms that exploit their structure.
Complexity. By Nash's theorem every finite game has an equilibrium in mixed strategies. But knowing that an equilibrium exists does not mean finding it. Even for two-player games no fast method of finding an equilibrium is known: the problem (exact equilibrium for two players, approximate equilibrium for many players) belongs to the class of hard problems called PPAD-complete (Daskalakis, Goldberg, and Papadimitriou; for two players, Chen and Deng).
Structure and design. Special structure brings efficiency. Zero-sum games are solved quickly by linear programming; in Nim, XOR labels exponentially many positions with a single computation. Rules are algorithms too: the rule that determines the winner and the payment in an auction is a program, and it must be designed correctly.
2.10.2Four questions
Algorithmic game theory has four main questions. The concepts of this chapter, that is, the classification of games, the equilibria of classic games, and backward induction in sequential games, are the common language of all four.
- Computation: can an equilibrium be found? Zero-sum games are solved quickly by linear programming. For general games no fast method for finding a Nash equilibrium is known; the problem is PPAD-complete. Combinatorial games can also be hard: solving Hex on large boards is PSPACE-complete (Reisch, 1981).
- Efficiency: what does selfishness cost? The Price of Anarchy is the ratio of the cost of the worst equilibrium to the cost of the best outcome. In the Prisoner's Dilemma, if years in prison are counted as cost, the equilibrium is 4 years in total and (Silent, Silent) is 2 years; the ratio is 4 / 2 = 2.
- Design: which rules? Mechanism design looks for rules that make players report their private information truthfully, that is, rules that are incentive compatible: auctions, matching, voting.
- Dynamics: how do players reach equilibrium? In repeated and online games, information arrives over time; players adapt their strategies by learning from the past. The guesses falling toward 0 over repeated rounds of the 2/3 game are an example of this.
In the price competition game (Table 2.4) the profits are payoffs, not costs. In this case the efficiency loss is measured by the ratio of the total profit of the best outcome to the total profit at equilibrium:
- Total profit at equilibrium: (100, 100) = 5 + 5 = 10.
- The outcome that maximizes total profit: (120, 120) = 6 + 6 = 12. (In the other cells 8 + 1 = 9.)
- Ratio: 12 / 10 = 1.2.
Selfish pricing costs the firms about 17% of their total profit (from 12 to 10, 2/12). The ratio in the Prisoner's Dilemma (2) is larger; the loss depends on the numbers in the game.
2.10.3Mechanism design: game theory in reverse
Game theory predicts the outcome of a given game: the rules are fixed, and the question is what will happen. Mechanism design turns the question around: the desired outcome is fixed, and the question is what rules and incentives will produce that outcome. For this reason mechanism design is also called "reverse game theory".
The difficulty of design is this: the agents' private information, for example the value they place on an item, their location, or their preferences, is hidden from the designer. Agents may lie when reporting this information. A good mechanism makes lying unprofitable. As Vickrey showed in 1961, in a second-price auction bidding truthfully is a dominant strategy: the winner pays not their own bid but the second-highest bid; inflating or shading the bid therefore adds nothing to the payoff.
Mechanisms fall into two groups:
- With money: the designer can collect or make payments; the payments encourage truth-telling. Examples: auctions, ad placement.
- Without money: incentives are provided only by the rule; usually the goal is compromised a little. Examples: elections, house swaps, facility location.
2.10.4Real-world applications
Mechanism design and algorithmic game theory work inside many real systems:
- Search ads: ad slots are allocated in every search by a generalized second price (GSP) auction. Unlike the single-slot second-price auction, in multi-slot GSP truthful bidding is not dominant.
- Spectrum auctions: governments sell frequency licenses in designed auctions; in the United States this practice has continued since 1994.
- School placement: in the student-proposing Gale–Shapley algorithm it is best for a student to report their true preferences; the result is a stable matching.
- Room and shift swaps: everyone brings what they hold; through swap cycles nobody gets something worse than before and no money is used.
- Traffic and routing: each driver chooses their own fastest path; the cost of selfish choices to total delay is measured by the Price of Anarchy.
- Platforms and incentives: surge pricing draws drivers to busy hours; Bitcoin miners validate transactions for a reward.
The common idea of these applications is this: the rules are designed so that the system works well even if everyone acts in their own interest. In the Prisoner's Dilemma individual interest led to a bad shared outcome; in a well-designed mechanism individual interest leads to the desired outcome.
2.11Solved problems
Five problems bring together the main methods of the chapter; the solutions are given with intermediate steps.
Problem. In the price competition game (Table 2.4), what are the dominant strategies and the equilibrium? Is the equilibrium Pareto optimal?
Solution. For Firm 1, 100 TL gives 5 > 1 against Firm 2's 100 and 8 > 6 against its 120: 100 is dominant. Since the game is symmetric, 100 is dominant for Firm 2 as well. The equilibrium is (100, 100) = (5, 5). Because (120, 120) = (6, 6) gives both firms more, it Pareto dominates the equilibrium; the equilibrium is not Pareto optimal.
Problem. In the 2/3 game (0–90), if 20% of the class thinks at level 0 and 80% at level 1, which level wins?
Solution. The expected average is 0.2 · 45 + 0.8 · 30 = 9 + 24 = 33 and the target is 2/3 · 33 = 22. The distances: level 0 (45) 23, level 1 (30) 8, level 2 (20) 2, level 3 (13.3) 8.7. Level 2 is closest. The Nash answer, 0, is 22 away.
Problem. Two players choose A or B. (A, A) = (4, 1), (B, B) = (1, 4), the other cells (0, 0). What are the pure equilibria? Which classic game does this game resemble?
Solution. In column A the row player gets 4 with A and 0 with B → A. In column B, 0 with A and 1 with B → B. In row A the column player gets 1 with A and 0 with B → A. In row B, 0 with A and 4 with B → B. The cells with two marks are (A, A) and (B, B). One favors the row player (4 > 1), the other the column player (4 > 1). Meeting is a shared interest and where to meet is a conflict: the structure of Battle of the Sexes.
Problem. A MAX root has three MIN children: B = [7, 2, 9], C = [4, 6], D = [1, 8]. What is the value of the game and what does MAX choose?
Solution. The MIN values: B = min(7, 2, 9) = 2, C = min(4, 6) = 4, D = min(1, 8) = 1. The root MAX = max(2, 4, 1) = 4; MAX chooses C. The 9 at B and the 8 at D are misleading: MIN does not allow them.
Problem. In the market entry game, why is (Stay out, Fight) not subgame perfect?
Solution. In the subgame that starts after E has entered, Fight gives I −1 and Share gives 1. Fight is not a best response in this subgame; hence the profile does not form a Nash equilibrium in that subgame. "If you enter, I will fight" is a non-credible threat. The profile is a Nash equilibrium of the whole game, but not of every subgame.
2.12Summary
- A game consists of players, strategies, payoffs, information, and rules. A rational player maximizes expected utility given their beliefs; rational does not mean selfish. Common knowledge is the chain of "everyone knows" continuing forever.
- A strategy is a complete plan saying what to do at every decision node; m actions at each of k nodes give mk strategies. A mixed strategy is a probability distribution over pure strategies.
- Ordinal utility carries only the order, cardinal utility also the size of differences. Lottery and mixed-strategy computations require cardinal utility; the transformation a · u + b (a > 0) preserves decisions.
- The normal form G = (N, (Si), (ui)) writes simultaneous games as a matrix; the extensive form writes sequential games as a tree. An information set shows a simultaneous game in a tree.
- Games are classified along six dimensions: timing, agreements, total payoff, symmetry, information, and horizon. Perfect information concerns past moves, complete information concerns payoff functions.
- A Nash equilibrium is a profile from which nobody wants to deviate unilaterally. In the Prisoner's Dilemma Betray is dominant and the only equilibrium, (−2, −2), is not Pareto optimal: stability is not efficiency.
- The six classic 2×2 games range from conflict to coordination: Matching Pennies has no pure equilibrium; Chicken, Battle of the Sexes, Stag Hunt, and Pure Coordination have two pure equilibria; in Free Money one of them is weak.
- In the 2/3 game iterated elimination 90 → 60 → 40 → … → 0 gives the unique equilibrium (everyone 0); real players think 1–2 steps and the best guess depends on beliefs (level-k).
- Minimax computes values from the leaves to the root; tic-tac-toe is a draw, the example tree has value 3. In Nim a position is losing if its nim-sum is 0 (Bouton); in Don't Say 21 the key numbers are multiples of 4.
- Subgame perfect equilibrium is a Nash equilibrium in every subgame and is found by backward induction; it rules out non-credible threats (market entry, investment, ultimatum). In the Centipede game the SPE is (1, 0).
- A game tree reaches a size of roughly bd. The minimax value rises from the leaves to the root: O(bd) time, O(b · d) memory. In Nim, minimax, the P/N labels, and the XOR rule find a winning move (negamax); in tic-tac-toe the empty board has value 0 and the depth penalty ±(10 − d) makes the program choose the fast win and the late loss.
- Alpha-beta pruning passes the interval [α, β] from top to bottom and skips the remaining children when α ≥ β; the root value and the chosen move do not change (7 leaves instead of 12 in the twelve-leaf example). With the best move ordering about bd/2 leaves are read (Knuth–Moore, 1975); in tic-tac-toe 7,865 nodes suffice instead of 549,946.
- In games where full search is impossible, the search stops at a depth limit and an evaluation function estimates the position. Being unable to see beyond the limit is the horizon effect; iterative deepening and a transposition table speed up the search. In Connect Four at depth 7, middle-outward alpha-beta visits 189 times fewer nodes than minimax.
- The grim trigger strategy deters betrayal in infinite repetition with a permanent punishment; with the Sam–John payoffs cooperation is an equilibrium when δ ≥ 1/2. With a finite, known horizon cooperation unravels.
- Algorithmic game theory asks four questions: computation, efficiency (the Price of Anarchy), design (mechanism design), and dynamics.
| Concept | Short definition | Example |
|---|---|---|
| Normal / extensive form | A matrix (simultaneous) or a game tree showing order and information | RPS, price competition; chess |
| Classification | Timing, agreements, total payoff, symmetry, information, horizon | Chess: sequential, zero-sum, perfect information |
| Dominant strategy, Nash equilibrium | Better whatever the other side does; no profitable unilateral deviation | Betray; (Betray, Betray) |
| Pareto optimality | Cannot be improved without making someone worse off | The equilibrium (−2, −2) is not |
| Classic 2×2 games | Conflict or coordination; pure equilibria found with best responses | Matching Pennies: none; Stag Hunt: two |
| Iterated elimination, level-k | Deleting the dominated again and again; best guess given beliefs | 2/3 game: 90 → 60 → 40 → … → 0 |
| Minimax, Nim | Best choice from leaves to root; P/N positions | Tree value 3; tic-tac-toe draw; Nim XOR |
| Alpha-beta, depth-limited search | Skipping branches that cannot affect the result with [α, β]; evaluation function at the depth limit | 7 of 12 leaves; tic-tac-toe: 549,946 → 7,865 nodes |
| Subgame perfect equilibrium | Nash in every subgame; found by backward induction | Market entry; Centipede (1, 0) |
| Grim trigger strategy | Deterring betrayal in infinite repetition with a permanent punishment | Cooperation among patient players (large δ) |
2.13Key terms
- game theory
- player
- rationality
- common knowledge
- strategy
- strategy profile
- pure strategy
- mixed strategy
- payoff
- utility function
- expected utility
- ordinal utility
- cardinal utility
- lottery
- information set
- perfect information
- complete information
- incomplete information
- Bayesian game
- normal form
- payoff matrix
- extensive form
- game tree
- leaf
- zero-sum game
- constant-sum game
- maximin
- minimax
- symmetric game
- coalition
- discount factor
- best response
- Nash equilibrium
- dominant strategy
- Prisoner's Dilemma
- Pareto optimal
- Pareto dominance
- Price of Anarchy
- commitment
- focal point
- level-k reasoning
- iterated elimination of dominated strategies
- combinatorial game
- Zermelo's theorem
- strategy-stealing argument
- nim-sum
- subgame
- subgame perfect equilibrium
- backward induction
- non-credible threat
- centipede game
- ultimatum game
- grim trigger
- branching factor
- ply
- negamax
- alpha-beta pruning
- move ordering
- evaluation function
- depth-limited search
- horizon effect
- quiescence search
- iterative deepening
- transposition table
- Monte Carlo tree search
- mechanism design
- incentive compatible
2.14Test Yourself
Firm 1 chooses one of four prices (80, 90, 100, 120 TL). Firm 2 sees this price and says 90, 100, or 120 TL. How many pure strategies does each firm have?
Answer
Firm 1 has a single decision node and 4 actions: 4 strategies. Firm 2 has 4 decision nodes (one for each of Firm 1's prices) and at each chooses among 3 actions: 34 = 81 strategies. The number of actions (3) or nodes × actions (12) is not the number of strategies.
In the cells (u1, u2): (Top, Left) = (2, 2), (Top, Right) = (0, 3), (Bottom, Left) = (3, 0), (Bottom, Right) = (1, 1). What are the dominant strategies, the Nash equilibrium, and the Pareto optimal outcomes?
Answer
For the row player Bottom is dominant: 3 > 2 against Left, 1 > 0 against Right. For the column player Right is dominant: 3 > 2 against Top, 1 > 0 against Bottom. The only Nash equilibrium is (Bottom, Right) = (1, 1). (Top, Left) = (2, 2) Pareto dominates the equilibrium. The Pareto optimal outcomes are (2, 2), (0, 3), and (3, 0). The game is a Prisoner's Dilemma.
In the 2/3 game (0–90), if 60% of the class thinks at level 0 and 40% at level 1, what is the target? Is level 1 or level 2 closer to the target?
Answer
The expected average is 0.6 · 45 + 0.4 · 30 = 27 + 12 = 39 and the target is 2/3 · 39 = 26. Level 1 (30) is 4 away from the target and level 2 (20) is 6 away. In this population level 1 wins: in a class where the others think little, thinking too much loses.
A MAX root has three MIN children: B = [5, 9], C = [6, 1, 8], D = [7, 4]. What is the minimax value of the game and what does MAX choose? Why can't the largest leaf in the tree be chosen?
Answer
The MIN values: B = min(5, 9) = 5, C = min(6, 1, 8) = 1, D = min(7, 4) = 4. The root MAX = max(5, 1, 4) = 5; MAX chooses B. The largest leaf 9 is at B, but at B the choice is MIN's and MIN chooses 5.
The Nim position is [1, 3, 6]. Is the player to move in a winning position? What is the winning move?
Answer
1 ⊕ 3 = 001 ⊕ 011 = 010 = 2; 2 ⊕ 6 = 010 ⊕ 110 = 100 = 4. The nim-sum is 4 ≠ 0: it is a winning position. The heaps are tried: 1 ⊕ 4 = 5 (larger than 1), 3 ⊕ 4 = 7 (larger than 3), 6 ⊕ 4 = 2 (smaller than 6). The only winning move is to take 4 tokens from the third heap, leaving [1, 3, 2]: 1 ⊕ 3 ⊕ 2 = 0.
In "Don't Say 25" players take turns saying 1 to 4 consecutive numbers; whoever says 25 loses. Which states (last number said) are losing, and who wins?
Answer
The base state is 24: the player to move must say 25 (L). From 23, 22, 21, 20 one can reach 24 (W). All of the states 20–23 reachable from 19 are W: 19 is L. The pattern continues in steps of 5: the L states are 24, 19, 14, 9, 4. Since 4 can be reached from the start 0, the first player wins: they say "1, 2, 3, 4", and then, if the opponent says x numbers, they say 5 − x numbers.
In the market entry game, suppose the Incumbent gains a reputation from fighting: let the leaf Enter–Fight be (−1, 3) instead of (−1, −1); the other leaves are the same (Stay out (0, 2), Enter–Share (1, 1)). What is the subgame perfect equilibrium? Is the threat "if you enter, I will fight" now credible?
Answer
At I's node Fight gives 3 and Share gives 1; I fights and the node's value is (−1, 3). At the root, Enter gives E −1 and Stay out gives 0; E stays out. The SPE is (Stay out, Fight) with outcome (0, 2). The threat is now credible, because when E enters, fighting really is in I's interest.
In a repeated game the payoffs each round are: if both cooperate, 3 each; if one deviates while the other cooperates, the deviator gets 6 and the other 0; if both deviate, 1 each. Both players play grim trigger. For deviating to be unprofitable, what must the probability δ that the game lasts one more round be at least?
Answer
Complying: 3 / (1 − δ). Deviating: 6 this round, then 1 every round: 6 + δ / (1 − δ). The condition is 3 / (1 − δ) ≥ 6 + δ / (1 − δ). Multiplying both sides by (1 − δ): 3 ≥ 6(1 − δ) + δ = 6 − 5δ, that is, δ ≥ 3/5. As the temptation to deviate grows (a larger number than 6), the threshold grows too.
A MAX root has three MIN children: B = [4, 8, 6], C = [2, 7], D = [5, 3, 9]. If the children are tried from left to right, which leaves does alpha-beta read and which does it prune? What is the value of the root?
Answer
All three of B's leaves are read: B = min(4, 8, 6) = 4 and at the root α = 4. [4, +∞] arrives at C; with the first leaf 2, β = 2 ≤ α = 4 and 7 is pruned. [4, +∞] also arrives at D; with 5, β = 5 and the interval is still nonempty; with 3, β = 3 ≤ 4 and 9 is pruned. The leaves read are 4, 8, 6, 2, 5, 3 (six of eight). The value of the root is max(4, 2, 3) = 4 and MAX chooses B. The result of minimax is the same: C = 2, D = 3.
In a uniform tree of depth 4 in which every interior node has 4 children, how many leaves does minimax read? How many does alpha-beta read with the best move ordering?
Answer
Minimax reads all the leaves: 44 = 256. In the best order the Knuth–Moore formula gives 42 + 42 − 1 = 31. In the worst order there is no pruning and again 256 leaves are read; the root value is the same in all three cases.
In tic-tac-toe the depth penalty ±(10 − d) is used. Of X's three moves, one forces a win 3 plies from the root, one forces a win 7 plies later, and one leads to a draw. What are the values of the moves and which does X choose? What changes on the ±1 scale?
Answer
The values are 10 − 3 = +7, 10 − 7 = +3, and 0; X chooses the largest, that is, the fast win (+7). On the ±1 scale both wins get +1 and the choice between them is decided only by the order in which the moves are tried; the program may needlessly prolong the win.
In Connect Four Red has put two discs in the middle column (first and second rows from the bottom); Blue's only disc is at the bottom of the leftmost column. With the window scores and the middle-column bonus, what is E(s)?
Answer
The vertical window in the middle column covering rows 1–4 from the bottom has two red discs and two empty squares: +2. All the other windows contain at most one of the red discs, or only the blue disc: 0. The middle-column bonus is 3 · (2 − 0) = 6. The total is E(s) = 2 + 6 = +8.
In a game with branching factor 3, iterative deepening searches from depth 1 up to 8. About how many times the search at depth 8 alone is the total work? What do you see when comparing with b = 7?
Answer
The total work is 3 + 32 + … + 38 ≈ 38 · (1 + 1/3 + 1/9 + …) = 38 · 3/2: about 1.5 times. For b = 7 the ratio is 7/6 ≈ 1.17. In general the ratio is b / (b − 1): the larger the branching factor, the more the last level exceeds the sum of the earlier ones, and the smaller the extra cost of iterative deepening.
2.15Further reading
- M. J. Osborne, An Introduction to Game Theory (2004), Chapters 2–5: normal-form games, the Nash equilibrium, extensive-form games, and backward induction, explained with little mathematics and many examples.
- A. R. Karlin and Y. Peres, Game Theory, Alive (2017): combinatorial games, Nim, and the strategy-stealing argument, with detailed proofs at student level.
- C. F. Camerer, Behavioral Game Theory (2003): examines the behavior of real players in games such as the 2/3 game, Centipede, and Ultimatum with experimental results.
- S. Russell and P. Norvig, Artificial Intelligence: A Modern Approach (4th edition, 2020), Chapter 5: explains minimax, alpha-beta pruning, evaluation functions, and Monte Carlo tree search through game-playing programs.
- D. E. Knuth and R. W. Moore, "An analysis of alpha-beta pruning" (1975): the classic paper that proves the correctness of alpha-beta and the number of leaves read in the best ordering.
- N. Nisan, T. Roughgarden, É. Tardos, and V. Vazirani (eds.), Algorithmic Game Theory (2007), Chapter 1: introduces the basic concepts of game theory in terms of the questions of algorithmic game theory.
2.16References
- L. V. Allis, A Knowledge-Based Approach of Connect-Four, master's thesis, Vrije Universiteit Amsterdam, 1988.
- C. L. Bouton, “Nim, a game with a complete mathematical theory”, Annals of Mathematics 3, 1901–1902.
- C. F. Camerer, Behavioral Game Theory, Princeton University Press, 2003.
- M. Campbell, A. J. Hoane, F. Hsu, “Deep Blue”, Artificial Intelligence 134, 57–83, 2002.
- R. Coulom, “Efficient selectivity and backup operators in Monte-Carlo tree search”, Computers and Games, 2006.
- D. Easley, J. Kleinberg, Networks, Crowds, and Markets, Cambridge University Press, 2010.
- W. Güth, R. Schmittberger, B. Schwarze, “An experimental analysis of ultimatum bargaining”, Journal of Economic Behavior & Organization 3(4), 1982.
- R. A. Hearn, E. D. Demaine, Games, Puzzles, and Computation, A K Peters, 2009.
- A. R. Karlin, Y. Peres, Game Theory, Alive, American Mathematical Society, 2017.
- D. E. Knuth, R. W. Moore, “An analysis of alpha-beta pruning”, Artificial Intelligence 6(4), 293–326, 1975.
- L. Kocsis, C. Szepesvári, “Bandit based Monte-Carlo planning”, ECML, 2006.
- H. W. Kuhn, “Extensive games and the problem of information”, Contributions to the Theory of Games II, Princeton University Press, 1953.
- R. D. McKelvey, T. R. Palfrey, “An experimental study of the centipede game”, Econometrica 60(4), 1992.
- R. Nagel, “Unraveling in guessing games: An experimental study”, American Economic Review 85(5), 1995.
- J. F. Nash, “Equilibrium points in n-person games”, PNAS 36(1), 1950.
- N. Nisan, T. Roughgarden, É. Tardos, V. Vazirani (eds.), Algorithmic Game Theory, Cambridge University Press, 2007 (Chapter 1).
- M. J. Osborne, An Introduction to Game Theory, Oxford University Press, 2004 (Chapters 2–5).
- S. Reisch, “Hex ist PSPACE-vollständig”, Acta Informatica 15, 1981.
- R. W. Rosenthal, “Games of perfect information, predatory pricing and the chain-store paradox”, Journal of Economic Theory 25, 1981.
- T. Roughgarden, Twenty Lectures on Algorithmic Game Theory, Cambridge University Press, 2016.
- S. Russell, P. Norvig, Artificial Intelligence: A Modern Approach, 4th edition, Pearson, 2020 (Chapter 5).
- J. Schaeffer et al., "Checkers is solved", Science 317(5844), 2007.
- T. C. Schelling, The Strategy of Conflict, Harvard University Press, 1960.
- R. Selten, "Spieltheoretische Behandlung eines Oligopolmodells mit Nachfrageträgheit", Zeitschrift für die gesamte Staatswissenschaft 121, 301–324 and 667–689, 1965.
- C. E. Shannon, “Programming a computer for playing chess”, Philosophical Magazine 41(314), 1950.
- Y. Shoham, K. Leyton-Brown, Multiagent Systems, Cambridge University Press, 2009 (Chapters 3 and 5).
- D. Silver et al., "Mastering the game of Go with deep neural networks and tree search", Nature 529, 484–489, 2016.
- B. Skyrms, The Stag Hunt and the Evolution of Social Structure, Cambridge University Press, 2004.
- J. Tromp, John's Connect Four Playground (number of Connect Four positions).
- J. Tromp, G. Farnebäck, “Combinatorics of Go”, Computers and Games, 2006.
- J. Tromp, “The Number of Legal Go Positions”, Computers and Games, 2016.
- J. von Neumann, “Zur Theorie der Gesellschaftsspiele”, Mathematische Annalen 100, 1928.
- E. Zermelo, "Über eine Anwendung der Mengenlehre auf die Theorie des Schachspiels", Proceedings of the Fifth International Congress of Mathematicians, vol. 2, 501–504, Cambridge University Press, 1913.
- A. L. Zobrist, “A new hashing method with application for game playing”, Tech. Rep. 88, University of Wisconsin, 1970.
Related pages: Chapter 2 slides · Course pages: Roughgarden CS364A · Shah CSC304 · Tools: Gambit, Nashpy · © Sercan Külcü. All rights reserved.