Computer Game Programming Board Games

Similar documents
ARTIFICIAL INTELLIGENCE (CS 370D)

Adversary Search. Ref: Chapter 5

Adversarial Search 1

CMPUT 396 Tic-Tac-Toe Game

Games (adversarial search problems)

Programming Project 1: Pacman (Due )

CS 2710 Foundations of AI. Lecture 9. Adversarial search. CS 2710 Foundations of AI. Game search

Foundations of Artificial Intelligence

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

Adversarial Search. Rob Platt Northeastern University. Some images and slides are used from: AIMA CS188 UC Berkeley

CSE 473: Artificial Intelligence Fall Outline. Types of Games. Deterministic Games. Previously: Single-Agent Trees. Previously: Value of a State

2 person perfect information

Adversarial Search. Human-aware Robotics. 2018/01/25 Chapter 5 in R&N 3rd Ø Announcement: Slides for this lecture are here:

ADVERSARIAL SEARCH. Today. Reading. Goals. AIMA Chapter , 5.7,5.8

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

CS 1571 Introduction to AI Lecture 12. Adversarial search. CS 1571 Intro to AI. Announcements

Artificial Intelligence 1: game playing

Artificial Intelligence. Minimax and alpha-beta pruning

mywbut.com Two agent games : alpha beta pruning

CS 5522: Artificial Intelligence II

ADVERSARIAL SEARCH. Today. Reading. Goals. AIMA Chapter Read , Skim 5.7

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

Adversarial Search. Robert Platt Northeastern University. Some images and slides are used from: 1. CS188 UC Berkeley 2. RN, AIMA

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

Game-Playing & Adversarial Search

CS440/ECE448 Lecture 9: Minimax Search. Slides by Svetlana Lazebnik 9/2016 Modified by Mark Hasegawa-Johnson 9/2017

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

Game Playing State-of-the-Art

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

CS 188: Artificial Intelligence

game tree complete all possible moves

Adversarial Search and Game- Playing C H A P T E R 6 C M P T : S P R I N G H A S S A N K H O S R A V I

Game Playing State-of-the-Art. CS 188: Artificial Intelligence. Behavior from Computation. Video of Demo Mystery Pacman. Adversarial Search

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

Game-playing AIs: Games and Adversarial Search I AIMA

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

Game Playing State-of-the-Art CSE 473: Artificial Intelligence Fall Deterministic Games. Zero-Sum Games 10/13/17. Adversarial Search

Artificial Intelligence

CS 440 / ECE 448 Introduction to Artificial Intelligence Spring 2010 Lecture #5

Adversarial Search Aka Games

Adversarial Search (Game Playing)

CS 771 Artificial Intelligence. Adversarial Search

CS188 Spring 2010 Section 3: Game Trees

Set 4: Game-Playing. ICS 271 Fall 2017 Kalev Kask

CPS 570: Artificial Intelligence Two-player, zero-sum, perfect-information Games

CS510 \ Lecture Ariel Stolerman

Announcements. Homework 1 solutions posted. Test in 2 weeks (27 th ) -Covers up to and including HW2 (informed search)

Adversarial Search Lecture 7

Game Tree Search. CSC384: Introduction to Artificial Intelligence. Generalizing Search Problem. General Games. What makes something a game?

Adversarial Search. Read AIMA Chapter CIS 421/521 - Intro to AI 1

ADVERSARIAL SEARCH. Chapter 5

CS 4700: Foundations of Artificial Intelligence

Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning

Pengju

CS 188: Artificial Intelligence

Adversarial Search: Game Playing. Reading: Chapter

CSE 40171: Artificial Intelligence. Adversarial Search: Game Trees, Alpha-Beta Pruning; Imperfect Decisions

Adversarial Search and Game Playing

Game Playing Part 1 Minimax Search

Game Engineering CS F-24 Board / Strategy Games

Artificial Intelligence

CS 331: Artificial Intelligence Adversarial Search II. Outline

Announcements. Homework 1. Project 1. Due tonight at 11:59pm. Due Friday 2/8 at 4:00pm. Electronic HW1 Written HW1

Games CSE 473. Kasparov Vs. Deep Junior August 2, 2003 Match ends in a 3 / 3 tie!

16.410/413 Principles of Autonomy and Decision Making

Game Playing. Chapter 8

CS188 Spring 2010 Section 3: Game Trees

Game-playing: DeepBlue and AlphaGo

Game Playing. Why do AI researchers study game playing? 1. It s a good reasoning problem, formal and nontrivial.

CS188 Spring 2014 Section 3: Games

Adversarial Search. CS 486/686: Introduction to Artificial Intelligence

School of EECS Washington State University. Artificial Intelligence

CSE 473: Artificial Intelligence. Outline

Ar#ficial)Intelligence!!

Games and Adversarial Search

CS 4700: Artificial Intelligence

Foundations of Artificial Intelligence

Lecture 14. Questions? Friday, February 10 CS 430 Artificial Intelligence - Lecture 14 1

Foundations of AI. 6. Board Games. Search Strategies for Games, Games with Chance, State of the Art

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

Foundations of AI. 6. Adversarial Search. Search Strategies for Games, Games with Chance, State of the Art. Wolfram Burgard & Bernhard Nebel

Adversarial search (game playing)

Chess Algorithms Theory and Practice. Rune Djurhuus Chess Grandmaster / September 23, 2013

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

Game Playing AI. Dr. Baldassano Yu s Elite Education

2/5/17 ADVERSARIAL SEARCH. Today. Introduce adversarial games Minimax as an optimal strategy Alpha-beta pruning Real-time decision making

Adversarial Search. CS 486/686: Introduction to Artificial Intelligence

Artificial Intelligence Adversarial Search

Artificial Intelligence, CS, Nanjing University Spring, 2018, Yang Yu. Lecture 4: Search 3.

Data Structures and Algorithms

Artificial Intelligence

Artificial Intelligence Lecture 3

Contents. Foundations of Artificial Intelligence. Problems. Why Board Games?

Game Tree Search. Generalizing Search Problems. Two-person Zero-Sum Games. Generalizing Search Problems. CSC384: Intro to Artificial Intelligence

COMP9414: Artificial Intelligence Adversarial Search

COMP219: COMP219: Artificial Intelligence Artificial Intelligence Dr. Annabel Latham Lecture 12: Game Playing Overview Games and Search

Foundations of Artificial Intelligence

Ch.4 AI and Games. Hantao Zhang. The University of Iowa Department of Computer Science. hzhang/c145

Adversarial Search. Chapter 5. Mausam (Based on slides of Stuart Russell, Andrew Parks, Henry Kautz, Linda Shapiro) 1

Game Playing. Dr. Richard J. Povinelli. Page 1. rev 1.1, 9/14/2003

Transcription:

1-466 Computer Game Programg Board Games Maxim Likhachev Robotics Institute Carnegie Mellon University

There Are Still Board Games Maxim Likhachev Carnegie Mellon University 2

Classes of Board Games Two players vs. more than two players (e.g., chess vs. poker) Perfect information vs. imperfect information (e.g., chess vs. poker) - everybody knows ALL the whole game state Zero-sum vs. non-zero-sum (e.g., chess vs. maximizing wealth by cooperating) - zero-sum refers to what your opponent looses, you gain (gain=loss) What class do most board games belong to? Maxim Likhachev Carnegie Mellon University 3

Game Tree For Two-opponent Zero-sum Perfect Information Game Game tree for Tic-Tac-Toe: At leaves: +1 if the leaf is a win for X, -1 if the leaf is a win for O X s turn: O s turn: X s turn: from Artificial Intelligence for Games by I. Millington & J. Funge Maxim Likhachev Carnegie Mellon University 4

Game Tree For Two-opponent Zero-sum Perfect Information Game Abstract game tree: At leaves: the score (evaluation of the leaf) for Player 1 from Artificial Intelligence for Games by I. Millington & J. Funge Maxim Likhachev Carnegie Mellon University

Game Tree For Two-opponent Zero-sum Perfect Information Game If branches can merge (can arrive to the same state via multiple paths), then the game has transpositions - no longer a tree Example of games with transpositions? Maxim Likhachev Carnegie Mellon University 6

Minimax for Games without Transposition Recursive approach to computing the value of the game assug we and the opponent are acting optimally GetMinimaxValue(state s at level d) if d = maximum depth, then return evaluation score of s if state s is a leaf state, then return the score of s if d is even, then return MAX s in succ(s) (GetMinimaxValue (s at level d+1)) if d is odd, then return MIN s in succ(s) (GetMinimaxValue (s at level d+1)) What do we do with these values afterwards? Maxim Likhachev Carnegie Mellon University 7

Minimax for Games without Transposition Recursive approach to computing the value of the game assug we and the opponent are acting optimally GetMinimaxValue(state s at level d) Anything wrong with this assumption? if d = maximum depth, then return evaluation score of s if state s is a leaf state, then return the score of s if d is even, then return MAX s in succ(s) (GetMinimaxValue (s at level d+1)) if d is odd, then return MIN s in succ(s) (GetMinimaxValue (s at level d+1)) Maxim Likhachev Carnegie Mellon University 8

Negamax for Games without Transposition Recursive approach to computing the value of the game assug we and the opponent are acting optimally GetNegaMaxValue(state s at level d) if d = maximum depth, then return (-1) d *evaluation score of s if state s is a leaf state, then return (-1) d *score of s return MAX s in succ(s) (-1*GetNegaMaxValue (s at level d+1)) Avoids alternating -max operations from Artificial Intelligence for Games by I. Millington & J. Funge Maxim Likhachev Carnegie Mellon University 9

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range max 4 9 4 10 max max max max 3 8 9 3 4 9 10 Maxim Likhachev Carnegie Mellon University 10

Alpha-Beta Pruning for Minimax No need to evaluate any branch whose value is guaranteed to Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score be outside of (α, β) range (- ; ) max (- ; ) 4 (- ; ) 9 4 10 max max max max - ; ) (?;?) 3 8 9 3 4 9 10 Maxim Likhachev Carnegie Mellon University 11

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range (- ; ) max (- ; ) 4 (- ; ) (?;?) 9 4 10 max max max max - ; ) (; ) 3 8 9 3 4 9 10 Maxim Likhachev Carnegie Mellon University 12

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range (- ; ) max (- ; ) 4 (- ; ) (- ;) 9 4 10 max max (8;) max max - ; ) (; ) (- ;) 3 8 9 3 4 9 10 Maxim Likhachev Carnegie Mellon University 13

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range (- ; ) max (- ; ) 4 (- ; ) (- ;) 9 4 10 max max (8;) max max - ; ) (; ) (- ;) 3 8 9 3 4 9 10 Maxim Likhachev Carnegie Mellon University 14

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range (- ; ) max (- ; ) (?;?) 4 (- ; ) (- ;) 9 4 10 max max (8;) max max - ; ) (; ) (- ;) 3 8 9 3 4 9 10 Maxim Likhachev Carnegie Mellon University 1

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range (- ; ) max (- ; ) (; ) 4 (- ; ) (- ;) (; ) 9 4 10 max max (8;) max max - ; ) (; ) (- ;) (; ) (?;?) 3 8 9 3 4 9 10 Maxim Likhachev Carnegie Mellon University 16

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range (- ; ) max (- ; ) (; ) 4 (?;?) (- ; ) (- ;) (; ) 9 4 10 max max (8;) max max - ; ) (; ) (- ;) (; ) (; ) 3 8 9 3 4 9 10 Maxim Likhachev Carnegie Mellon University 17

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range (- ; ) max (- ; ) (; ) 4 (;4) (- ; ) (- ;) (; ) 9 4 10 max max (8;) max max - ; ) (; ) (- ;) (; ) (; ) 3 8 9 3 4 9 10 Maxim Likhachev Carnegie Mellon University 18

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range GetMinimaxValuewithAB(state s at level d, a, b) if d = maximum depth, then return evaluation score of s if state s is a leaf state, then return the score of s iterate over all successors s in succ(s) if d is even, then a = MAX(a, GetMinimaxValue (s at level d+1, a, b)) if a b return a //beta cut-off if d is odd, then b = MIN(b, GetMinimaxValue (s at level d+1, a, b)) if a b return b //alpha cut-off Maxim Likhachev Carnegie Mellon University 19

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range What are the initial parameter values? GetMinimaxValuewithAB(state s at level d, a, b) if d = maximum depth, then return evaluation score of s if state s is a leaf state, then return the score of s iterate over all successors s in succ(s) if d is even, then a = MAX(a, GetMinimaxValue (s at level d+1, a, b)) if a b return a //beta cut-off if d is odd, then b = MIN(b, GetMinimaxValue (s at level d+1, a, b)) if a b return b //alpha cut-off Maxim Likhachev Carnegie Mellon University 20

Alpha-Beta Pruning for Minimax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score No need to evaluate any branch whose value is guaranteed to be outside of (α, β) range What are the initial parameter values? GetMinimaxValuewithAB(state s at level d, a, b) if d = maximum depth, then return evaluation score of s if state s is a leaf state, then return the score of s iterate over all successors s in succ(s) if d is even, then a = MAX(a, GetMinimaxValue (s at level d+1, a, b)) if a b return a //beta cut-off if d is odd, then b = MIN(b, GetMinimaxValue (s at level d+1, a, b)) if a b return b //alpha cut-off Maxim Likhachev Carnegie Mellon University 21

Alpha-Beta Pruning for Negamax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score GetNegaMaxValue(state s at level d, a, b) if d = maximum depth, then return (-1) d *evaluation score of s if state s is a leaf state, then return (-1) d *score of s iterate over all successors s in succ(s) a = MAX(a, -1*GetNegaMaxValue (s at level d+1, -b, -a)) if a b return a //alpha-beta cut-off from Artificial Intelligence for Games by I. Millington & J. Funge Maxim Likhachev Carnegie Mellon University 22

Alpha-Beta Pruning for Negamax Alpha α: lower bound on the optimal score Beta β: upper bound on the optimal score GetNegaMaxValue(state s at level d, a, b) if d = maximum depth, then return (-1) d *evaluation score of s if state s is a leaf state, then return (-1) d *score What is the of main s computational bottleneck in iterate over all successors s in succ(s) both imax & negamax? a = MAX(a, -1*GetNegaMaxValue (s at level d+1, -b, -a)) if a b return a //alpha-beta cut-off What are the way to speed it up? from Artificial Intelligence for Games by I. Millington & J. Funge Maxim Likhachev Carnegie Mellon University 23

Speeding Up Picking right ordering for Alpha-Beta Minimax/Negamax Artificially narrowing the alpha-beta window (aspiration search) Use full-window for the first move, and then windows whose width varies as a result of the first move scores (negascout) Maxim Likhachev Carnegie Mellon University 24

Speeding Up Picking right ordering for Alpha-Beta Minimax/Negamax Artificially narrowing the alpha-beta window (aspiration search) Apparently, a combination is extremely popular in board games such as Chess, Checkers, etc. Use full-window for the first move, and then windows whose width varies as a result of the first move scores (negascout) Maxim Likhachev Carnegie Mellon University 2

Games with Transpositions If branches can merge (can arrive to the same state via multiple paths), then the game has transpositions - no longer a tree Can we use the same Minimax/Negamax/Alpha- Beta searches? Maxim Likhachev Carnegie Mellon University 26

Games with Transpositions If branches can merge (can arrive to the same state via multiple paths), then the game has transpositions - no longer a tree Can we use the same Minimax/Negamax/Alpha- Beta searches? Yes How can we improve their efficiency? Maxim Likhachev Carnegie Mellon University 27

Games with Transpositions If branches can merge (can arrive to the same state via multiple paths), then the game has transpositions - no longer a tree Can we use the same Minimax/Negamax/Alpha- Beta searches? Yes How can we improve their efficiency? Use transposition tables to avoid duplicate work Maxim Likhachev Carnegie Mellon University 28

Games with Transpositions Transposition tables: - maintain values for computed board configurations in memory and look them up/insert new ones during search - let us avoid evaluating the same board configurations multiple times - let us avoid computing the imax value of the sub-tree for the same board configurations multiple times Maxim Likhachev Carnegie Mellon University 29

Games with Transpositions Transposition tables: - maintain values for computed board configurations in memory and look them up/insert new ones during search - let us avoid evaluating the same board configurations multiple times - let us avoid computing the imax value of the sub-tree for the same board configurations multiple times How do you store them in memory given the HUGE # of all possible configurations? Maxim Likhachev Carnegie Mellon University 30

Games with Transpositions Transposition tables: - maintain values for computed board configurations in memory and look them up/insert new ones during search - let us avoid evaluating the same board configurations multiple times - let us avoid computing the imax value of the sub-tree for the same board configurations multiple times How do you store them in memory given the HUGE # of all possible configurations? Hash table Maxim Likhachev Carnegie Mellon University 31

Games with Transpositions Transposition tables: - maintain values for computed board configurations in memory and look them up/insert new ones during search - let us avoid evaluating the same board configurations multiple times - let us avoid computing the imax value of the sub-tree for the same board configurations multiple times How do you store them in memory given the HUGE # of all possible configurations? Hash table How do you keep the hash tables from growing too large? Maxim Likhachev Carnegie Mellon University 32

Games with Transpositions Transposition tables: - maintain values for computed board configurations in memory and look them up/insert new ones during search - let us avoid evaluating the same board configurations multiple times - let us avoid computing the imax value of the sub-tree for the same board configurations multiple times You can also store the transposition table from previous searches and work on improving it while your opponent thinks (typical trick used in commercial board games)! How do you store them in memory given the HUGE # of all possible configurations? Hash table How do you keep the hash tables from growing too large? Maxim Likhachev Carnegie Mellon University 33