Background. Game Theory and Nim. The Game of Nim. Game is Finite 1/27/2011

Similar documents
Game Theory and Algorithms Lecture 19: Nim & Impartial Combinatorial Games

Plan. Related courses. A Take-Away Game. Mathematical Games , (21-801) - Mathematical Games Look for it in Spring 11

Math 152: Applicable Mathematics and Computing

Senior Math Circles February 10, 2010 Game Theory II

Tangent: Boromean Rings. The Beer Can Game. Plan. A Take-Away Game. Mathematical Games I. Introduction to Impartial Combinatorial Games

Sequential games. We may play the dating game as a sequential game. In this case, one player, say Connie, makes a choice before the other.

Combined Games. Block, Alexander Huang, Boao. icamp Summer Research Program University of California, Irvine Irvine, CA

ON SPLITTING UP PILES OF STONES

Tutorial 1. (ii) There are finite many possible positions. (iii) The players take turns to make moves.

Obliged Sums of Games

Contents. MA 327/ECO 327 Introduction to Game Theory Fall 2017 Notes. 1 Wednesday, August Friday, August Monday, August 28 6

Jim and Nim. Japheth Wood New York Math Circle. August 6, 2011

CS 491 CAP Intro to Combinatorial Games. Jingbo Shang University of Illinois at Urbana-Champaign Nov 4, 2016

On Variants of Nim and Chomp

Crossing Game Strategies

Advanced Automata Theory 4 Games

EXPLORING TIC-TAC-TOE VARIANTS

On Variations of Nim and Chomp

GAMES AND STRATEGY BEGINNERS 12/03/2017

1, 2,, 10. Example game. Pieces and Board: This game is played on a 1 by 10 board. The initial position is an empty board.

Final Exam, Math 6105

STAJSIC, DAVORIN, M.A. Combinatorial Game Theory (2010) Directed by Dr. Clifford Smyth. pp.40

Grade 7 & 8 Math Circles. Mathematical Games

Numan Sheikh FC College Lahore

Advanced Microeconomics: Game Theory

V. Adamchik Data Structures. Game Trees. Lecture 1. Apr. 05, Plan: 1. Introduction. 2. Game of NIM. 3. Minimax

Solutions to Part I of Game Theory

of Nebraska - Lincoln

Introduction to Auction Theory: Or How it Sometimes

Formidable Fourteen Puzzle = 6. Boxing Match Example. Part II - Sums of Games. Sums of Games. Example Contd. Mathematical Games II Sums of Games

PRIMES STEP Plays Games

SOME MORE DECREASE AND CONQUER ALGORITHMS

ARTIFICIAL INTELLIGENCE (CS 370D)

Subtraction games with expandable subtraction sets

CSE 20 DISCRETE MATH. Fall

Game Theory Lecturer: Ji Liu Thanks for Jerry Zhu's slides

Selected Game Examples

Checkpoint Questions Due Monday, October 7 at 2:15 PM Remaining Questions Due Friday, October 11 at 2:15 PM

A variation on the game SET

Legend. The Red Goal. The. Blue. Goal

NIM WITH A MODULAR MULLER TWIST. Hillevi Gavel Department of Mathematics and Physics, Mälardalen University, Västerås, Sweden

Mathematical Investigation of Games of "Take-Away"

Analysis of Don't Break the Ice

CMPUT 396 Tic-Tac-Toe Game

Analyzing ELLIE - the Story of a Combinatorial Game

Graph Nim. PURE Insights. Breeann Flesch Western Oregon University,

Analyzing Games: Solutions

Three Pile Nim with Move Blocking. Arthur Holshouser. Harold Reiter.

The Hex game and its mathematical side

Mathematics. Programming

Math Circle: Logic Puzzles

NIM Games: Handout 1

Adversary Search. Ref: Chapter 5

Game 0: One Pile, Last Chip Loses

game tree complete all possible moves

Binary Games. Keep this tetrahedron handy, we will use it when we play the game of Nim.

Game-playing AIs: Games and Adversarial Search I AIMA

Circular Nim Games. S. Heubach 1 M. Dufour 2. May 7, 2010 Math Colloquium, Cal Poly San Luis Obispo

Introduction Solvability Rules Computer Solution Implementation. Connect Four. March 9, Connect Four 1

Figure 1: A Checker-Stacks Position

JUSTIN. 2. Go play the following game with Justin. This is a two player game with piles of coins. On her turn, a player does one of the following:

Definition 1 (Game). For us, a game will be any series of alternating moves between two players where one player must win.

On Drawn K-In-A-Row Games

THE GAME CREATION OPERATOR

The tenure game. The tenure game. Winning strategies for the tenure game. Winning condition for the tenure game

Some Unusual Applications of Math

CHECKMATE! A Brief Introduction to Game Theory. Dan Garcia UC Berkeley. The World. Kasparov

MATH LEVEL 2 LESSON PLAN 3 FACTORING Copyright Vinay Agarwala, Checked: 1/19/18

The Mathematics of Playing Tic Tac Toe

Problem F. Chessboard Coloring


Tic-Tac-Toe on graphs

Positive Triangle Game

Game, Set, and Match Carl W. Lee September 2016

Math Games Ideas. For School or Home Education. by Teresa Evans. Copyright 2005 Teresa Evans. All rights reserved.

GAME THEORY. Thomas S. Ferguson

o o o o o o o o o o o o

A Winning Strategy for the Game of Antonim

CS103 Handout 25 Spring 2017 May 5, 2017 Problem Set 5

Grade 7/8 Math Circles Game Theory October 27/28, 2015

Lecture 33: How can computation Win games against you? Chess: Mechanical Turk

STRATEGY AND COMPLEXITY OF THE GAME OF SQUARES

CSE 332: Data Structures and Parallelism Games, Minimax, and Alpha-Beta Pruning. Playing Games. X s Turn. O s Turn. X s Turn.

Playing Games. Henry Z. Lo. June 23, We consider writing AI to play games with the following properties:

Computer Science and Software Engineering University of Wisconsin - Platteville. 4. Game Play. CS 3030 Lecture Notes Yan Shi UW-Platteville

Unit 12: Artificial Intelligence CS 101, Fall 2018

Math 127: Equivalence Relations

Copyright 2010 DigiPen Institute Of Technology and DigiPen (USA) Corporation. All rights reserved.

New Toads and Frogs Results

Grade 6 Math Circles Combinatorial Games - Solutions November 3/4, 2015

Impartial Combinatorial Games Berkeley Math Circle Intermediate II Ted Alper Evans Hall, room 740 Sept 1, 2015

The game of Reversi was invented around 1880 by two. Englishmen, Lewis Waterman and John W. Mollett. It later became

arxiv: v2 [cs.cc] 18 Mar 2013

PROBLEMS & INVESTIGATIONS. Introducing Add to 15 & 15-Tac-Toe

CS 4700: Artificial Intelligence

Which Rectangular Chessboards Have a Bishop s Tour?

Advanced Automata Theory 5 Infinite Games

The first player, Fred, turns on the calculator, presses a digit key and then presses the

Two Parity Puzzles Related to Generalized Space-Filling Peano Curve Constructions and Some Beautiful Silk Scarves

Sept. 26, 2012

Transcription:

Background Game Theory and Nim Dr. Michael Canjar Department of Mathematics, Computer Science and Software Engineering University of Detroit Mercy 26 January 2010 Nimis a simple game, easy to play. It illustrates basic principles of Game Theory. Very Elegant solution to it easily accessible to Math and CS students. (Just need Binary Numbers.) Makes a Nice Math-CS Club Talk I first learned about it in 1983, from Dr. Richard Stark at St Mary s College of Maryland. http://www.smcm.edu/catalog/directory/faculty.html There is a Wikipedia article on it, which has gotten better, but still not as clear as Stark s treatment of it. http://en.wikipedia.org/wiki/nim 1/27/2011 11:59:22 AM 1 1/27/2011 11:59:22 AM 2 The Game of Nim Nimis a two player game, in which players take turns on alternate moves. A NimBoard consists of several piles of objects, such as A B C D x xxxx xx xxx x I will describe this Board as [ 5 2 3 1 ] In each turn, players must pick up some ( 1) of the objects, but from only one pile. In Example, we have 11 possible moves. We could pick up From A : 1,2,3,4 or 5 From B: 1 or 2 objects From C : 1, 2 or 3 objects. From D : 1 object Game is Finite Nimis a game in which players take alternate turns. On each turns they must pick up some objects but from only one pile. Obviously, the game will eventually ends. No loops. In my Example: A B C D x xxxx xx xxx x 5 2 3 1 The game can t last beyond 11 moves, because there are 11 objects, and that number goes down each turn. 1/27/2011 11:59:22 AM 3 1/27/2011 11:59:22 AM 4 1

Object of the Game Nimis a game in which players take alternate turns. On each turns they must pick up some objects but from only one pile. Obviously, the game ends when the last piece is picked up. What is the Object of the Game? Who Wins? Two Variations on the Rules : 1. The Last Player wins sometimes called Normal game 2. The Last Player loses sometimes called amiseregame. Version 2 (Misere) is the more common. Note that No Ties (unlike Tic TacToe). Demonstration Via Computer 1/27/2011 11:59:22 AM 5 1/27/2011 11:59:22 AM 6 Demonstration Simple Computer Game From Most Boards the computer usually wins. That is, the computer can force a win, being able to cleverly counter any move that we make. For some Boards, we can force a win, if we play properly and make no errors. Question: Determine the Winning Strategy Characterize the Winning Positions and the proper responses. Interesting Feature: That for most of the game, we don t need to know the rules to make the correct play. A Little Game Theory We will say that a Board is a Winning Board (WB) or Winning Position if the current player can force a win from that position. We will say that a Board is Losing Board (LB) or Losing Position if the opponent can force a win (Opponent can counter to every move we make.) Say that a Board is non-determined (ND) if is neither a Winning Board or a Losing Board. Theorem : Every NimBoard is either a WB or a LB i.e. there are no ND Boards. (in any Nimgame, one of the players can force a win.) 1/27/2011 11:59:22 AM 7 1/27/2011 11:59:22 AM 8 2

Tic Tac Toe Example Recursive Definition O X X s turn: X has a Winning Position X O X O s turn after X has made a winning move. Ohas a Losing Position A Board is a LB if for every move we can make gives our opponent a WB A Board is a WB is we have some move to a LB. The terminal state (Empty Board) is specified by the Rules Final Board is a WB for Nim-Misere Game Final Board is a LB for Nim-Normal game This quasi-circular definition is an example of recursion. 1/27/2011 11:59:22 AM 9 1/27/2011 11:59:22 AM 10 Sketch of Proof Theorem : Every NimBoard is either a Winning Position or a Losing Position i.e. There are no Non-Determined (ND) Nim Boards. For contradiction, let B 0 be an ND Board. This means that there is a move M : B 0 B 1 which keeps the player alive. [B 1 is not WB] But B 1 is not a LB, since otherwise B 0 would be WB. So B 1 is an ND Board. Same argument shows that there is move from B 1 to an ND Board B 2. We get a chain of ND Boards B 0 B 1 B 2.. B N But this is an infinite loop, contradiction. Elements of the Proof Properties of Nimthat were used 1. There are no loops. All Games end. ( Tree is well-founded ). 2. Each game ends with a Winner (and a Loser ). That is No Ties. The Theorem applies to such Games in the same genre: Perfect Information with No Random Elements. 1/27/2011 11:59:22 AM 11 1/27/2011 11:59:22 AM 12 3

Given a NimBoard : The Issues Determine if it is a Winning Board or a Losing Board If is a WB, find (all possible) winning moves. This function is called a Winning Strategy. Brute Force Recursive Solution Given a Board B If it is empty (terminal) Apply Game Rules. Otherwise: Consider each possible Move Look at the Board Produced. Apply the Algorithm to that Board If any such Board is a LB then B is WB else (all Boards are WB) then B is LB Can Visualize with a Tree. This is a Top Down Algorithm. 1/27/2011 11:59:22 AM 13 1/27/2011 11:59:22 AM 14 Bottom Up Iterative Algorithm Our analysis of Nim lends itself to an iterative approach: Loop for N=0,1,2,3, Analyze all sub-boards with N elements. At each you store the Results. You use the results of the previous stage. In Tree, we are working from the Bottom Up Can Use this to prove Theorem by Induction. * Easier with Odometer Order ( 001, 002, 00M, 010, 011 ) [Code as a Base M numeral] Are we done? Problem : Given a NimBoard : Determine if it is a Winning Board or a Losing Board If is a WB, find (all possible) winning moves. This function is called a Winning Strategy. Our Brute Methods do Work But... 1/27/2011 11:59:22 AM 15 1/27/2011 11:59:22 AM 16 4

Disadvantages of Brute Force A Mathematician would like an elegant solution. Some closed form method that will compute the winning moves from a Board. A Computer Scientist is concerned with Complexity Issues- running time and memory. If we consider NxMNimGames (N piles of < M objects), the # of sub-boards is M N For 10x10 games, we have 10 Billion. Let us work on a direct method. Example We will see that the Board { 73 69 57 21 20 } is a Winning Board, which admits only one winning move (out of 240 possibilities): { 73 69 13 21 20 } The number of sub-boards is 73 x 69 x 57 x 21 x 20 = 120,585,780 Before we are done, will put the computation of the winning move on one slide. Easy with Binary Number 1/27/2011 11:59:22 AM 17 1/27/2011 11:59:22 AM 18 Binary Numbers Our Solution will involve Base-2 Numbers. The decimal number 167 is 1 x 10 2 + 6 x 10 1 + 7 x 10 0 In Binary is represented as 1010011 1 1x2 7 +0x2 6 +1x2 5 +0x2 4 +0x2 3 +1x2 2 +1x2 1 +1x2 0 128 32 4 2 1 Converting to Binary Example : Convert 13 decimal to Base-2 Divide 13 by 2 : Quotient = 6 Remainder = 1 Divide 6 by 2 : Quotient is 3 Remainder = 0 Divide 3 by 2 Quotient is 1 Remainder = 1 Divide 1 by 2 Quotient=0 Remainder = 1 Done : Quotient of 0 : 1 1 0 1 1/27/2011 11:59:22 AM 19 1/27/2011 11:59:22 AM 20 5

NimBoards in Binary Given a Board [ X 1 X 2... X n ] Express the numbers in Binary and list them in column, lining up their respective bits in columns. In each Column compute the Sum of Bits, and classify the column as to whether or not this is Even or Odd. Call Board an Even Position if everycolumn is even. Call it an Odd Positionif anycolumn is Odd. (Of course, most positions are Odd. ) [Preview: Non-Trivial Odd Positions are Winning Non-Trivial Even Positions are Losing ] 1/27/2011 11:59:22 AM 21 Example [9 8 5 4] 9 1 0 0 1 8 1 0 0 0 5 0 1 0 1 4 0 1 0 0 Parity: [ 9854 ] is even [ 985 x ] is odd (x 4 ) [ 98 x 4 ] is odd (x 5 ) [ 9 x 54 ] is odd (x 8 ) [ x 854 ] is odd (x 9) If Every Col. Is Even, Board is Even If Any Col. Is Odd, the Board is Odd. 9 1 0 0 1 8 1 0 0 0 5 0 1 0 1 2 0 0 1 0 Parity: Even Odd Odd Even 1 0 0 0 1 8 1 0 0 0 5 0 1 0 1 4 0 1 0 0 1/27/201111:59:22 AM Odd Even Even Even 22 E-Lemma E-Lemma: Every Move from an Even Position results in an Odd Position. Proof: Any move changes only one row and must change at least one bit, which changes he parity of that column from Even Odd Odd Even Ex: [11 7 10] 7 0 1 1 1 Even Odd Odd Even 13 1 1 0 1 7 0 1 1 1 1 0 0 0 1 Adds 2 Subt 6 What about Odd Positions? Next Lemma will be: O-Lemma: From an Odd Position there is at least one move that results in an Even Position. 1/27/2011 11:59:22 AM 23 Need to Change Col 4 & 2 7 0 1 1 1 Adds 2 3 Piles (Rows) to Try : 12 1 1 0 0 Change each bit in Odd Cols 1/27/201111:59:22 AM 24 6

Odd Even Summary Given Odd Position In each Pile, there is a move to an Even Position, by changing the bits in odd columns. Not all are legal NimMoves. Need the first bit change to be 1 0 But Must be at least one 1 in first Odd Col since a cols of all 0s would be even. 1/27/2011 11:59:22 AM 25 Odd Even Ex: [11 7 10] 7 0 1 1 1 Even Odd Odd Even Given Odd Position In each Pile, can move to Even Pos : change the bits in odd cols. Not all are legal NimMoves. Need the first bit changed is 1 Have at least one 1 in the first Odd Col, since all 0s is Even. 13 1 1 0 1 7 0 1 1 1 1 0 0 0 1 7 0 1 1 1 12 1 1 0 0 Adds 2 Subt 6 Adds 2 1/27/2011 11:59:22 AM 26 Example: [73 69 57 21 20 ] 64 32 16 Example: [73 69 57 21 20 ] Only 1 Move [73 69 1321 20 ] 64 32 16 73 1 0 0 1 0 0 1 69 1 0 0 0 1 0 1 57 0 1 1 1 0 0 1 21 0 0 1 0 1 0 1 20 0 0 1 0 1 0 0 Need 1 in First Odd Col : 32 73 1 0 0 1 0 0 1 69 1 0 0 0 1 0 1 13 0 0 0 1 1 0 1 21 0 0 1 0 1 0 1 20 0 0 1 0 1 0 0 Need 1 in First Odd Col : 32 Even Odd Odd Even Odd Even Even Even Even Even Need to Change Col 32, 16, & 4 Need to Change Col 32, 16, & 4 1/27/2011 11:59:22 AM 27 1/27/2011 11:59:22 AM 28 7

Odd Even Algorithm O-Lemma : Given an Odd Position, there is at least one move to an Even Pos. In the first Odd Col, find one row (pile) in which there is a 1 Must be at least one 1 in the first Odd Col, since all 0s is Even In that Pile, change the bits in each Odd Col.. Winning Strategy (Even-Odd Strat) OL : Every Move from an Odd Position produces an Even Position. EL: From an Even Position, there is a move to an Odd Position. Always Give your opponents an Even Position They returns an Odd Position... Since the Empty Board is Even, this will win every Normal Game But, it loses every MisereGame. Need a little tweaking! D-Lemma 1/27/2011 11:59:22 AM 29 1/27/2011 11:59:22 AM 30 Trivial Games Call a pile a Singletonif it has 1 elements. Call a board Trivial if all non-empty piles are singletons, let B = a trivial Board with N non-empty piles : [ 1 1 1 1 1. 1 ] <N singletons > If N =1: we pick last object. Win Normal Game, Lose MisereGame. If N =2 : Opponent takes last object. Win Misere Game, Lose Normal Game. N =3: Wins Normal, Loses MisereGame N=4 Win Misere Game, Lose Normal Game. Note that there is no real choice here. Characterization of Trivial Boards L B be trivial board consisting of N objects. (N piles of 1 element each.) If N is Even Normal Game: B is LB MisereGame : B is WB If N is Odd Normal Game: B is WB MisereGame : B is LB 1/27/2011 11:59:22 AM 31 1/27/2011 11:59:22 AM 32 8

Decisive Positions Call a Board a Decisive Position if it contains exactly one non-singleton. Example: 17 1 1 1... 1 Pick from the 17 pile and either take it all or leave only 1 (depending on Rules) Result is a Trivial Board. Control whether we leave an Even or Odd number of Singletons. D-Lemma: A Decisive Position is a Winning Position for both types of Games. DP Example D-Lemma: A Decisive Position is a Winning Position for both types of Games. Given 4 piles: [ 13 1 1 1 ] If I want you to have an even number of singletons (Normal Game) I pick up 12 [1 1 1 1] If I want you to have an odd number of singletons (Misere Game) I pick up all 13 [ 0 1 1 1 ] 1/27/2011 11:59:22 AM 33 1/27/2011 11:59:22 AM 34 Existence of DP Any play of non-trivial Game will pass through a Decisive Position. There will be last non-trivial position and that must be Decisive. [ Each move can only reduce the number on non-singletons by 1. Eventually get one with exactly 1 non-singleton ] Summary Even-Odd Plan: Given an Odd Position which is not decisive, return an even position. Opponent will return Odd Position The Decisive Pos is winning for both Rules. The Even-Odd Plan wins all Normal Games. The Decisive Position must be Odd. [Can Do this by direct computation Exercise] 1/27/2011 11:59:22 AM 35 1/27/2011 11:59:22 AM 36 9

Complete Characterization A non-trivial Board is a WB iffit is Odd. Given Odd Board, we give our opponent an Even Board, until we have a Decisive Position. At the DP, we consult the rules and leave our opponent a trivial Board. Consult the Rule to decide whether to leave even/odd # of singletons. A Trivial Board is WB/LB depending on its parity (even/odd # of piles) N and the Rules of the Game. The move at Decisive Position is the onlytime we pay attention to the rules. End Slides 1/27/2011 11:59:22 AM 37 1/27/2011 11:59:22 AM 38 10