Instructor: Eyal Amir Grad TAs: Wen Pu, Yonatan Bisk Undergrad TAs: Sam Johnson, Nikhil Johri CS 440 / ECE 448 Introduction to Artificial Intelligence.

Slides:



Advertisements
Similar presentations
CMSC 471 Spring 2014 Class #9 Tue 2/25/14 Game Playing Professor Marie desJardins,
Advertisements

Game Playing CS 63 Chapter 6
Adversarial Search Chapter 6 Section 1 – 4. Types of Games.
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.
Games & Adversarial Search Chapter 5. Games vs. search problems "Unpredictable" opponent  specifying a move for every possible opponent’s reply. Time.
February 7, 2006AI: Chapter 6: Adversarial Search1 Artificial Intelligence Chapter 6: Adversarial Search Michael Scherger Department of Computer Science.
Games & Adversarial Search
Artificial Intelligence Adversarial search Fall 2008 professor: Luigi Ceccaroni.
CMSC 671 Fall 2001 Class #8 – Thursday, September 27.
ICS-271:Notes 6: 1 Notes 6: Game-Playing ICS 271 Fall 2008.
CSC 8520 Spring Paula Matuszek CS 8520: Artificial Intelligence Solving Problems by Searching Paula Matuszek Spring, 2010 Slides based on Hwee Tou.
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.
Lecture 12 Last time: CSPs, backtracking, forward checking Today: Game Playing.
Adversarial Search CSE 473 University of Washington.
1 Adversarial Search Chapter 6 Section 1 – 4 The Master vs Machine: A Video.
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.
CMSC 463 Chapter 5: Game Playing Prof. Adam Anthony.
This time: Outline Game playing The minimax algorithm
Lecture 02 – Part C Game Playing: Adversarial Search
Game Playing CSC361 AI CSC361: Game Playing.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Ch.6: Adversarial Search Fall 2008 Marco Valtorta.
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)
Adversarial Search and Game Playing (Where making good decisions requires respecting your opponent) R&N: Chap. 6.
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”
Game Playing State-of-the-Art  Checkers: Chinook ended 40-year-reign of human world champion Marion Tinsley in Used an endgame database defining.
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.
CSC 412: AI Adversarial Search
CHAPTER 6 : ADVERSARIAL SEARCH
PSU CS 370 – Introduction to Artificial Intelligence Game MinMax Alpha-Beta.
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.
AD FOR GAMES Lecture 4. M INIMAX AND A LPHA -B ETA R EDUCTION Borrows from Spring 2006 CS 440 Lecture Slides.
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 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.
Adversarial Search Chapter 6 Section 1 – 4. Outline Optimal decisions α-β pruning Imperfect, real-time decisions.
Notes on Game Playing by Yun Peng of theYun Peng University of Maryland Baltimore County.
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.
Adversarial Search Chapter 6 Section 1 – 4. Search in an Adversarial Environment Iterative deepening and A* useful for single-agent search problems What.
Paula Matuszek, CSC 8520, Fall Based in part on aima.eecs.berkeley.edu/slides-ppt 1 CS 8520: Artificial Intelligence Adversarial Search Paula Matuszek.
ARTIFICIAL INTELLIGENCE (CS 461D) Princess Nora University Faculty of Computer & Information Systems.
Game-playing AIs Part 2 CIS 391 Fall CSE Intro to AI 2 Games: Outline of Unit Part II  The Minimax Rule  Alpha-Beta Pruning  Game-playing.
Game Playing Chapter 6 Some material adopted from notes by Charles R. Dyer, University of Wisconsin-Madison.
Game Playing: Adversarial Search chapter 5. Game Playing: Adversarial Search  Introduction  So far, in problem solving, single agent search  The machine.
Game Playing: Adversarial Search Chapter 6. Why study games Fun Clear criteria for success Offer an opportunity to study problems involving {hostile,
Adversarial Search and Game Playing Russell and Norvig: Chapter 6 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2004/home.htm Prof: Dekang.
Adversarial Search and Game Playing Russell and Norvig: Chapter 5 Russell and Norvig: Chapter 6 CS121 – Winter 2003.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 5 Adversarial Search (Thanks Meinolf Sellman!)
Adversarial Search and Game Playing. Topics Game playing Game trees Minimax Alpha-beta pruning Examples.
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 and Game-Playing
Adversarial Search and Game Playing (Where making good decisions requires respecting your opponent) R&N: Chap. 6.
PENGANTAR INTELIJENSIA BUATAN (64A614)
Adversarial Search and Game Playing (Where making good decisions requires respecting your opponent) R&N: Chap. 6.
CMSC 471 Fall 2011 Class #8-9 Tue 9/27/11 – Thu 9/29/11 Game Playing
Game Playing: Adversarial Search
CMSC 671 Fall 2010 Tue 9/21/10 Game Playing
Adversarial Search and Game Playing
Game Playing: Adversarial Search
Game Playing Chapter 5.
Presentation transcript:

Instructor: Eyal Amir Grad TAs: Wen Pu, Yonatan Bisk Undergrad TAs: Sam Johnson, Nikhil Johri CS 440 / ECE 448 Introduction to Artificial Intelligence Spring 2010 Lecture #5

Topics Game playing Game trees –Minimax –Alpha-beta pruning Examples

Why study games Offer an opportunity to study problems involving {hostile, adversarial, competing} agents. Fun Interesting, hard problems

Game-Playing Agent environment agent ? sensors actuators Environment

Types of games perfect information imperfect information deterministicchance

Types of games chess, checkers, go, othello backgammon, monopoly bridge, poker, scrabble perfect information imperfect information deterministicchance

Deterministic 2-player games 2-person game Players alternate moves Zero-sum: one player’s loss is the other’s gain Perfect information: both players have access to complete information about the state of the game. No information is hidden from either player. No chance (e.g., using dice) involved Examples: Tic-Tac-Toe, Checkers, Chess, Go, Nim, Othello Not: Bridge, Solitaire, Backgammon,...

Partial Game Tree for Tic-Tac- Toe f(n) = +1 if the position is a win for X. f(n) = -1 if the position is a win for O. f(n) = 0 if the position is a draw.

Perfect Two-Player Game Two players MAX and MIN take turn (with MAX playing first) State space Initial state Successor function Terminal test Score function, that tells whether a terminal state is a win (for MAX), a loss, or a draw Perfect knowledge of states, no uncertainty in successor function ~Utility

How to play a game A way to play such a game is to: –Consider all the legal moves you can make –Compute the new position resulting from each move –Evaluate each resulting position and determine which is best –Make that move –Wait for your opponent to move and repeat Key problems are: –Representing the “board” –Generating all legal next boards –Evaluating a position

Optimal Play MAX MIN This is the optimal play

Minimax Tree MAX node MIN node f value value computed by minimax

Minimax procedure Apply the evaluation function at each of the leaf nodes “Back up” values for each of the non-leaf nodes until a value is computed for the root node –At MIN nodes, the backed-up value is the minimum of the values associated with its children. –At MAX nodes, the backed up value is the maximum of the values associated with its children. Pick the operator associated with the child node whose backed-up value determined the value at the root

Minimax Example

But in general the search tree is too big to make it possible to reach the terminal states! Examples: Checkers: ~10 40 nodes Chess: ~ nodes

Evaluation function Evaluation function or static evaluator is used to evaluate the “goodness” of a game position. –Contrast with heuristic search where the evaluation function was a non-negative estimate of the cost from the start node to a goal and passing through the given node The zero-sum assumption allows us to use a single evaluation function to describe the goodness of a board with respect to both players. –f(n) >> 0: position n good for me and bad for you –f(n) << 0: position n bad for me and good for you –f(n) near 0: position n is a neutral position –f(n) = +infinity: win for me –f(n) = -infinity: win for you

Evaluation function examples Example of an evaluation function for Tic-Tac-Toe: f(n) = [# of 3-lengths open for me] - [# of 3-lengths open for you] where a 3-length is a complete row, column, or diagonal Alan Turing’s function for chess –f(n) = w(n)/b(n) where w(n) = sum of the point value of white’s pieces and b(n) = sum of black’s Most evaluation functions are specified as a weighted sum of position features: f(n) = w 1 *feat 1 (n) + w 2 *feat 2 (n) w n *feat k (n) Example features for chess are piece count, piece placement, squares controlled, etc. Deep Blue has about 6000 features in its evaluation function

Game trees Problem spaces for typical games are represented as trees Root node represents the current board configuration; player must decide the best single move to make next Static evaluator function rates a board position. f(board) = real number with f>0 “white” (me), f<0 for black (you) Arcs represent the possible legal moves for a player If it is my turn to move, then the root is labeled a "MAX" node; otherwise it is labeled a "MIN" node, indicating my opponent's turn. Each level of the tree has nodes that are all MAX or all MIN; nodes at level i are of the opposite kind from those at level i+1

Minimax procedure Create start node as a MAX node with current board configuration Expand nodes down to some depth (a.k.a. ply) of lookahead in the game Apply the evaluation function at each of the leaf nodes “Back up” values for each of the non-leaf nodes until a value is computed for the root node –At MIN nodes, the backed-up value is the minimum of the values associated with its children. –At MAX nodes, the backed up value is the maximum of the values associated with its children. Pick the operator associated with the child node whose backed-up value determined the value at the root

Issues Choice of the horizon Size of memory needed Number of nodes examined

Adaptive Search Wait for quiescence - hot spots Horizon effect Extend singular nodes /Secondary search Note that the horizon may not then be the same on every path of the tree

Issues Choice of the horizon Size of memory needed Number of nodes examined

Alpha-Beta Procedure Generate the game tree to depth h in depth-first manner Back-up estimates (alpha and beta values) of the evaluation functions whenever possible Prune branches that cannot lead to changing the final decision

Alpha-beta pruning We can improve on the performance of the minimax algorithm through alpha-beta pruning Basic idea: “If you have an idea that is surely bad, don't take the time to see how truly awful it is.” -- Pat Winston 271 =2 >=2 <=1 ? We don’t need to compute the value at this node. No matter what it is, it can’t affect the value of the root node. MAX MIN

Alpha-beta pruning Traverse the search tree in depth-first order At each MAX node n, alpha(n) = maximum value found so far At each MIN node n, beta(n) = minimum value found so far –Note: The alpha values start at -infinity and only increase, while beta values start at +infinity and only decrease. Beta cutoff: Given a MAX node n, cut off the search below n (i.e., don’t generate or examine any more of n’s children) if alpha(n) >= beta(i) for some MIN node ancestor i of n. Alpha cutoff: stop searching below MIN node n if beta(n) <= alpha(i) for some MAX node ancestor i of n.

Alpha-beta example MIN MAX PRUNE 145 2

Alpha-Beta Procedure The alpha of a MAX node is a lower bound on the backed-up value The beta of a MIN node is an upper bound on the backed-up value Update the alpha/beta of the parent of a node N when all search below N has been completed or discontinued

Alpha-Beta Procedure The alpha of a MAX node is a lower bound on the backed-up value The beta of a MIN node is a higher bound on the backed-up value Update the alpha/beta of the parent of a node N when all search below N has been completed or discontinued Discontinue the search below a MAX node N if its alpha is  beta of a MIN ancestor of N Discontinue the search below a MIN node N if its beta is  alpha of a MAX ancestor of N

Alpha-beta algorithm function MAX-VALUE (state, game, alpha, beta) ;; alpha = best MAX so far; beta = best MIN if CUTOFF-TEST (state) then return EVAL (state) for each s in SUCCESSORS (state) do alpha := MAX (alpha, MIN-VALUE (state, game, alpha, beta)) if alpha >= beta then return beta end return alpha function MIN-VALUE (state, game, alpha, beta) if CUTOFF-TEST (state) then return EVAL (state) for each s in SUCCESSORS (state) do beta := MIN (beta, MAX-VALUE (s, game, alpha, beta)) if beta <= alpha then return alpha end return beta

Alpha-Beta Example

Alpha-Beta Example

Effectiveness of alpha-beta Alpha-beta is guaranteed to compute the same value for the root node as computed by minimax, with less or equal computation Worst case: no pruning, examining b^d leaf nodes, where each node has b children and a d-ply search is performed Best case: examine only (b)^(d/2) leaf nodes. –Result is you can search twice as deep as minimax! Best case is when each player’s best move is the first alternative generated In Deep Blue, they found empirically that alpha-beta pruning meant that the average branching factor at each node was about 6 instead of about 35!

Games of chance Backgammon is a two-player game with uncertainty. Players roll dice to determine what moves to make. White has just rolled 5 and 6 and has four legal moves: 5-10, , , , Such games are good for exploring decision making in adversarial problems involving skill and luck.

Game Trees with Chance Nodes Chance nodes (shown as circles) represent random events For a random event with N outcomes, each chance node has N distinct children; a probability is associated with each (For 2 dice, there are 21 distinct outcomes) Use minimax to compute values for MAX and MIN nodes Use expected values for chance nodes For chance nodes over a max node, as in C: expectimax(C) = Sum i (P(d i ) * maxvalue(i)) For chance nodes over a min node: expectimin(C) = Sum i (P(d i ) * minvalue(i)) Max Rolls Min Rolls

Meaning of the evaluation function Dealing with probabilities and expected values means we have to be careful about the “meaning” of values returned by the static evaluator. Note that a “relative-order preserving” change of the values would not change the decision of minimax, but could change the decision with chance nodes. Linear transformations are ok A1 is best move A2 is best move 2 outcomes with prob {.9,.1}

Some examples….

Checkers © Jonathan Schaeffer

Chinook vs. Tinsley Name: Marion Tinsley Profession: Teach mathematics Hobby: Checkers Record: Over 42 years loses only 3 (!) games of checkers © Jonathan Schaeffer

Chinook First computer to win human world championship! Visit to play a version of Chinook over the Internet.

Backgammon branching factor several hundred TD-Gammon v1 – 1-step lookahead, learns to play games against itself TD-Gammon v2.1 – 2-ply search, does well against world champions TD-Gammon has changed the way experts play backgammon.

Chess

Reversi/Othello © Jonathan Schaeffer

Go: And on the Other Gave Handtalk a 9 stone handicap and still easily beat the program, thereby winning $15,000 © Jonathan Schaeffer

Perspective on Games: Con “Chess is the Drosophila of artificial intelligence. However, computer chess has developed much as genetics might have if the geneticists had concentrated their efforts starting in 1910 on breeding racing Drosophila. We would have some science, but mainly we would have very fast fruit flies.” John McCarthy © Jonathan Schaeffer

Summary Two-players game as a domain where action models are uncertain Optimal decision in the worst case Game tree Evaluation function / backed-up value Minimax procedure Alpha-beta procedure

Additional Resources Game AI Page

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

Alpha-Beta Example

How Much Do We Gain? Size of tree = O(b h ) In the worst case all nodes must be examined In the best case, only O(b h/2 ) nodes need to be examined Exercise: In which order should the node be examined in order to achieve the best gain?

The Game Rules: 1.Red goes first 2.On their turn, a player must move their piece 3.They must move to a neighboring square, or if their opponent is adjacent to them, with a blank on the far side, they can hop over them 4.The player that makes it to the far side first wins.

Draw the game tree Rules: 1.Red goes first 2.On their turn, a player must move their piece 3.They must move to a neighboring square, or if their opponent is adjacent to them, with a blank on the far side, they can hop over them 4.The player that makes it to the far side first wins.

Try this for your Game Tree Rules: 1.Red goes first 2.On their turn, a player must move their piece 3.They must move to a neighboring square, or if their opponent is adjacent to them, with a blank on the far side, they can hop over them 4.The player that makes it to the far side first wins.