AD FOR GAMES Lecture 4. M INIMAX AND A LPHA -B ETA R EDUCTION Borrows from Spring 2006 CS 440 Lecture Slides.

Slides:



Advertisements
Similar presentations
Adversarial Search Chapter 6 Section 1 – 4. Types of Games.
Advertisements

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.
Adversarial Search Reference: “Artificial Intelligence: A Modern Approach, 3 rd ed” (Russell and Norvig)
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.
CS 484 – Artificial Intelligence
Adversarial Search Chapter 5.
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.
Search Strategies.  Tries – for word searchers, spell checking, spelling corrections  Digital Search Trees – for searching for frequent keys (in text,
1 Adversarial Search Chapter 6 Section 1 – 4 The Master vs Machine: A Video.
Games CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Minimax and Alpha-Beta Reduction Borrows from Spring 2006 CS 440 Lecture Slides.
This time: Outline Game playing The minimax algorithm
Lecture 02 – Part C Game Playing: Adversarial Search
1 Game Playing Chapter 6 Additional references for the slides: Luger’s AI book (2005). Robert Wilensky’s CS188 slides:
Game Playing CSC361 AI CSC361: Game Playing.
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)
ICS-271:Notes 6: 1 Notes 6: Game-Playing ICS 271 Fall 2006.
Adversarial Search: Game Playing Reading: Chess paper.
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”
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
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.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 2 Adapted from slides of Yoonsuck.
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.
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.
1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah
Adversarial Search CS311 David Kauchak Spring 2013 Some material borrowed from : Sara Owsley Sood and others.
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.
For Wednesday Read Weiss, chapter 12, section 2 Homework: –Weiss, chapter 10, exercise 36 Program 5 due.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
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.
A RTIFICIAL I NTELLIGENCE Games. G AMES AND C OMPUTERS Games offer concrete or abstract competitions “I’m better than you!” Some games are amenable to.
Today’s Topics Playing Deterministic (no Dice, etc) Games –Mini-max –  -  pruning –ML and games? 1997: Computer Chess Player (IBM’s Deep Blue) Beat Human.
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.
CMSC 421: Intro to Artificial Intelligence October 6, 2003 Lecture 7: Games Professor: Bonnie J. Dorr TA: Nate Waisbrot.
Game Playing: Adversarial Search chapter 5. Game Playing: Adversarial Search  Introduction  So far, in problem solving, single agent search  The machine.
Adversarial Search 2 (Game Playing)
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.
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.
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.
Adversarial Search and Game-Playing
Last time: search strategies
PENGANTAR INTELIJENSIA BUATAN (64A614)
CS Fall 2016 (Shavlik©), Lecture 11, Week 6
Chapter 6 : Game Search 게임 탐색 (Adversarial Search)
Games & Adversarial Search
Game Playing: Adversarial Search
Introduction to Artificial Intelligence Lecture 9: Two-Player Games I
Game Playing Fifth Lecture 2019/4/11.
Game Playing: Adversarial Search
Game Playing Chapter 5.
Adversarial Search CMPT 420 / CMPG 720.
Games & Adversarial Search
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

AD FOR GAMES Lecture 4

M INIMAX AND A LPHA -B ETA R EDUCTION Borrows from Spring 2006 CS 440 Lecture Slides

M OTIVATION Want to create programs to play games Want to play optimally Want to be able to do this in a reasonable amount of time

T YPES OF G AMES Backgammon Monopoly Chess Checkers Go Othello Card GamesBattleship Fully Observable Partially Observable Deterministic Nondeterministic (Chance) Minimax is for deterministic, fully observable games

H OW TO PLAY A GAME BY SEARCHING General Scheme Consider all legal moves, each of which will lead to some new state of the environment (‘board position’) Evaluate each possible resulting board position Pick the move which leads to the best board position. Wait for your opponent’s move, then repeat. Key problems Representing the ‘board’ Representing legal next boards Evaluating positions Looking ahead

G AME T REES Represent the problem space for a game by a tree Nodes represent ‘board positions’; edges represent legal moves. Root node is the position in which a decision must be made. Evaluation function f assigns real-number scores to `board positions.’ Terminal nodes represent ways the game could end, labeled with the desirability of that ending (e.g. win/lose/draw or a numerical score)

B ASIC I DEA ( SEARCHING ) Search problem Searching a tree of the possible moves in order to find the move that produces the best result Depth First Search algorithm Assume the opponent is also playing optimally Try to guarantee a win anyway!

R EQUIRED P IECES FOR M INIMAX An initial state The positions of all the pieces Whose turn it is Operators Legal moves the player can make Terminal Test Determines if a state is a final state Utility Function Other name: static evaluation function

U TILITY F UNCTION Gives the utility of a game state utility(State) Examples -1, 0, and +1, for Player 1 loses, draw, Player 1 wins, respectively Difference between the point totals for the two players Weighted sum of factors (e.g. Chess) utility(S) = w 1 f 1 (S) + w 2 f 2 (S) w n f n (S) f 1 (S) = (Number of white queens) – (Number of black queens), w 1 = 9 f 2 (S) = (Number of white rooks) – (Number of black rooks), w 2 = 5...

T WO A GENTS MAX Wants to maximize the result of the utility function Winning strategy if, on MIN's turn, a win is obtainable for MAX for all moves that MIN can make MIN Wants to minimize the result of the evaluation function Winning strategy if, on MAX's turn, a win is obtainable for MIN for all moves that MAX can make

E XAMPLE Coins game There is a stack of N coins In turn, players take 1, 2, or 3 coins from the stack The player who takes the last coin loses

C OINS G AME : F ORMAL D EFINITION Initial State: The number of coins in the stack Operators: 1. Remove one coin 2. Remove two coins 3. Remove three coins Terminal Test: There are no coins left on the stack Utility Function: F(S) F(S) = 1 if MAX wins, 0 if MIN wins

N = 4 K = N = 3 K = N = 2 K = N = 1 K = N = 0 K = N = 1 K = N = 2 K = N = 0 K = N = 0 K = N = 1 K = N = 0 K = N = 1 K = N = 0 K = N = 0 K = N = 0 K = 1F(S)=0 F(S)=1 MAX MIN

N = 4 K = 1 N = 3 K = 0 N = 2 K = 0 N = 1 K = 1 N = 0 K = 1 N = 1 K = 0 N = 2 K = 1 N = 0 K = 1 N = 0 K = 1 N = 1 K = 0 N = 0 K = 0 N = 1 K = 1 N = 0 K = 0 N = 0 K = N = 0 K = 1 1F(S)=0 F(S)=1 MAX MIN Solution

Basic Algorithm

D EMO T IME See: WinMinimaxCS project demo

E XERCISE T IME See board ….

A NALYSIS Max Depth: 5 Branch factor: 3 Number of nodes: 15 Even with this trivial example, you can see that these trees can get very big Generally, there are O(b d ) nodes to search for Branch factor b: maximum number of moves from each node Depth d: maximum depth of the tree Exponential time to run the algorithm! How can we make it faster??????

A LPHA -B ETA P RUNING Main idea: Avoid processing subtrees that have no effect on the result Two new parameters α : The best value for MAX seen so far β : The best value for MIN seen so far α is used in MIN nodes, and is assigned in MAX nodes β is used in MAX nodes, and is assigned in MIN nodes

A LPHA -B ETA P RUNING MAX (Not at level 0) If a subtree is found with a value k greater than the value of β, then we do not need to continue searching subtrees MAX can do at least as good as k in this node, so MIN would never choose to go here! MIN If a subtree is found with a value k less than the value of α, then we do not need to continue searching subtrees MIN can do at least as good as k in this node, so MAX would never choose to go here!

Algorithm

CSE Intro to AI 22 A LPHA -B ETA P RUNING 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

CSE Intro to AI 23 A LPHA -B ETA P RUNING Traverse the search tree in depth-first order For each MAX node n, α(n)=maximum child value found so far Starts with –  Increases if a child returns a value greater than the current α(n) Lower-bound on the final value For each MIN node n, β(n)=minimum child value found so far Starts with +  Decreases if a child returns a value less than the current β(n) Upper-bound on the final value MAX cutoff rule: At a MAX node n, cut off search if α(n)>=β(n) MIN cutoff rule: At a MIN node n, cut off search if β(n)<=α(n) Carry α and β values down in search

function Max-Value (s,α,β) inputs: s: current state in game, A about to play α: best score (highest) for A along path to s β: best score (lowest) for B along path to s output: min(β, best-score (for A) available from s) if ( s is a terminal state ) then return ( terminal value of s ) else for each s’ in Succ(s) α:= max( α, Min-value(s’,α,β)) if ( α≥β) then return β return α function Min-Value (s’,α,β) output: max(α, best-score (for B) available from s ) if ( s is a terminal state ) then return ( terminal value of s) else for each s’ in Succs(s) β:= min( β, Max-value(s’,α,β)) if (β≤α) then return α return β

CSE Intro to AI 25

CSE Intro to AI 26

CSE Intro to AI 27

CSE Intro to AI 28

CSE Intro to AI 29

CSE Intro to AI 30

CSE Intro to AI 31

CSE Intro to AI 32

CSE Intro to AI 33

CSE Intro to AI 34

CSE Intro to AI 35

CSE Intro to AI 36

CSE Intro to AI 37

CSE Intro to AI 38

CSE Intro to AI 39

CSE Intro to AI 40

CSE Intro to AI 41

CSE Intro to AI 42

E FFECTIVENESS OF A LPHA -B ETA P RUNING Guaranteed to compute same root value as Minimax Worst case: no pruning, same as Minimax (O(bd)) Best case: when each player’s best move is the first option examined, you examine only O(bd/2) nodes, allowing you to search twice as deep!

C ONCLUSION Minimax finds optimal play for deterministic, fully observable, two-player games Alpha-Beta reduction makes it faster Interesting Link(s): alphabeta.html alphabeta.html

Y OUR KBS 2 P ROJECT We will focus on deterministic, two-player, fully observable games You will use minimax, alpha beta pruning and transposition tables ( next college )

H OMEWORK Study chapter Games form your study book Study this presentation

H OMEWORK AND P RACTICE Implement “ Tic Tac Toe with a Twist ” with two human players. See DEMO now During practice you are asked to implement an AI player using minimax for this game.