1Mathematical GamesGreat Theoretical Ideas In Computer ScienceV. AdamchikD. SleatorCS 15-251 Spring 2010Lecture 10 Feb. 11, 2010 Carnegie Mellon UniversityPlanIntroduction toImpartial Combinatorial GamesRelated courses15-859, (21-801) -Mathematical GamesLook for it in Spring „1121 chipsTwo Players: 1 and 2A move consists of removing one, two, or three chips from the pilePlayers alternate moves, with Player 1 startingPlayer that removes the last chip winsA Take-Away GameWhich player would you rather be?2Try Small Examples!If there are 1, 2, or 3 only, player who moves next winsIf there are 4 chips left,player who moves next must leave 1, 2 or 3 chips, and his opponent will winWith 5, 6 or 7 chips left, the player who moves next can win by leaving 4 chips0, 4, 8, 12, 16, … are target positions; if a player moves to that position, they can win the gameTherefore, with 21 chips, Player 1 can win!21 chipsWhat if the last player to move loses?If there is 1 chip, the player who moves next losesIf there are 2,3, or 4 chips left, the player who moves next can win by leaving only 1In this case, 1, 5, 9, 13, … are a win for the second playerCombinatorial Games• A set of positions • Two players • Rules specify for each player and for each position which moves to other positions are legal moves • The players alternate moving • A terminal position in one in which there are no moves • The game ends when a player has no moves • The game must end in a finite number of moves • (No draws!) Normal Versus MisèreNormal Play Rule: The last player to move winsMisère Play Rule: The last player to move losesA Terminal Position is one where neither player can move anymoreWhat is OmittedNo random movesNo hidden stateNo draws in a finite number of moves(This rules out games like poker)(This rules out games like battleship)(This rules out tic-tac-toe)3Impartial Versus PartizanA combinatorial game is impartial if the same set of moves is available to both players in any position. A combinatorial game is partizan if themove sets may differ for the two players In this lecture we'll study impartial games. Partizan games will not be discussed P-Positions and N-PositionsP-Position: Positions that are winning for the Previous player (the player who just moved) (Sometimes called LOSING positions)N-Position: Positions that are winning for the Next player (the player who is about to move) (Sometimes called WINNING positions)0, 4, 8, 12, 16, … are P-positions; if a player moves to that position, they can win the game21 chips is an N-position21 chipsWhat‟s a P-Position? “Positions that are winning for the Previous player (the player who just moved)”That means:For any move that N makesThere exists a move for P such thatFor any move that N makesThere exists a move for P such that…There exists a move for P such thatThere are no possible moves for NP-positions and N-positions can be defined recursively by the following:(1) All terminal positions are P-positions (normal winning condition)(2) From every N-position, there is at least one move to a P-position(3) From every P-position, every move is to an N-positionChomp!Two-player game, where each move consists of taking a square and removing it and all squares to the right and above.Player who takes position (1,1) loses4Show That This is a P-positionN-Positions!Show That This is an N-positionP-position!Let‟s Play! I‟m player 1No matter what you do, I can mirror it!Mirroring is an extremely important strategy in combinatorial games!Theorem: Player 1 can win in any square starting position of ChompProof:The winning strategy for player 1 is to chomp on (2,2), leaving only an “L” shaped positionThen, for any move that Player 2 takes, Player 1 can simply mirror it on the flip side of the “L”5Theorem: Every rectangle is a N-positionProof: Consider this position:This is either a P or an N-position. If it‟s a P-position, then the original rectangle was N. If it‟s an N-position, then there exists a move from it to a P-position X.But by the geometry of the situation, X is also available as a move from the starting rectangle. It follows that the original rectangle is an N-position.The Game of Nimx y zTwo players take turns movingA move consists of selecting a pile and removing chips from it (you can take as many as you want, but you have to at least take one)In one move, you cannot remove chips from more than one pileWinner is the last player to remove chipsx y zWe use (x,y,z) to denote this position(0,0,0) is a:P-positionAnalyzing Simple PositionsOne-Pile NimWhat happens in positions of the form (x,0,0)?The first player can just take the entire pile, so (x,0,0) is an N-positionTwo-Pile NimP-positions are those for which the two piles have an equal number of chipsIf it is the opponent‟s turn to move from such a position, he must change to a position in which the two piles have different number of chipsFrom a position with an unequal number of chips, you can easily go to one with an equal number of chips (perhaps the terminal position)Nim-SumThe nim-sum of two non-negative integers is their addition without carry in base 2We will use to denote the nim-sum2 3 =5 3 =7 4 =(10)2 (11)2 = (01)2 = 1(101)2 (011)2 = (110)2 = 6(111)2 (100)2 = (011)2 = 3 is associative: (a b) c = a (b c) is commutative: a b = b a6For any non-negative integer x, x x =0Cancellation Property HoldsIf x y = x zThen x x y = x x zSo y = zBouton‟s Theorem: A position (x,y,z) in Nim is a P-position if and only if x y z = 0Let Z denote the set of Nim positions with nim-sum zero Proof:Let NZ denote the set of Nim positions with non-zero nim-sum We prove the theorem by proving that Z and NZ satisfy the three conditions of P-positions and N-positions (1) All terminal positions are in Z(2) From each position in NZ, there is a move to a position in ZThe only terminal position is (0,0,0)001010001100010111111010000010010110001010001100010111101000110000000000Look at leftmost column with an odd # of 1sRig any of the numbers with a 1 in that column so that everything adds up to zero(3) Every move from a position in Z is to a position in NZIf (x,y,z) is in Z, and x is changed tox < x, then we cannot havex y z = 0 = x y zBecause then x = xPart II - Sums of GamesConsider a game called Boxing Match which was defined in a programming contest
View Full Document