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

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

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

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

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

NIM Games: Handout 1

Game 0: One Pile, Last Chip Loses

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

On Modular Extensions to Nim

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

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

Obliged Sums of Games

ON SPLITTING UP PILES OF STONES

Game Playing Part 1 Minimax Search

CMPUT 396 Tic-Tac-Toe Game

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

SOME MORE DECREASE AND CONQUER ALGORITHMS

Module 3. Problem Solving using Search- (Two agent) Version 2 CSE IIT, Kharagpur

PRIMES STEP Plays Games

Senior Math Circles February 10, 2010 Game Theory II

CSC 380 Final Presentation. Connect 4 David Alligood, Scott Swiger, Jo Van Voorhis

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

The Galaxy. Christopher Gutierrez, Brenda Garcia, Katrina Nieh. August 18, 2012

CS885 Reinforcement Learning Lecture 13c: June 13, Adversarial Search [RusNor] Sec

Crossing Game Strategies

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

Surreal Numbers and Games. February 2010

Week 1. 1 What Is Combinatorics?

Presentation by Toy Designers: Max Ashley

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

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

Problem F. Chessboard Coloring

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

Eric Duchêne (Univ. Claude Bernard Lyon 1) Michel Rigo (University of Liège)

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

Stat 155: solutions to midterm exam

A Winning Strategy for the Game of Antonim

CS 540-2: Introduction to Artificial Intelligence Homework Assignment #2. Assigned: Monday, February 6 Due: Saturday, February 18

COMP3211 Project. Artificial Intelligence for Tron game. Group 7. Chiu Ka Wa ( ) Chun Wai Wong ( ) Ku Chun Kit ( )

On Variations of Nim and Chomp

of Nebraska - Lincoln

game tree complete all possible moves

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.

New Toads and Frogs Results

CS 188: Artificial Intelligence Spring 2007

Math 152: Applicable Mathematics and Computing

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

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

Adversarial Search 1

CS 229 Final Project: Using Reinforcement Learning to Play Othello

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

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

A Combinatorial Game Mathematical Strategy Planning Procedure for a Class of Chess Endgames

Introduction To Game Theory: Two-Person Games of Perfect Information and Winning Strategies. Wes Weimer, University of Virginia

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

mywbut.com Two agent games : alpha beta pruning

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

Solutions to Part I of Game Theory

Dice Games and Stochastic Dynamic Programming

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

Selected Game Examples

Game-playing AIs: Games and Adversarial Search I AIMA

ARTIFICIAL INTELLIGENCE (CS 370D)

Counting in Algorithms

Instability of Scoring Heuristic In games with value exchange, the heuristics are very bumpy Make smoothing assumptions search for "quiesence"

(b) In the position given in the figure below, find a winning move, if any. (b) In the position given in Figure 4.2, find a winning move, if any.

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

Analyzing ELLIE - the Story of a Combinatorial Game

GAMES AND STRATEGY BEGINNERS 12/03/2017

CS 188: Artificial Intelligence

VARIATIONS ON NARROW DOTS-AND-BOXES AND DOTS-AND-TRIANGLES

Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning

EXPLORING TIC-TAC-TOE VARIANTS

CSE : Python Programming

AI Approaches to Ultimate Tic-Tac-Toe

Game Simulation and Analysis

Alessandro Cincotti School of Information Science, Japan Advanced Institute of Science and Technology, Japan

CS188 Spring 2014 Section 3: Games

On Variants of Nim and Chomp

Artificial Intelligence. 4. Game Playing. Prof. Bojana Dalbelo Bašić Assoc. Prof. Jan Šnajder

THE GAME CREATION OPERATOR

Mohammad Hossein Manshaei 1394

1 In the Beginning the Numbers

arxiv: v2 [cs.cc] 18 Mar 2013

Analyzing Games: Solutions

Open Problems at the 2002 Dagstuhl Seminar on Algorithmic Combinatorial Game Theory

Positive Triangle Game

Game-playing AIs: Games and Adversarial Search FINAL SET (w/ pruning study examples) AIMA

INF September 25, The deadline is postponed to Tuesday, October 3

SF2972 Game Theory Written Exam March 17, 2011

A Brief Introduction to Game Theory

Homework Assignment #2

Counters in a Cup In and Out. The student sets up the cup, drops the counters on it, and records how many landed in and out of the cup.

Contest 1. October 20, 2009

Adversarial Search and Game Playing. Russell and Norvig: Chapter 5

One-Dimensional Peg Solitaire, and Duotaire

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

Games, Triangulations, Theory

Algorithms for Data Structures: Search for Games. Phillip Smith 27/11/13

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

Adversary Search. Ref: Chapter 5

Transcription:

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

Outline What is combinatorial game? Example 1: Simple Game Zero-Sum Game and Minimax Algorithms Nim Game Recommended Readings

Outline What is combinatorial game? Example 1: Simple Game Zero-Sum Game and Minimax Algorithms Nim Game Recommended Readings

Combinatorial Games Turn-based There are two players moving alternately; Each turn, the player changes the current state using a valid move. Perfect Information There are no chance devices (e.g., dices) and both players have perfect information. The rules are such that the game must eventually end; At some state, there are no valid moves and the game ends at this point Can be a simple win-or-lose game, or involve points (no draw!) Note: no cycles or cycles are always not optimal!

Outline What is combinatorial game? Example 1: Simple Game Zero-Sum Game and Minimax Algorithms Nim Game Recommended Readings

Example 1: Game Setting Rules There are n stones in a pile. Two players take turns. Each turn, the player removes either 1 or 3 stones. The one who takes the last stones wins. Goal Find out the winner if both players play perfectly Perfectly means that Players want to win! Players are smart enough!

Example 1: State & Move State x the number of remaining stones in the pile Valid moves from state x If x 1, x (x 1) If x 3, x x 3 State x = 0 is the losing state Because it has no valid move.

Example 1: Algorithm No cycles in the state transitions dynamic programming f(x) is a boolean value that whether the player starting with the state x can win the game A player wins if there is a way to force the opponent to lose Conversely, a player loses if there is no such way f x = f x 1 f(x 3) State x is the winning state if: (x 1) is the losing state OR (x 3) is the losing state Otherwise, x is the losing state O(n) solution get!

Example 1: More efficient? Let s solve the first few cases with DP DP tables for the first few values n 0 1 2 3 4 5 W/L L W L W L W What s the pattern? Let s prove our conjecture using induction

Example 1: Proof Conjecture: If n is odd, the first player wins. Othwerise, (i.e., n is even), the second player wins Clearly holds for n = 0 n 1 If n is odd, the resulting number of stones after taking away 1 or 3 stones is always even By the inductive argument, the next player loses, so the current player wins the game If n is even, the resulting number of stones is always odd By the inductive argument, the next player wins, so the current player loses the game

Outline What is combinatorial game? Example 1: Simple Game Zero-Sum Game and Minimax Algorithms Nim Game Recommended Readings

Zero-Sum Game: Game Setting Settings: Two players Zero-sum: If the first player s score is x, the other player gets x Each player tries to maximize his/her own score Both players play perfectly Can be solved using Minimax algorithm

Minimax Algorithm Recursive algorithm that decides the best move for the current player at a given state Let f(s) be the optimal score of the current player who starts at state S Let T S,1, T S,2,, T S,mS be states that can be reached from S using a single move m f S = max S i=1 f(t S,i ) Intuition: minimizing the opponent s score maximizes my score

Minmax Algorithm: Pseudocode Given state S, want to compute f(s) If we have computed f(s) Return f(s) // Memoize (refer to DP lecture) Set f S = For i = 1 to m S do f S = max f S, f T S,i Return f(s)

Zero-Sum Game: Extension Points are associated with moves The game is not zero-sum Each player wants to maximize his own score Each player wants to maximize the difference between his score and the opponent s There are more than two players All of the above can be solved using a similar idea

Example 2: Game Setting An array of n positive integers Two players take turns Each turn, the player can take a number at the either end of the array and add to his/her points and then the number disappears Players want to maximize their own scores If both play perfectly, output the score of each player

Example 2: State & Move State (i, j) - the remaining numbers are from the i-th index to the j-th index f(i, j) is the optimal score for the current player at state (i, j) Let sum(i, j) be the sum of the numbers from the i-th index to the j-th index Move Take the i-th number: i, j (i + 1, j) Take the j-th number: i, j (i, j 1)

Example 2: Algorithm Taking the i-th number: Optimal score for the next player at state (i + 1, j) is f(i + 1, j) So the player at state (i, j) will gain sum i, j f i + 1, j Taking the jth number: Similarly, will gain sum i, j f i, j 1 f i, j = max sum i, j f i + 1, j, sum i, j f(i, j 1) f i, j = sum i, j min f i + 1, j, f(i, j 1) The final answer: O(n 2 ) f 1, n sum 1, n f(1, n)

Outline What is combinatorial game? Example 1: Simple Game Zero-Sum Game and Minimax Algorithms Nim Game Recommended Readings

Nim Game: Setting Settings: n piles (heaps) of stones. Two players take turns. Each turn, the player chooses a pile, and removes any positive number of stones from the pile. The one who takes the last stones wins. Goal: Find out the winner if both play optimally

Nim Game: State & Move State The number of stones in all piles O m n state space, where m is the maximum number of stones in a single pile We can t really use DP since the state space will be huge for large number of piles

Nim Game: Example Starts with heaps of 3, 4, 5 stones Call them heap A, B, and C respectively Player 1 takes 2 stones from A: (1, 4, 5) Player 2 takes 4 from C: (1, 4, 1) Player 1 takes 4 from B: (1, 0, 1) Player 2 takes 1 from A: (0, 0, 1) Player 1 takes 1 from C and wins: (0, 0, 0)

Nim Game: Algorithm Given heaps of size n 1, n 2,, n m Claim The first player wins if and only if the nim sum, n 1 n 2 n m is nonzero (bitwise XOR operation: ^ in C/C++, Java, Python)

Nim Game: Proof Similar to Example 1: induction! It holds for the losing state (0,0,, 0) since the nim sum is 0. If the nim sum is 0, then whatever the current player does, nim sum of the next state is non-zero Because there is only one number changed If the nim sum is nonzero, it is possible to force it to become 0 Not obvious, but true Refer to Wikipedia for more details Proof of the winning formula in https://en.wikipedia.org/wiki/nim

Outline What is combinatorial game? Example 1: Simple Game Zero-Sum Game and Minimax Algorithms Nim Game Recommended Readings

Recommended Readings Sprague Grundy theorem Variations of Nim

Q&A