Difference between revisions of "Game theory"

From PEGWiki
Jump to: navigation, search
Line 25: Line 25:
 
In a two-player, deterministic, impartial game which is guaranteed to end in a finite number of moves, an ''N-position'' is a configuration such that the '''n'''ext player to make a move can force victory, and a ''P-position'' is a configuration such that the '''p'''revious player who moved can force victory. In a normal-play game, a configuration in which no further moves are possible is a P-position, since the player who is supposed to move next cannot do so and loses; in a misère-play game, it is an N-position, since the player who moved last made the last move and hence lost.
 
In a two-player, deterministic, impartial game which is guaranteed to end in a finite number of moves, an ''N-position'' is a configuration such that the '''n'''ext player to make a move can force victory, and a ''P-position'' is a configuration such that the '''p'''revious player who moved can force victory. In a normal-play game, a configuration in which no further moves are possible is a P-position, since the player who is supposed to move next cannot do so and loses; in a misère-play game, it is an N-position, since the player who moved last made the last move and hence lost.
  
Consider a configuration <math>C</math> of such a game and the configurations <math>C_1, C_2, C_3, ...</math> reachable from it. If at least one of <math>C_1, C_2, C_3, ...</math> is a P-position, then the player presented with configuration <math>C</math> wants to make the move that results in that configuration, so that he or she becomes the previous player when the next player is to move --- guaranteeing victory. This makes that
+
Consider a configuration <math>C</math> of such a game and the configurations <math>C_1, C_2, C_3, ...</math> reachable from it. If at least one of <math>C_1, C_2, C_3, ...</math> is a P-position, then the player presented with configuration <math>C</math> wants to make the move that results in that configuration, so that he or she becomes the previous player when the next player is to move --- guaranteeing victory. This makes <math>C</math> a N-position. If all of <math>C_1, C_2, C_3, ...</math> are N-positions, then no matter what move the current player makes, the next player can force victory, making <math>C</math> a P-position. In summary,
 +
* If all positions reachable in one move from position <math>C</math> are N-positions, then <math>C</math> is a P-position, and the current player does not have a winning strategy.
 +
* Otherwise (at least one P-position is reachable from <math>C</math>) <math>C</math> is an N-position, and a winning strategy necessarily entails leaving behind one of these P-positions for the next player.
  
 
==Nimbers==
 
==Nimbers==
Line 45: Line 47:
 
We state here the solution to Nim, a well-known result, and show later how it fits into the framework of Nim-like games in general. Simply compute the bitwise XOR of the sizes of all piles gives the ''nim-sum'' of a configuration of Nim. If this is zero, then the configuration is a P-position; otherwise it is an N-position. For example, if there are three piles containing one, two, and three sticks, respectively, the nim-sum is 1 XOR 2 XOR 3 = 0, and the configuration is a P-position; however, if instead of a three-stick pile we had a four-stick pile, the nim-sum would be instead 1 XOR 2 XOR 4 = 7, and the configuration would be a N-position.
 
We state here the solution to Nim, a well-known result, and show later how it fits into the framework of Nim-like games in general. Simply compute the bitwise XOR of the sizes of all piles gives the ''nim-sum'' of a configuration of Nim. If this is zero, then the configuration is a P-position; otherwise it is an N-position. For example, if there are three piles containing one, two, and three sticks, respectively, the nim-sum is 1 XOR 2 XOR 3 = 0, and the configuration is a P-position; however, if instead of a three-stick pile we had a four-stick pile, the nim-sum would be instead 1 XOR 2 XOR 4 = 7, and the configuration would be a N-position.
  
If, on your turn, you are faced with a P-position, it doesn't matter what you do; your opponent can force you to lose. If, on the other hand, you are faced with an N-position, you want to  
+
If, on your turn, you are faced with a P-position, it doesn't matter what you do; your opponent can force you to lose. If, on the other hand, you are faced with an N-position, you want to leave a P-position for your opponent. In the example with one, two, and four sticks, you would want to take one stick from the four-stick pile, leaving behind one, two, and three sticks for your opponent: a P-position. Repeatedly applying this strategy guarantees victory.
 +
 
 +
====Nimbers in Nim====
 +
The '''nimber''' of a position in Nim is equal to its nim-sum, as defined above: the nimber of a single pile of sticks is simply the number of sticks in it, and the nimber of a collection of piles is the bitwise XOR of the nimbers of the individual piles.
 +
 
 +
===Disjunctive sum of games===
 +
In some cases, a position in a game may be analyzed as the '''disjunctive sum''' of two or more sub-positions of the same game. This means that a player chooses exactly one of those sub-positions and makes exactly one valid move in it. For example, if a Ni
  
 
===Statement of the theorem===
 
===Statement of the theorem===
The Sprague-Grundy theorem is the remarkable result that '''to any Nim-like game can be assigned a nimber'''.
+
The Sprague-Grundy theorem is the remarkable result that '''a nimber can be assigned to any configuration of any Nim-like game'''. This means that nimbers are useful in the analysis of not only Nim itself but of any Nim-like game. There are only a few simple rules for assigning nimbers:
 +
# A nimber is a non-negative integer.
 +
# The nimber of a position is the smallest possible value that does not appear among the nimbers of positions reachable from it in a single move. For example, if no moves are possible from a given configuration, the nimber is zero. If moves possible from a given configuration lead to other configurations with nimbers of 3, 0, 5, and 2, then the nimber for the given configuration is 1: the smallest non-negative integer that doesn't appear among these.
 +
# Suppose that a

Revision as of 18:09, 15 February 2010

Game theory is the formal study of mathematical games. The ultimate goal of game theory is usually to solve a game; that is, to determine the nature of an optimal strategy for each player, and the outcome of such a strategy. Often, solving a game entails lengthy calculations, necessitating the use of a computer. However, brute force computational power is usually insufficient and clever mathematical reasoning is needed to invent efficient algorithms. Thus, game theory lies at a crossroads between mathematics and computer science.

Basic concepts

The terms game, player, objective, and move denote axiomatic concepts in game theory and we will not attempt to define them here.

State

The state, position, or configuration of a game, loosely put, consists of exactly that information which determines the valid moves that can be made in the future and is itself modified when moves take place. In a deterministic game (see below), the state, taken together with the players' strategies, is sufficient and necessary to determine the game's outcome. In a nondeterministic game, the same combination is sufficient and necessary to determine the probabilities of the possible outcomes of the game.

Determinism

A deterministic game is one in which the decisions of the players, reflected in the moves they make, are sufficient to determine the game's outcome. The opposite is an indeterministic game. More simply, "games of chance" are nondeterministic, whereas pure strategy games with no element of chance are deterministic. Chess, for example, is a deterministic game, whereas backgammon is not. Deterministic games are of greater mathematical interest than nondeterministic games, but both can be studied with the aid of a computer.

Availability of information

When all players know the entire state of a game at any given time, the game is said to be perfect information. Perfect information games include chess, Go, and tic-tac-toe. Most games of interest in mathematics and computer science are perfect information games. Imperfect information games include most card games, as each player usually hides cards from opponents.

Partiality

An impartial game is one which satisfies two conditions:

  1. The valid moves from a given position depend only upon the position itself and not upon which player is to move next.
  2. The outcome of the game is symmetric with respect to the players.

Most games fail the first condition. Chess, for example, fails the first, since we must know if the player moving next is player 1 or player 2 to determine whether that player is to move a white piece or a black piece. Games failing the second condition are much rarer in serious mathematical study. Nim is a archetype for the impartial game; pieces are shared between the two players and each has the same goal.

Play convention

An important class of games consists of those between two players in which there are only two possible outcomes: victory and loss. If the winner is the last player who is able to make a legal move, the game is said to follow the normal play convention. Otherwise, it is said to follow the misère play convention. Dominoes is an example of a normal play game.

N-positions and P-positions

In a two-player, deterministic, impartial game which is guaranteed to end in a finite number of moves, an N-position is a configuration such that the next player to make a move can force victory, and a P-position is a configuration such that the previous player who moved can force victory. In a normal-play game, a configuration in which no further moves are possible is a P-position, since the player who is supposed to move next cannot do so and loses; in a misère-play game, it is an N-position, since the player who moved last made the last move and hence lost.

Consider a configuration C of such a game and the configurations C_1, C_2, C_3, ... reachable from it. If at least one of C_1, C_2, C_3, ... is a P-position, then the player presented with configuration C wants to make the move that results in that configuration, so that he or she becomes the previous player when the next player is to move --- guaranteeing victory. This makes C a N-position. If all of C_1, C_2, C_3, ... are N-positions, then no matter what move the current player makes, the next player can force victory, making C a P-position. In summary,

  • If all positions reachable in one move from position C are N-positions, then C is a P-position, and the current player does not have a winning strategy.
  • Otherwise (at least one P-position is reachable from C) C is an N-position, and a winning strategy necessarily entails leaving behind one of these P-positions for the next player.

Nimbers

A game which is

  • deterministic,
  • impartial,
  • normal play, and
  • guaranteed to end in a finite number of moves

can be analyzed using the Sprague-Grundy theorem. We shall denote such games as Nim-like. (Note that this term is not in use in the academic literature.)

Nim

The name nimber alludes to what is perhaps the simplest interesting example of such a game: Nim. The rules of the game are as follows:

  1. The game board consists of one or more piles of sticks.
  2. On a player's turn, he or she chooses one non-empty pile and removes one or more sticks from it.
  3. The first player who cannot make a move loses. (That is, the player who takes the last stick wins.)

It is deterministic because the outcome of the game depends entirely upon the players' decisions and not upon any element of chance, it is perfect-information because we assume that both players know the sizes of all piles at any time, it is impartial because any move available to one player is available to the other and because both players have the same goal, it is normal play because the last to move wins, and it is guaranteed to end in a finite number of moves because each move removes at least one stick from the total count of sticks in play.

Winning strategy

We state here the solution to Nim, a well-known result, and show later how it fits into the framework of Nim-like games in general. Simply compute the bitwise XOR of the sizes of all piles gives the nim-sum of a configuration of Nim. If this is zero, then the configuration is a P-position; otherwise it is an N-position. For example, if there are three piles containing one, two, and three sticks, respectively, the nim-sum is 1 XOR 2 XOR 3 = 0, and the configuration is a P-position; however, if instead of a three-stick pile we had a four-stick pile, the nim-sum would be instead 1 XOR 2 XOR 4 = 7, and the configuration would be a N-position.

If, on your turn, you are faced with a P-position, it doesn't matter what you do; your opponent can force you to lose. If, on the other hand, you are faced with an N-position, you want to leave a P-position for your opponent. In the example with one, two, and four sticks, you would want to take one stick from the four-stick pile, leaving behind one, two, and three sticks for your opponent: a P-position. Repeatedly applying this strategy guarantees victory.

Nimbers in Nim

The nimber of a position in Nim is equal to its nim-sum, as defined above: the nimber of a single pile of sticks is simply the number of sticks in it, and the nimber of a collection of piles is the bitwise XOR of the nimbers of the individual piles.

Disjunctive sum of games

In some cases, a position in a game may be analyzed as the disjunctive sum of two or more sub-positions of the same game. This means that a player chooses exactly one of those sub-positions and makes exactly one valid move in it. For example, if a Ni

Statement of the theorem

The Sprague-Grundy theorem is the remarkable result that a nimber can be assigned to any configuration of any Nim-like game. This means that nimbers are useful in the analysis of not only Nim itself but of any Nim-like game. There are only a few simple rules for assigning nimbers:

  1. A nimber is a non-negative integer.
  2. The nimber of a position is the smallest possible value that does not appear among the nimbers of positions reachable from it in a single move. For example, if no moves are possible from a given configuration, the nimber is zero. If moves possible from a given configuration lead to other configurations with nimbers of 3, 0, 5, and 2, then the nimber for the given configuration is 1: the smallest non-negative integer that doesn't appear among these.
  3. Suppose that a