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

Similar documents
Games and Adversarial Search II

CS 771 Artificial Intelligence. Adversarial Search

Game-playing AIs: Games and Adversarial Search I AIMA

Game-Playing & Adversarial Search

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 & Adversarial Search Alpha-Beta Pruning, etc.

Adversarial Search and Game Playing

Adversarial Search (Game Playing)

Game Playing State-of-the-Art

CS 5522: Artificial Intelligence II

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

Programming Project 1: Pacman (Due )

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

Adversarial Search Aka Games

Game playing. Chapter 5. Chapter 5 1

Adversarial Search 1

Artificial Intelligence

Game Playing AI Class 8 Ch , 5.4.1, 5.5

Artificial Intelligence 1: game playing

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

CS 188: Artificial Intelligence

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

CS 188: Artificial Intelligence

Game Playing. Philipp Koehn. 29 September 2015

Game playing. Chapter 6. Chapter 6 1

CS 380: ARTIFICIAL INTELLIGENCE ADVERSARIAL SEARCH. Santiago Ontañón

Foundations of Artificial Intelligence

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

Game Playing: Adversarial Search. Chapter 5

ARTIFICIAL INTELLIGENCE (CS 370D)

Foundations of Artificial Intelligence

Adversarial Search. Soleymani. Artificial Intelligence: A Modern Approach, 3 rd Edition, Chapter 5

Game playing. Chapter 5, Sections 1 6

Game playing. Outline

CS 380: ARTIFICIAL INTELLIGENCE

Games vs. search problems. Game playing Chapter 6. Outline. Game tree (2-player, deterministic, turns) Types of games. Minimax

Path Planning as Search

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

Game playing. Chapter 6. Chapter 6 1

Artificial Intelligence

Adversarial Search: Game Playing. Reading: Chapter

CS 188: Artificial Intelligence Spring Announcements

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

CS 188: Artificial Intelligence Spring 2007

Adversarial Search Lecture 7

CSE 473: Artificial Intelligence. Outline

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

Games vs. search problems. Adversarial Search. Types of games. Outline

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

Game Playing State of the Art

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

CPS331 Lecture: Search in Games last revised 2/16/10

Adversary Search. Ref: Chapter 5

ADVERSARIAL SEARCH. Chapter 5

Announcements. CS 188: Artificial Intelligence Spring Game Playing State-of-the-Art. Overview. Game Playing. GamesCrafters

Outline. Game playing. Types of games. Games vs. search problems. Minimax. Game tree (2-player, deterministic, turns) Games

Artificial Intelligence. Topic 5. Game playing

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

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

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

School of EECS Washington State University. Artificial Intelligence

Lecture 5: Game Playing (Adversarial Search)

Artificial Intelligence Adversarial Search

Artificial Intelligence. Minimax and alpha-beta pruning

Adversarial Search. Hal Daumé III. Computer Science University of Maryland CS 421: Introduction to Artificial Intelligence 9 Feb 2012

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

mywbut.com Two agent games : alpha beta pruning

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

CSE 473: Ar+ficial Intelligence

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

Last update: March 9, Game playing. CMSC 421, Chapter 6. CMSC 421, Chapter 6 1

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

Outline. Game Playing. Game Problems. Game Problems. Types of games Playing a perfect game. Playing an imperfect game

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

CS 331: Artificial Intelligence Adversarial Search II. Outline

CS 188: Artificial Intelligence. Overview

Adversarial search (game playing)

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

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

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

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

Game Playing AI. Dr. Baldassano Yu s Elite Education

Game playing. Chapter 5, Sections 1{5. AIMA Slides cstuart Russell and Peter Norvig, 1998 Chapter 5, Sections 1{5 1

CSE 573: Artificial Intelligence Autumn 2010

Artificial Intelligence

Adversarial Search (a.k.a. Game Playing)

CS 4700: Foundations of Artificial Intelligence

game tree complete all possible moves

Adversarial Search. CMPSCI 383 September 29, 2011

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

CSE 40171: Artificial Intelligence. Adversarial Search: Games and Optimality

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

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

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

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

CSE 573: Artificial Intelligence

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

Local Search. Hill Climbing. Hill Climbing Diagram. Simulated Annealing. Simulated Annealing. Introduction to Artificial Intelligence

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

Transcription:

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

Games: Outline of Unit Part I: Games as Search Motivation Game-playing AI successes Game Trees Evaluation Functions Part II: Adversarial Search The Minimax Rule Alpha-Beta Pruning CIS 391 - Intro to AI 2

The Minimax Rule (AIMA 5.2)

The Minimax Rule: `Don t play hope chess Idea: Make the best move for MAX assuming that MIN always replies with the best move for MIN Easily computed by a recursive process The backed-up value of each node in the tree is determined by the values of its children: For a MAX node, the backed-up value is the maximum of the values of its children (i.e. the best for MAX) For a MIN node, the backed-up value is the minimum of the values of its children (i.e. the best for MIN) CIS 391 - Intro to AI 4

The Minimax Procedure Until game is over: 1. Start with the current position as a MAX node. 2. Expand the game tree a fixed number of ply. 3. Apply the evaluation function to the leaf positions. 4. Calculate back-up values bottom-up. 5. Pick the move assigned to MAX at the root 6. Wait for MIN to respond CIS 391 - Intro to AI 5

2-ply Example: Backing up values MAX MIN 2 2 7 1 8 2 1 2 7 1 8 2 1 2 7 1 8 Evaluation function value 2 This is the move selected by minimax 2 1 2 7 1 8 CIS 391 - Intro to AI 6

What if MIN does not play optimally? Definition of optimal play for MAX assumes MIN plays optimally: Maximizes worst-case outcome for MAX. (Classic game theoretic strategy) But if MIN does not play optimally, MAX will do even better. [Theorem-not hard to prove] CIS 391 - Intro to AI 7

Comments on Minimax Search Depth-first search with fixed number of ply m as the limit. O(b m ) time complexity As usual! O(bm) space complexity Performance will depend on the quality of the static evaluation function (expert knowledge) depth of search (computing power and search algorithm) Differences from normal state space search Looking to make one move only, despite deeper search No cost on arcs costs from backed-up static evaluation MAX can t be sure how MIN will respond to his moves Minimax forms the basis for other game tree search algorithms. CIS 391 - Intro to AI 8

Alpha-Beta Pruning (AIMA 5.3) Many slides adapted from Richard Lathrop, USC/ISI, CS 271

Alpha-Beta Pruning A way to improve the performance of the Minimax Procedure Basic idea: If you have an idea which is surely bad, don t take the time to see how truly awful it is ~ Pat Winston =2 >=2 <=1 We don t need to compute the value at this node. 2 7 1? No matter what it is it can t effect the value of the root node. CIS 391 - Intro to AI 10

Alpha-Beta Pruning II During Minimax, keep track of two additional values: α: MAX s current lower bound on MAX s outcome β: MIN s current upper bound on MIN s outcome MAX will never allow a move that could lead to a worse score (for MAX) than α MIN will never allow a move that could lead to a better score (for MAX) than β Therefore, stop evaluating a branch whenever: When evaluating a MAX node: a value v β is backed-up MIN will never select that MAX node When evaluating a MIN node: a value v α is found MAX will never select that MIN node CIS 391 - Intro to AI 11

Alpha-Beta Pruning IIIa Based on observation that for all viable paths utility value f(n) will be α <= f(n) <= β Initially, α = -infinity, β=infinity As the search tree is traversed, the possible utility value window shrinks as α increases, β decreases CIS 391 - Intro to AI 12

Alpha-Beta Pruning IIIc Whenever the current ranges of alpha and beta no longer overlap, it is clear that the current node is a dead end CIS 391 - Intro to AI 13

Tic-Tac-Toe Example with Alpha-Beta Pruning Backup Values 1 CIS 391 - Intro to AI 14

Alpha-beta Algorithm: In detail Depth first search (usually bounded, with static evaluation) only considers nodes along a single path from root at any time = highest-value found at any point of current path for MAX (initially, = infinity) = lowest-value found at any point of current path for MIN (initially, = +infinity) Pass current values of and down to child nodes during search. Update values of and during search: MAX updates at MAX nodes MIN updates at MIN nodes Prune remaining branches at a node when CIS 391 - Intro to AI 15

When to Prune Prune whenever. β α Prune below a Max node when its value becomes the value of its ancestors. Max nodes update based on children s returned values. Idea: Player MIN at node above won t pick that value anyway, he can force a worse value. Prune below a Min node when its value becomes the value of its ancestors. Min nodes update based on children s returned values. Idea: Player MAX at node above won t pick that value anyway; she can do better. CIS 391 - Intro to AI 16

Pseudocode for Alpha-Beta Algorithm function ALPHA-BETA-SEARCH(state) returns an action inputs: state, current state in game v MAX-VALUE(state, -, + ) return an action in ACTIONS(state) with value v CIS 391 - Intro to AI 17

Pseudocode for Alpha-Beta Algorithm function ALPHA-BETA-SEARCH(state) returns an action inputs: state, current state in game v MAX-VALUE(state, -, + ) return an action in ACTIONS(state) with value v function MAX-VALUE(state,, ) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v - for a in ACTIONS(state) do v MAX(v,MIN-VALUE(Result(s,a),, )) if v then return v MAX(,v) return v CIS 391 - Intro to AI 18

Alpha-Beta Algorithm II function MIN-VALUE(state,, ) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v + for a,s in SUCCESSORS(state) do v MIN(v,MAX-VALUE(s,, )) if v then return v MIN(,v) return v CIS 391 - Intro to AI 19

An Alpha-Beta Example Do DF-search until first leaf,, initial values = =+,, passed to kids = =+ CIS 391 - Intro to AI 20

Alpha-Beta Example (continued) = =+ = =3 MIN updates, based on kids CIS 391 - Intro to AI 21

Alpha-Beta Example (continued) = =+ = =3 MIN updates, based on kids. No change. CIS 391 - Intro to AI 22

Alpha-Beta Example (continued) MAX updates, based on kids. =3 =+ 3 is returned as node value. CIS 391 - Intro to AI 23

Alpha-Beta Example (continued) =3 =+,, passed to kids =3 =+ CIS 391 - Intro to AI 24

Alpha-Beta Example (continued) =3 =+ MIN updates, based on kids. =3 =2 CIS 391 - Intro to AI 25

Alpha-Beta Example (continued) =3 =+ =3 =2, so prune. CIS 391 - Intro to AI 26

Alpha-Beta Example (continued) MAX updates, based on kids. No change. =3 =+ 2 is returned as node value. CIS 391 - Intro to AI 27

Alpha-Beta Example (continued) =3 =+,,, passed to kids =3 =+ CIS 391 - Intro to AI 28

Alpha-Beta Example (continued) =3 =+, MIN updates, based on kids. =3 =14 CIS 391 - Intro to AI 29

Alpha-Beta Example (continued) =3 =+, MIN updates, based on kids. =3 =5 CIS 391 - Intro to AI 30

Alpha-Beta Example (continued) =3 =+ 2 is returned as node value. 2 CIS 391 - Intro to AI 31

Alpha-Beta Example (continued) Max now makes it s best move, as computed by Alpha-Beta 2 CIS 391 - Intro to AI 32

Effectiveness of Alpha-Beta Pruning Guaranteed to compute same root value as Minimax Worst case: no pruning, same as Minimax (O(b d )) Best case: when each player s best move is the first option examined, examines only O(b d/2 ) nodes, allowing to search twice as deep! CIS 391 - Intro to AI 33

When best move is the first examined, examines only O(b d/2 ) nodes. So: run Iterative Deepening search, sort by value last iteration. So: expand captures first, then threats, then forward moves, etc. O(b (d/2) ) is the same as having a branching factor of sqrt(b), Since (sqrt(b)) d = b (d/2) e.g., in chess go from b ~ 35 to b ~ 6 For Deep Blue, alpha-beta pruning reduced the average branching factor from 35-40 to 6, as expected, doubling search depth CIS 391 - Intro to AI 34

Real systems use a few tricks Expand the proposed solution a little farther Just to make sure there are no surprises Learn better board evaluation functions E.g., for backgammon Learn model of your opponent E.g., for poker Do stochastic search E.g., for go CIS 391 - Intro to AI 35

Chinook and Deep Blue Chinook the World Man-Made Checkers Champion, developed at the University of Alberta. Competed in human tournaments, earning the right to play for the human world championship, and defeated the best players in the world. Deep Blue Defeated world champion Gary Kasparov 3.5-2.5 in 1997 after losing 4-2 in 1996. Uses a parallel array of 256 special chess-specific processors Evaluates 200 billion moves every 3 minutes; 12-ply search depth Expert knowledge from an international grandmaster. 8000 factor evaluation function tuned from hundreds of thousands of grandmaster games Tends to play for tiny positional advantages. CIS 391 - Intro to AI 36

FOR STUDY.

Example -which nodes can be pruned? 3 4 1 2 7 8 5 6 CIS 391 - Intro to AI 38

Answer to Example Max -which nodes can be pruned? Min Max 3 4 1 2 7 8 5 6 Answer: NONE! Because the most favorable nodes for both are explored last (i.e., in the diagram, are on the right-hand side). 39

Second Example (the exact mirror image of the first example) -which nodes can be pruned? 6 5 8 7 2 1 3 4 40

Answer to Second Example (the exact mirror image of the first example) Max -which nodes can be pruned? Min Max 6 5 8 7 2 1 3 4 Answer: LOTS! Because the most favorable nodes for both are explored first (i.e., in the diagram, are on the left-hand side). 41