Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 4415-251Great Theoretical Ideas in Computer Science15-251Game Playing for Computer ScientistsCombinatorial GamesLecture 3 (September 2, 2008)21 chipsTwo Players: I and IIA move consists of removing one, two, or three chips from the pilePlayers alternate moves, with Player I startingPlayer that removes the last chip winsA Take-Away GameWhich player would you rather be?Try 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 I 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 GamesThere are two playersThere is a finite set of possible positionsThe rules of the game specify for both players and each position which moves to other positions are legal movesThe players alternate movingThe game ends 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 movesNo 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)P-Positions and N-PositionsP-Position: Positions that are winning for the Previous player (the player who just moved)N-Position: Positions that are winning for the Next player (the player who is about to move)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(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 (0,0) losesShow That This is a P-positionN-Positions!Show That This is an N-positionP-position!Let’s Play! I’m player INo matter what you do, I can mirror it!Mirroring is an extremely important strategy in combinatorial games!Theorem: Player I can win in any square starting position of ChompProof:The winning strategy for player I is to chomp on (1,1), leaving only an “L” shaped positionThen, for any move that Player II takes, Player I can simply mirror it on the flip side of the “L”What about rectangular boards?What about rectangular boards?What about rectangular boards?Theorem: Player I can win in any rectangular starting positionProof:Look at this first move:If this is a P-position, then player 1 winsOtherwise, there exists a P-position that can be obtained from this positionAnd player I could have just taken that move originallyMove-the-TokenTwo-player game, where each move consists of taking the token and moving it either downwards or to the left (but not both).Player who makes the last move - to (0,0) - winsThe 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 NimSeen this before?It’s the “Move-the-Token” gameTwo-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)3-Pile Nimx y zTwo players take turns movingWinner is the last player to remove chipsNim-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 aFor 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 = 0 Let 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 to x < x, then we cannot havex y z = 0 = x y zBecause then x = xk-Pile NimHere’s What You Need to Know…Combinatorial Games• P-positions versus N-positions• When
View Full Document