CS 331: Artificial Intelligence Adversarial Search. Games we will consider

Similar documents
Games we will consider. CS 331: Artificial Intelligence Adversarial Search. What makes games hard? Formal Definition of a Game.

CS 771 Artificial Intelligence. Adversarial Search

ADVERSARIAL SEARCH 5.1 GAMES

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

ARTIFICIAL INTELLIGENCE (CS 370D)

Artificial Intelligence Adversarial Search

Artificial Intelligence 1: game playing

Ar#ficial)Intelligence!!

Game Playing Part 1 Minimax Search

Artificial Intelligence. Minimax and alpha-beta pruning

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

Lecture 5: Game Playing (Adversarial Search)

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

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

Solving Problems by Searching: Adversarial Search

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

Game playing. Chapter 5, Sections 1 6

Game playing. Outline

Adversarial Search 1

Game playing. Chapter 5. Chapter 5 1

Game Playing Beyond Minimax. Game Playing Summary So Far. Game Playing Improving Efficiency. Game Playing Minimax using DFS.

ADVERSARIAL SEARCH. Chapter 5

mywbut.com Two agent games : alpha beta pruning

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

Game-playing AIs: Games and Adversarial Search I AIMA

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

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

Games (adversarial search problems)

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

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

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

Game playing. Chapter 6. Chapter 6 1

Artificial Intelligence

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

Adversarial Search. CMPSCI 383 September 29, 2011

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

2 person perfect information

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

Game playing. Chapter 6. Chapter 6 1

CS 380: ARTIFICIAL INTELLIGENCE

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

Adversarial Search and Game Playing

CS510 \ Lecture Ariel Stolerman

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

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

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

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

game tree complete all possible moves

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

Game Playing: Adversarial Search. Chapter 5

CS 4700: Foundations of Artificial Intelligence

Artificial Intelligence

CS 188: Artificial Intelligence Spring 2007

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

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

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

Games and Adversarial Search II

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

CS 188: Artificial Intelligence

Game Engineering CS F-24 Board / Strategy Games

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

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

Game Playing. Philipp Koehn. 29 September 2015

CS 4700: Artificial Intelligence

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

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

Today. Types of Game. Games and Search 1/18/2010. COMP210: Artificial Intelligence. Lecture 10. Game playing

CS 188: Artificial Intelligence Spring Announcements

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

Game Playing AI Class 8 Ch , 5.4.1, 5.5

Data Structures and Algorithms

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

CS 331: Artificial Intelligence Adversarial Search II. Outline

Artificial Intelligence. Topic 5. Game playing

Pengju

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

Project 1. Out of 20 points. Only 30% of final grade 5-6 projects in total. Extra day: 10%

Adversary Search. Ref: Chapter 5

Artificial Intelligence

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

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

Adversarial Search Aka Games

CS188 Spring 2014 Section 3: Games

Computer Game Programming Board Games

CS 188: Artificial Intelligence. Overview

CMPUT 396 Tic-Tac-Toe Game

Game Playing State-of-the-Art

Adversarial Search (Game Playing)

Prepared by Vaishnavi Moorthy Asst Prof- Dept of Cse

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

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

! HW5 now available! ! May do in groups of two.! Review in recitation! No fancy data structures except trie!! Due Monday 11:59 pm

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

Theory and Practice of Artificial Intelligence

Artificial Intelligence

Adversarial Search: Game Playing. Reading: Chapter

Games and Adversarial Search

Foundations of Artificial Intelligence

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

Transcription:

CS 331: rtificial ntelligence dversarial Search 1 Games we will consider Deterministic Discrete states and decisions Finite number of states and decisions Perfect information ie. fully observable Two agents whose actions alternate Their utility values at the end of the game are equal and opposite (we call this zero-sum) t s not enough for me to win, have to see my opponents lose 2 1

Which of these games fit the description? Two-player, zero-sum, discrete, finite, deterministic games of perfect information Which of these games fit the description? Two-player, zero-sum, discrete, finite, deterministic games of perfect information 2

What makes games hard? Hard to solve eg. Chess has a search tree with about 10 40 distinct nodes Need to make a decision even though you can t calculate the optimal decision Need to make a decision with time limits 5 Formal Definition of a Game quintuplet (S,, Succ(), T, U): S Finite set of states. States include information on which player s turn it is to move. nitial board position and which player is first to move Succ() T U Takes a current state and returns a list of (move,state) pairs, each indicating a legal move and the resulting state Terminal test which determines when the game ends. Terminal states: subset of S in where the game has ended Utility function (aka objective function or payoff function): maps from terminal state to real number 6 3

Challenge 7 Nim Many different variations. We ll do this one. Start with 9 beaver er logos n one player s turn, that player can remove 1, 2 or 3 beaver logos The person who takes the last beaver logo wins 8 4

Formal Definition of Nim Notation: () quintuplet (S,, Succ(), T, U): Who s move # matches left S (), (), (), () (), (), (), () () Succ() Succ(()) = {(),(),()} Succ(()) = {(),(),()} Succ(()) = {(),()} Succ(()) = {(),()} Succ(()) = {()} Succ(()) = {()} T (), (), (), (), (), () U Utility(() or () or ()) =, Utility(() or () or ()) = 9 Nim 10 5

Nim Game Tree We ll call the players and, with starting first How to Use a Game Tree wants to maximize his utility wants to minimize s utility s strategy must take into account what does since they alternate moves move by or is called a ply 12 6

The imax Value of a Node The minimax value of a node is the utility for MX of being in the corresponding state, assuming that both players play optimally from there to the end of the game MNMX- VLUE( n) UTLTY(n) f n is a terminal state max s Successors( n) MNMX- VLUE( s) min s Successors( n) MNMX- VLUE( s) f n is a MX node f n is a MN node imax value maximizes worst-case outcome for MX Nim Game Tree 14 7

imax Values in Nim Game Tree 15 imax Values in Nim Game Tree 16 8

imax Values in Nim Game Tree 17 imax Values in Nim Game Tree 1 1 18 9

imax Values in Nim Game Tree 1 1 19 imax Values in Nim Game Tree 1 1 imax decision at the root: taking this action results in the successor with highest minimax value 20 10

MX nother Example = imizing player = imizing player MN B C D 3 12 8 2 4 6 14 5 2 21 nother Example MX MN 3 B 2 C 2 D 3 12 8 2 4 6 14 5 2 22 11

nother Example MX 3 MN 3 B 2 C 2 D 3 12 8 2 4 6 14 5 2 23 The MNMX lgorithm function MNMX-DECSON(state) returns an action inputs: state, current state in game v MX-VLUE(state) return the action in SUCCESSORS(state) with value v function MX-VLUE(state) returns a utility value if TERMNL-TEST(state) then return UTLTY(state) v - nfinity for a, s in SUCCESSORS(state) do v MX(v, MN-VLUE(s)) return v function MN-VLUE(state) returns a utility value if TERMNL-TEST(state) then return UTLTY(state) v nfinity for a, s in SUCCESSORS(state) do v MN(v, MX-VLUE(s)) return v 24 12

The MNMX algorithm Computes minimax decision from the current state Depth-first exploration of the game tree Time Complexity O(b m ) where b=# of legal moves, m=maximum depth of tree Space Complexity: O(bm) if all successors generated at once O(m) if only one successor generated at a time (each partially expanded node remembers which successor to generate next) 25 imax With 3 Players B C (1,2,6) (4,2,3) (6,1,2) (7,4,1) (5,1,1) (1,5,2) (7,7,1) (5,4,5) Now have a vector of utilities for players (,B,C). ll players maximize their utilities. Note: n two-player, zero-sum games, we have a single value 26 because the values are always opposite. 13

imax With 3 Players B C (1,2,6) (6,1,2) (1,5,2) (5,4,5) (1,2,6) (4,2,3) (6,1,2) (7,4,1) (5,1,1) (1,5,2) (7,7,1) (5,4,5) 27 imax With 3 Players B (1,2,6) (1,5,2) C (1,2,6) (6,1,2) (1,5,2) (5,4,5) (1,2,6) (4,2,3) (6,1,2) (7,4,1) (5,1,1) (1,5,2) (7,7,1) (5,4,5) 28 14

imax With 3 Players (1,2,6) B (1,2,6) (1,5,2) C (1,2,6) (6,1,2) (1,5,2) (5,4,5) (1,2,6) (4,2,3) (6,1,2) (7,4,1) (5,1,1) (1,5,2) (7,7,1) (5,4,5) 29 Subtleties With Multiplayer Games lliances can be made and broken For example, if and B are weaker than C, they can gang up on C But and B can turn on each other once C is weakened But society considers the player that breaks the alliance to be dishonorable 30 15

Pruning Can we improve on the time complexity of O(b m )? Yes if we prune away branches that cannot possibly influence the final decision 31 Pruning in Nim 1 1 f we know that the only two outcomes are and, what branches do we not need to explore when minimax backtracks? 16

Pruning in Nim 1 1 f we know that the only two outcomes are and, what branches do we not need to explore when minimax backtracks? Pruning in Nim 1 1 What happens if we have more than just two outcomes? 34 17

Pruning ntuition (General Case) MX MN 5 1 The max player will never choose the right subtree once it knows that it is upper bounded by 1 5 10 1 Suppose we just went down this branch. We know that the minimax value of its parent will be 1 35 Pruning Example MX MN B C D 3 12 8 2 x y 14 5 2 MNMX-VLUE(root) = max(min(3,12,8),min(2,x,y),min(14,5,2)) min(2 x min(14 2)) = max(3,min(2,x,y),2) = max(3,z,2) where z 2 = 3 36 18

Pruning ntuition Remember that minimax search is DFS. t any one time, we only have to consider the nodes along a single path in the tree n general, let: = highest minimax value of all of the MX player s choices expanded on current path = lowest minimax value of all of the MN player s choices expanded on current path f at a MN player node, prune if minimax value of node f at a MX player node, prune if minimax value of node v 4 37 LPH-BET Pseudocode function LPH-BET-SERCH(state) returns an action inputs: state, current state in game v MX-VLUE(state, -, + ) return the action in SUCCESSORS(state) with value v function MX-VLUE(state,, ) returns a utility value inputs: state, current state in game, the value of the best alternative for MX along the path to state, the value of the best alternative for MN along the path to state if TERMNL-TEST(state) then return UTLTY(state) v - for a, s in SUCCESSORS(state) do v MX(v, MN-VLUE(s,, )) if v then return v MX(, v) return v 38 19

LPH-BET Pseudocode function MN-VLUE(state,, ) returns a utility value inputs: state, current state in game, the value of the best alternative for MX along the path to state, the value of the best alternative for MN along the path to state if TERMNL-TEST(state) then return UTLTY(state) v + for a, s in SUCCESSORS(state) do v MN(v, MX-VLUE(s,, )) if v then return v MN(, v) return v 39 llustrating the Pseudocode n the example to follow, the notation (-, + ) represents the (, ) values for the corresponding node This example is intended to illustrate how the actual implementation of lpha-beta pruning works = imizing player (-, + ) = imizing player B C D 40 20

lpha-beta Pruning Example a) (-, + ) b) (-, + ) (-, + ) B C D (-, 3) B C D 3 c) d) (-, + ) (-, + ) (-, 3) B C D (-, 3) B C D 3 12 3 12 8 lpha-beta Pruning Example e) (3, + ) f) (3, + ) B C D B C D (3, + ) 3 12 8 3 12 8 g) h) (3, + ) (3, + ) B C D (3, + ) B C D 3 12 8 2 3 12 8 2 Pruning happens: 2 ( =3) 21

lpha-beta Pruning Example i) (3, + ) j) (3, + ) B C (3, + ) D B C (3, 14) D 3 12 8 2 3 12 8 2 14 k) l) (3, + ) (3, + ) B C (3, 5) D B C D 3 12 8 2 14 5 3 12 8 2 14 5 2 Pruning happens: 2 ( =3) but not much is pruned since we re at the bottom Effectiveness of lpha-beta Depends on order of successors Best case: lpha-beta reduces complexity from O(b m ) for minimax to O(b m/2 ) This means lpha-beta can lookahead about twice as far as minimax in the same amount of time 44 22

mplementation Details n games we have the problem of transposition Transposition means different permutations of the move sequence that end up in the same position Results in lots of repeated states Use a transposition table to remember the states you ve seen (similar to closed list) 45 What you should know Be able to draw up a game tree Know how the imax algorithm works Know how the lpha-beta algorithm works Be able to do both algorithms by hand 46 23