Nim, nim.py and games.py Homework 4 Problem 4. The History of Nim Games Believed to have been created in China; unknown date of origin First actual recorded.

Slides:



Advertisements
Similar presentations
Game Playing CS 63 Chapter 6
Advertisements

ICAMP: Game Simulation and Analysis Analysis of the Game “Poison” Sarah Eichhorn University of California Irvine iCAMP Overview Meeting, 5/5/10.
Martin Boyd Christopher Hirunthanakorn
Adversarial Search We have experience in search where we assume that we are the only intelligent being and we have explicit control over the “world”. Lets.
Introduction to Combinatorial Game Acm Honored Class Weitao.
For Friday Finish chapter 5 Program 1, Milestone 1 due.
Artificial Intelligence Adversarial search Fall 2008 professor: Luigi Ceccaroni.
CS 484 – Artificial Intelligence
Lecture 12 Last time: CSPs, backtracking, forward checking Today: Game Playing.
Search Strategies.  Tries – for word searchers, spell checking, spelling corrections  Digital Search Trees – for searching for frequent keys (in text,
Minimax and Alpha-Beta Reduction Borrows from Spring 2006 CS 440 Lecture Slides.
Progressively Finite Games
CompSci Recursion & Minimax Playing Against the Computer Recursion & the Minimax Algorithm Key to Acing Computer Science If you understand everything,
Game Playing CSC361 AI CSC361: Game Playing.
The Game of Nim on Graphs: NimG Gwendolyn Stockman Alan Frieze and Juan Vera.
1 search CS 331/531 Dr M M Awais A* Examples:. 2 search CS 331/531 Dr M M Awais 8-Puzzle f(N) = g(N) + h(N)
Game-Playing Read Chapter 6 Adversarial Search. Game Types Two-person games vs multi-person –chess vs monopoly Perfect Information vs Imperfect –checkers.
Adversarial Search: Game Playing Reading: Chess paper.
Using Reduction for the Game of NIM. At each turn, a player chooses one pile and removes some sticks. The player who takes the last stick wins. Problem:
Alpha-Beta Search. 2 Two-player games The object of a search is to find a path from the starting position to a goal position In a puzzle-type problem,
Time for playing games Form pairs You will get a sheet of paper to play games with You will have 12 minutes to play the games and turn them in.
Game-Playing Read Chapter 6 Adversarial Search. State-Space Model Modified States the same Operators depend on whose turn Goal: As before: win or win.
Game Playing: Adversarial Search Chapter 6. Why study games Fun Clear criteria for success Interesting, hard problems which require minimal “initial structure”
Great Theoretical Ideas in Computer Science.
Great Theoretical Ideas in Computer Science.
1 Adversary Search Ref: Chapter 5. 2 Games & A.I. Easy to measure success Easy to represent states Small number of operators Comparison against humans.
Lecture 5 Note: Some slides and/or pictures are adapted from Lecture slides / Books of Dr Zafar Alvi. Text Book - Aritificial Intelligence Illuminated.
Game Playing Chapter 5. Game playing §Search applied to a problem against an adversary l some actions are not under the control of the problem-solver.
Game Playing. Introduction Why is game playing so interesting from an AI point of view? –Game Playing is harder then common searching The search space.
Game Playing.
MOM! Phineas and Ferb are … Aims:
AD FOR GAMES Lecture 4. M INIMAX AND A LPHA -B ETA R EDUCTION Borrows from Spring 2006 CS 440 Lecture Slides.
Probability (Grade 12) Daljit Dhaliwal. Sticks and Stones game.
Traditional game playing 2 player adversarial (win => lose) based on search but... huge game trees can't be fully explored.
Mark Dunlop, Computer and Information Sciences, Strathclyde University 1 Algorithms & Complexity 5 Games Mark D Dunlop.
Game-playing AIs Part 1 CIS 391 Fall CSE Intro to AI 2 Games: Outline of Unit Part I (this set of slides)  Motivation  Game Trees  Evaluation.
For Wednesday Read Weiss, chapter 12, section 2 Homework: –Weiss, chapter 10, exercise 36 Program 5 due.
For Friday Finish reading chapter 7 Homework: –Chapter 6, exercises 1 (all) and 3 (a-c only)
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
For Wednesday Read chapter 7, sections 1-4 Homework: –Chapter 6, exercise 1.
Search exploring the consequences of possible actions.
Game Playing. Introduction One of the earliest areas in artificial intelligence is game playing. Two-person zero-sum game. Games for which the state space.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
For Friday Finish chapter 6 Program 1, Milestone 1 due.
GAME PLAYING 1. There were two reasons that games appeared to be a good domain in which to explore machine intelligence: 1.They provide a structured task.
Copyright © 2002, Department of Systems and Computer Engineering, Carleton University 1 Exercise 6 This assignment is probably best started by running.
An Introduction to Game Theory Math 480: Mathematics Seminar Dr. Sylvester.
ARTIFICIAL INTELLIGENCE (CS 461D) Princess Nora University Faculty of Computer & Information Systems.
Graph Search II GAM 376 Robin Burke. Outline Homework #3 Graph search review DFS, BFS A* search Iterative beam search IA* search Search in turn-based.
The Standard Genetic Algorithm Start with a “population” of “individuals” Rank these individuals according to their “fitness” Select pairs of individuals.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Adversarial Search. Regular Tic Tac Toe Play a few games. –What is the expected outcome –What kinds of moves “guarantee” that?
AIMA Code: Adversarial Search CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth February 2005.
Adversarial Search and Game Playing Russell and Norvig: Chapter 6 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2004/home.htm Prof: Dekang.
Benjamin Casey C S 329 E Spring  Variants played since ancient times; resemblance to Chinese “Jianshizi” or “picking stones”  Current name and.
Chapter 5 Adversarial Search. 5.1 Games Why Study Game Playing? Games allow us to experiment with easier versions of real-world situations Hostile agents.
CMPT 463. What will be covered A* search Local search Game tree Constraint satisfaction problems (CSP)
Content Game of Nim Impartial Games Sprague-Grundy theorem
Adversarial Search and Game-Playing
Great Theoretical Ideas in Computer Science
Nim, nim.py and games.py Homework 4 Problem 4.
Adversarial Search.
Game Playing.
Nim Game Lesson1 Compendium , page 173 Guidebook , page 127 THE LESSON Lesson Title: NIM lesson1 Date: Length of the Lesson: 45 minutes.
Announcements Homework 3 due today (grace period through Friday)
Nim Game Lesson1 Compendium , page 173 Guidebook , page 127 THE LESSON Lesson Title: NIM lesson1 Date: Length of the Lesson: 45 minutes.
CSE (c) S. Tanimoto, 2007 Search 2: AlphaBeta Pruning
CS51A David Kauchak Spring 2019
Unit II Game Playing.
Presentation transcript:

Nim, nim.py and games.py Homework 4 Problem 4

The History of Nim Games Believed to have been created in China; unknown date of origin First actual recorded date- 15 th century Europe Originally known as Tsyanshidzi meaning “picking stones game” Presently comes from German word “nimm” meaning “take” Adapted from a presentation by Tim Larson and Danny Livarchik

Rules of Nim Impartial game of mathematical strategy Strictly two players Alternate turns removing any number of items from any ONE heap until no pieces remain Must remove at least one item per turn Last player to be able to remove a wins Variations: –Initial number of heaps and items in each –Misere play: last player who can move loses –Limit on number of items that can be removed

Demonstration Player 1 wins!

Theoretical Approach Theorem developed by Charles Bouton in 1901 This states that in order to win, the goal is to reach a nim-sum of 0 after each turn until all turns are finished Nim Sum: evaluated by taking the exclusive-or of the corresponding numbers when the numbers are given in binary form Exclusive-or is used for adding two or more numbers in binary and it basically ignores all carries

Tree for (2,1)

Tree for (2,2)

games.py Peter Norvig’s python framework for multiple- player, turn taking games Implements minimax and alphabeta For a new game, subclass the Game class –Decide how to represent the “board” –Decide how to represent a move –A state is (minimally) a board and whose turn to move –Write methods to (1) initialize game instance, (2) generate legal moves from a state, (3) make a move in state, (4) recognize terminal states (win, lose or draw), (5) compute utility of a state for a player, (5) display a state

Assumptions about states games.py assumes that your representation of a state is a object with at least two attributes: to_move and board The Struct class defined in utils.py can be used to create such instances –s = Struct(foo=‘a’, to_move = 1, board = [[1][2][3]]) –Access the attributes as s.to-move, etc.

Caution Python lists are mutable objects If you use a list to represent a board and whant to generate a new board from it, you probably want to copy it fist new_board = board[:] new_board[3] = new_board[3] - 1

Players The games.py framework defines several players random_player: choses a random move from among legal moves alphabeta_player: uses alpha_beta to choose best move, optional args specify cutoff depth (default is 8) and some other variations human_player: asks user to enter move

Variations def make_alphabeta_player(N): """ returns a player function that uses alpha_beta search to depth N """ return lambda game, state: alphabeta_search(state, game, d=N) # add to the PLAYER dictionary player function named ab1,ab2,...ab20 # that use alpha_beta search with depth cutoffs between 1 and 20 for i in range(20): PLAYER['ab'+str(i)] = make_alphabeta_player(i)