Game Playing ECE457 Applied Artificial Intelligence Spring 2008 Lecture #5.

Slides:



Advertisements
Similar presentations
Adversarial Search Reference: “Artificial Intelligence: A Modern Approach, 3 rd ed” (Russell and Norvig)
Advertisements

Games & Adversarial Search Chapter 5. Games vs. search problems "Unpredictable" opponent  specifying a move for every possible opponent’s reply. Time.
This lecture topic: Game-Playing & Adversarial Search
February 7, 2006AI: Chapter 6: Adversarial Search1 Artificial Intelligence Chapter 6: Adversarial Search Michael Scherger Department of Computer Science.
Games & Adversarial Search
Games and adversarial search
Artificial Intelligence Adversarial search Fall 2008 professor: Luigi Ceccaroni.
ICS-271:Notes 6: 1 Notes 6: Game-Playing ICS 271 Fall 2008.
CS 484 – Artificial Intelligence
Adversarial Search Chapter 6 Section 1 – 4.
University College Cork (Ireland) Department of Civil and Environmental Engineering Course: Engineering Artificial Intelligence Dr. Radu Marinescu Lecture.
Adversarial Search Chapter 5.
COMP-4640: Intelligent & Interactive Systems Game Playing A game can be formally defined as a search problem with: -An initial state -a set of operators.
1 Game Playing. 2 Outline Perfect Play Resource Limits Alpha-Beta pruning Games of Chance.
Lecture 12 Last time: CSPs, backtracking, forward checking Today: Game Playing.
Adversarial Search CSE 473 University of Washington.
Artificial Intelligence for Games Game playing Patrick Olivier
Adversarial Search 對抗搜尋. Outline  Optimal decisions  α-β pruning  Imperfect, real-time decisions.
10/19/2004TCSS435A Isabelle Bichindaritz1 Game and Tree Searching.
Games CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
G51IAI Introduction to AI Minmax and Alpha Beta Pruning Garry Kasparov and Deep Blue. © 1997, GM Gabriel Schwartzman's Chess Camera, courtesy IBM.
Lecture 13 Last time: Games, minimax, alpha-beta Today: Finish off games, summary.
Artificial Intelligence in Game Design
This time: Outline Game playing The minimax algorithm
1 Game Playing Chapter 6 Additional references for the slides: Luger’s AI book (2005). Robert Wilensky’s CS188 slides:
Games and adversarial search
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Ch.6: Adversarial Search Fall 2008 Marco Valtorta.
1 DCP 1172 Introduction to Artificial Intelligence Lecture notes for Chap. 6 [AIMA] Chang-Sheng Chen.
ICS-271:Notes 6: 1 Notes 6: Game-Playing ICS 271 Fall 2006.
Games & Adversarial Search Chapter 6 Section 1 – 4.
Game Playing: Adversarial Search Chapter 6. Why study games Fun Clear criteria for success Interesting, hard problems which require minimal “initial structure”
ICS-270a:Notes 5: 1 Notes 5: Game-Playing ICS 270a Winter 2003.
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.
Game Trees: MiniMax strategy, Tree Evaluation, Pruning, Utility evaluation Adapted from slides of Yoonsuck Choe.
PSU CS 370 – Introduction to Artificial Intelligence Game MinMax Alpha-Beta.
Lecture 6: Game Playing Heshaam Faili University of Tehran Two-player games Minmax search algorithm Alpha-Beta pruning Games with chance.
Game Playing.
Game Playing ECE457 Applied Artificial Intelligence Spring 2007 Lecture #5.
Adversarial Search Chapter 6 Section 1 – 4. Outline Optimal decisions α-β pruning Imperfect, real-time decisions.
Kansas State University Department of Computing and Information Sciences CIS 730: Introduction to Artificial Intelligence Lecture 9 of 14 Friday, 10 September.
Introduction to Artificial Intelligence CS 438 Spring 2008 Today –AIMA, Ch. 6 –Adversarial Search Thursday –AIMA, Ch. 6 –More Adversarial Search The “Luke.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
1 Adversarial Search CS 171/271 (Chapter 6) Some text and images in these slides were drawn from Russel & Norvig’s published material.
For Wednesday Read chapter 7, sections 1-4 Homework: –Chapter 6, exercise 1.
Adversarial Search Chapter Games vs. search problems "Unpredictable" opponent  specifying a move for every possible opponent reply Time limits.
Artificial Intelligence
ARTIFICIAL INTELLIGENCE (CS 461D) Princess Nora University Faculty of Computer & Information Systems.
Adversarial Search and Game Playing Russell and Norvig: Chapter 6 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2004/home.htm Prof: Dekang.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 5 Adversarial Search (Thanks Meinolf Sellman!)
Artificial Intelligence in Game Design Board Games and the MinMax Algorithm.
G51IAI Introduction to AI Andrew Parkes Game Playing 2: Alpha-Beta Search and General Issues.
Adversarial Search Chapter 5 Sections 1 – 4. AI & Expert Systems© Dr. Khalid Kaabneh, AAU Outline Optimal decisions α-β pruning Imperfect, real-time decisions.
ADVERSARIAL SEARCH Chapter 6 Section 1 – 4. OUTLINE Optimal decisions α-β pruning Imperfect, real-time decisions.
Adversarial Search CMPT 463. When: Tuesday, April 5 3:30PM Where: RLC 105 Team based: one, two or three people per team Languages: Python, C++ and Java.
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.
1 Chapter 6 Game Playing. 2 Chapter 6 Contents l Game Trees l Assumptions l Static evaluation functions l Searching game trees l Minimax l Bounded lookahead.
Artificial Intelligence AIMA §5: Adversarial Search
Adversarial Search and Game-Playing
Games and adversarial search (Chapter 5)
4. Games and adversarial search
PENGANTAR INTELIJENSIA BUATAN (64A614)
Games and adversarial search (Chapter 5)
Games & Adversarial Search
Games & Adversarial Search
Games & Adversarial Search
Games & Adversarial Search
Games & Adversarial Search
Adversarial Search CMPT 420 / CMPG 720.
Adversarial Search CS 171/271 (Chapter 6)
Games & Adversarial Search
Presentation transcript:

Game Playing ECE457 Applied Artificial Intelligence Spring 2008 Lecture #5

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 2 Outline Types of games Playing a perfect game Minimax search Alpha-beta pruning Playing an imperfect game Real-time Imperfect information Chance Russell & Norvig, chapter 6 Project #2

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 3 Game Problems Games are well-defined search problems… Well-defined board configurations (states) Limited set of well-defined moves (actions) Well-defined victory conditions (goal) Values assigned to pieces, moves, outcomes (cost) …that are hard to solve by searching A search tree for chess has an average branching factor of 35 An average chess game lasts for 50 moves per player (ply) The average search tree has nodes!

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 4 Game Problems The opponent He wants to win and make our agent lose We have no control over his actions He prevents us from reaching the optimal solution Introduces uncertainty in the search We don’t know what moves the opponent will do We will assume “perfect play” behaviour

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 5 Types of Games DeterministicChance Perfect information Chess Checkers Go Backgammon Monopoly Imperfect information Stratego Battleship Bridge Poker Scrabble Zero-sum games: a player’s gains are exactly substracted from another player’s score (chess) Non-zero-sum games: players can gain or lose without an exact change on others (prisoners’ dilemma)

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 6 Game-Playing Strategy Our agent and the opponent play sequentially We assume the opponent plays perfectly Our agent cannot get to the optimal goal The opponent won’t allow it Our agent must find the best achievable goal

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 7 Minimax Algorithm Payoff (utility) function assigns a value to each leaf node in the tree Value then propagates up to non-leaf nodes Two players MAX wants to maximise payoff MIN wants to minimise payoff MAX is the player currently looking for a move (i.e. at root of tree) Payoff function Simple 1 = win / 0 = draw / -1 = lose Complex for different victory conditions Win/lose for MAX

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 8 Minimax Algorithm XX X X O XO XO XOXXO X XO X … … …

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 9 Minimax Algorithm MAX MIN MAX

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 10 Minimax Algorithm Game of Nim Initial state: 7 matches in a pile Each player must divide a pile into two non- empty unequal piles Player who can’t do that, loses Payoff +1 win, -1 loss

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page (max wins) Minimax Algorithm MAX MIN MAX MIN MAX MIN -1 (max loses) +1 (max wins) The value of each node is the value of the best leaf the current player (MAX or MIN) can reach.

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 12 Minimax Algorithm Generate entire game tree Compute payoff of leaf nodes For each non-leaf node, from the lowest in the tree to the root If MAX level, then assign value of the child with maximum payoff If MIN level, then assign value of the child with minimum payoff At the root, select action with maximum payoff

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 13 Minimax Algorithm Complete, if tree is finite Optimal against a perfect opponent Time complexity = O(b m ) Space complexity = O(bm) But remember, b and m can be huge For chess, b ≈ 35 and m ≈ 100

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 14 Alpha-Beta Pruning MAX take the max of its children MIN gives each child the min of its children max(min(3,18,5),min(1,15,42),min(56,-12,-5)) We don’t need to compute the values of all the grandchildren! Only until we find a value lower than the highest child’s value max(min(3,18,5),min(1,?,?),min(56,-12,?))

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 15 Alpha-Beta Pruning Maintain values  and   is the maximum value that MAX is assured of at any point in the search  is the minimum value that MIN is assured of at any point in the search Both computed using payoff propagated through the tree Start with  = -  and  =  As the search goes on, the number of possible values of  and  decreases When    Current path is not the result of best play by both players, so no need to explore further

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 16 Alpha-Beta Pruning MAX MIN MAX [- ,  ] 5. [3,  ] 1. [- ,  ] 3. [- , 3] 7. [3,  ] 4. [3,  ] 6. [3, 1] 9. [3, -12] 8. [3, 56] [ ,  ]

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 17 Alpha-Beta Pruning Called as “rootvalue = Evaluate(root, - ,  )” Evaluate(node, ,  ) If node is leaf Return payoff If node is MAX v = -  For each child of node v = max( v, Evaluate(child, ,  ) Break if v    = max( , v) Return v If node is MIN v =  For each child of node v = min( v, Evaluate(child, ,  ) ) Break if v    = min( , v) Return v

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 18 Alpha-Beta Pruning Efficiency dependant on ordering of children Will check each of MAX’s children until finding one with a value higher than beta Will check each of MIN’s children until finding one with a value lower than alpha Use heuristics to order the nodes to check Check the highest-value children first for MAX Check the lowest-value children first for MIN Good ordering can reduce time complexity to O(b m/2 ) Random ordering gives roughly O(b 3m/4 ) Minimax is O(b m )

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 19 Minimax Exercise A BC D EFGH JM N O LK I

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page [8, 0] 2.[- ,  ] 5.[5,  ] Pruning Exercise A BC D EFGH JM N O [- ,  ] 3.[- , 6] 4.[- , 5] 6.[5,  ] 7.[- ,  ] 8.[8,  ] 9.[8,  ] LK 11.[5, 8] 12.[- , 8] 13.[9, 8] I 14.[5, 4]

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 21 Imperfect Play Real-time or time constraints Chance Hidden information

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 22 Real-Time Games Sometimes we can’t search the entire tree Real-time games Time constraints (playing against a clock) Tree too big (e.g. chess)

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 23 Real-Time Games Evaluation function Estimate value of a non-leaf node in the tree Cut off search at a given level Chess: count value of pieces, available moves, board configurations, … X X O X OX <

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 24 Real-Time Minimax Algorithm Generate entire game tree down to maximum number of ply Evaluate lowest nodes For each non-leaf node, from the lowest in the tree to the root If MAX level, then assign value of the child with maximum payoff If MIN level, then assign value of the child with minimum payoff At the root, select action with maximum payoff

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 25 Real-Time Alpha-Beta Pruning Called as “rootvalue = Evaluate(root, - ,  )” Evaluate(node, ,  ) If node is at lowest level Return evaluation If node is MAX v = -  For each child of node v = max( v, Evaluate(child, ,  ) Break if v    = max( , v) Return v If node is MIN v =  For each child of node v = min( v, Evaluate(child, ,  ) ) Break if v    = min( , v) Return v

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 26 Real-Time Games: Problems Non-quiescent positions Some state configurations cause value to change wildly Solved with quiescence search Expand non-quiescent boards deeper, until you reach stable “quiescent” boards

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 27 Real-Time Games: Problems Horizon effect A “singular” move is considerably better than all others But a damaging unavoidable move is (or can be pushed) just beyond the search depth limit (the “horizon”) Solved with singular extension Expand singular state deeper

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 28 Games of Chance Minimax requires planning for upcoming moves If moves depend on dice rolls, random draws, etc., planning is impossible We need to add all possible outcomes in the tree!

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 29 Recall

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 30 Expectiminimax MAX has already rolled the dice and has three possible moves Then, MIN rolls the dice And MIN picks an action based on the roll result There are three possible outcomes to the roll

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 31 Expectiminimax

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 32 Problems with Expectiminimax

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 33 Problems with Expectiminimax Time complexity: O(b m n m ) n is the number of possible outcomes of a chance node Recall: minimax is O(b m ) Trees can grow very large very quickly Minimax & pruning limits search to likely sequences of actions given perfect play With randomness, there is no likely sequence of actions

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 34 Imperfect Information Algorithms so far require knowing everything about the game In some games, information about the opponent is hidden Cards in poker, pieces in Stratego, etc. We could approximate hidden information to random events The probability that the opponent has a flush, the probability that a piece is a bomb, etc. Then use expectiminimax to get best action

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 35 Imperfect Information List all possible outcomes, then average best action overall Can lead to irrational behaviour! Possible cases: Road 1 leads to money, road 2-a leads to gold, road 2-b leads to death (rational action is road 2, then a) Road 1 leads to money, road 2-a leads to death, road 2-b leads to gold (rational action is road 2, then b) But the real situation is: Road 1 leads to money, road 2 leads to gold or death (rational action is road 1) 12 ab

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 36 Imperfect Information It’s a useful approximation, but it’s not exact! Advantages: Works in many cases Doesn’t require new techniques to handle information discovery Disadvantages: In reality, hidden information is not the same as random events Can lead to irrational behaviour

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 37 Imperfect Information Need to handle information Gather information Plan based on what information we will have at a given point in the future Leads to more rational behaviour Acting to gain information Acting to give information to partners Acting to conceal information from the opponents We will learn to do that later in the course

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 38 IBM Deep Blue First chess computer to defeat a reigning world champion (Garry Kasparov) under normal chess tournament constraints in 1997 Relied on brute hardware search power 30 processors for the search 480 custom VLSI chess processors for move generation and ordering, and leaf node evaluation

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 39 IBM Deep Blue Searched a minimax tree M states per second, maximum 330M Average 6 to 16 ply, maximum 40 ply Decide which moves are worth expanding, giving priority to singular expansion and chess threats Null-window alpha-beta pruning Alpha-beta pruning but limited to a “window” of moves rather than the entire tree Faster and easier to implement on hardware Approximate, can only returns bounds on the minimax value Allows for a highly non-uniform, more selective and human-like search of the tree

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 40 IBM Deep Blue Two board evaluation heuristics Fast evaluation to get a quick approximate value Considers piece position value Slow evaluation to get an exact value Considers 8,000 features Includes common chess concepts and specific Kasparov strategies Features have programmable weights learned automatically from 700,000 grandmaster games and fine-tuned manually by a chess grandmaster

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 41 Assumptions Utility-based agent Environment Fully observable Deterministic Sequential Static Discrete / Continuous Single agent

ECE457 Applied Artificial Intelligence R. Khoury (2008)Page 42 Assumptions Updated Utility-based agent Environment Fully observable / Partially observable (approximation) Deterministic / Strategic / Stochastic Sequential Static / Semi-dynamic Discrete / Continuous Single agent / Multi-agent