Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning

Similar documents
Games (adversarial search problems)

Tree representation Utility function

Adversary Search. Ref: Chapter 5

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

ARTIFICIAL INTELLIGENCE (CS 370D)

mywbut.com Two agent games : alpha beta pruning

2 person perfect information

Adversarial Search 1

Artificial Intelligence

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

Game-playing AIs: Games and Adversarial Search I AIMA

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

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

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

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

game tree complete all possible moves

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

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

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

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

COMP219: Artificial Intelligence. Lecture 13: Game Playing

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

CS 331: Artificial Intelligence Adversarial Search II. Outline

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

CS2212 PROGRAMMING CHALLENGE II EVALUATION FUNCTIONS N. H. N. D. DE SILVA

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

Artificial Intelligence Search III

INF September 25, The deadline is postponed to Tuesday, October 3

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

Foundations of Artificial Intelligence

Adversarial Search: Game Playing. Reading: Chapter

CS 188: Artificial Intelligence Spring Announcements

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

Artificial Intelligence. Minimax and alpha-beta pruning

Programming Project 1: Pacman (Due )

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

Game Playing AI. Dr. Baldassano Yu s Elite Education

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

Path Planning as Search

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

Adversarial Search. CMPSCI 383 September 29, 2011

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

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

More Adversarial Search

Artificial Intelligence. Topic 5. Game playing

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

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

Game Playing State-of-the-Art

CS 4700: Foundations of Artificial Intelligence

Artificial Intelligence 1: game playing

CS 771 Artificial Intelligence. Adversarial Search

Game-Playing & Adversarial Search

CS 5522: Artificial Intelligence II

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

Artificial Intelligence Adversarial Search

COMP9414: Artificial Intelligence Adversarial Search

Rules of the game. chess checkers tic-tac-toe...

Artificial Intelligence

Foundations of Artificial Intelligence

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

CMPUT 396 Tic-Tac-Toe Game

CS 188: Artificial Intelligence. Overview

CITS3001. Algorithms, Agents and Artificial Intelligence. Semester 2, 2016 Tim French

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

Adversarial Search Lecture 7

Computer Game Programming Board Games

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

Artificial Intelligence

Foundations of AI. 6. Adversarial Search. Search Strategies for Games, Games with Chance, State of the Art. Wolfram Burgard & Bernhard Nebel

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

Ar#ficial)Intelligence!!

Foundations of AI. 5. Board Games. Search Strategies for Games, Games with Chance, State of the Art. Wolfram Burgard and Luc De Raedt SA-1

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

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

Game Playing Part 1 Minimax Search

Foundations of Artificial Intelligence

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

Foundations of AI. 6. Board Games. Search Strategies for Games, Games with Chance, State of the Art

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

CS 188: Artificial Intelligence

6. Games. COMP9414/ 9814/ 3411: Artificial Intelligence. Outline. Mechanical Turk. Origins. origins. motivation. minimax search

CS 188: Artificial Intelligence

Adversarial Search Aka Games

More on games (Ch )

Game Playing. Philipp Koehn. 29 September 2015

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

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

Game Engineering CS F-24 Board / Strategy Games

Game-Playing & Adversarial Search Alpha-Beta Pruning, etc.

Solving Problems by Searching: Adversarial Search

Game Playing State of the Art

Data Structures and Algorithms

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

Game Playing State-of-the-Art. CS 188: Artificial Intelligence. Behavior from Computation. Video of Demo Mystery Pacman. Adversarial Search

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

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

More on games (Ch )

CSC384: Introduction to Artificial Intelligence. Game Tree Search

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

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

Transcription:

Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning CSCE 315 Programming Studio Fall 2017 Project 2, Lecture 2 Adapted from slides of Yoonsuck Choe, John Keyser

Two-Person Perfect Information Deterministic Game Two players take turns making moves Board state fully known, deterministic evaluation of moves One player wins by defeating the other (or else there is a tie) Want a strategy to win, assuming the other person plays as well as possible

General Strategy Player 1 wants to maximize his chance of win Player 2 wants to maximize his (minimize Player 1 s) (9 possibilities) (8 possibilities)

Minimax Tree Use Minimax tree to emulate human s forward thinking process In Chess, players think a couple of steps (e.g., 3-4 steps) ahead in contingency of opponent moves Similar idea applies to other such games

Minimax tree Min Min Minimax tree Generate a new level for each move Levels alternate between max (player 1 moves) and min (player 2 moves)

Minimax Tree Evaluation Assign utility values to leaves Sometimes called board evaluation function If a state is a leaf state where Player 1 wins (looses), assign the maximum(minimum) possible utility value Board State 1 Board State 2 Board State 3 Utility: +100 Utility: 0 Utility: -100 Otherwise, keep expanding (make the next move)

Minimax tree Min 100 Min -100 100-100

Minimax Tree Algorithm function MAX-VALUE (state) if TERMINAL-TEST (state) return UTILITY (state) v = foreach s in SUCCESSORS (state) v = MAX (v, MIN-VALUE (s)) return v function MIN-VALUE (state) if TERMINAL-TEST (state) return UTILITY (state) v = foreach s in SUCCESSORS (state) v = MIN (v, MAX-VALUE (s)) return v

Minimax Tree Evaluation At each min node, assign the minimum of all utility values at children Player 2 chooses the best available move At each max node, assign the maximum of all utility values at children Player 1 chooses best available move Push values from leaves to top of tree

Problem?? What if the node we are trying to judge is NOT a LEAF node For Chess, a LEAF node could be many levels down Could take years(!!!) to compute It would be best if there was a Oracle saying: this is promising state, go for this move The answer to this problem: Utility Function

Utility Function Create a utility function Evaluation of board/game state to determine how strong the position of player 1 is. Assume that x is Player 1 in the following Tic-Tac- Toe Example: You have all of Queen, Rooks, Knights, Bishops and some Pawns, while your opponent has only 1 Knight, you have a high chance of winning Utility function will assign a numeric value to this board state (say 90/100)

Minimax tree Min 28-3 12 70-4 100-73 -14-8 Min 23 28 21-3 12 4 70-4 -12-70 -5-100 -73-14 -8-24

Minimax tree Min -3-4 -73 28-3 12 70-4 100-73 -14-8 Min 23 28 21-3 12 4 70-4 -12-70 -5-100 -73-14 -8-24

Minimax tree -3 Min -3-4 -73 28-3 12 70-4 100-73 -14-8 Min 23 28 21-3 12 4 70-4 -12-70 -5-100 -73-14 -8-24

Minimax Evaluation Given average branching factor b, and depth m: A complete evaluation takes time b m A complete evaluation takes space bm Usually, we cannot evaluate the complete state, since it s too big Instead, we limit the depth based on various factors, including time available.

Utility Evaluation Function Very game-specific Take into account knowledge about game Stupid utility 1 if player 1 wins -1 if player 0 wins 0 if tie (or unknown) Only works if we can evaluate complete tree But, should form a basis for other evaluations

Utility Evaluation Need to assign a numerical value to the state Could assign a more complex utility value, but then the min/max determination becomes trickier Typically assign numerical values to lots of individual factors a = # player 1 s pieces - # player 2 s pieces b = 1 if player 1 has queen and player 2 does not, -1 if the opposite, or 0 if the same c = 2 if player 1 has 2-rook advantage, 1 if a 1- rook advantage, etc.

Utility Evaluation The individual factors are combined by some function Usually a linear weighted combination is used u = aa + bb + cc Different ways to combine are also possible Notice: quality of utility function is based on: What features are evaluated How those features are scored How the scores are weighted/combined Absolute utility value doesn t matter relative value does.

Evaluation functions If you had a perfect utility evaluation function, what would it mean about the minimax tree?

Evaluation functions If you had a perfect utility evaluation function, what would it mean about the minimax tree? You would never have to evaluate more than one level deep! Typically, you can t create such perfect utility evaluations, though.

Pruning the Minimax Tree Since we have limited time available, we want to avoid unnecessary computation in the minimax tree. Pruning: ways of determining that certain branches will not be useful

a Cuts If the current max value is greater than the successor s min value, don t explore that min subtree any more

a Cut example -3 Min -3-4 -73 21-3 12 70-4 100-73 -14

a Cut example Min 21-3 12-70 -4 100-73 -14 Depth first search along path 1

a Cut example Min 21 21-3 12-70 -4 100-73 -14 21 is minimum so far (second level) Can t evaluate yet at top level

a Cut example -3 Min -3 21-3 12-70 -4 100-73 -14-3 is minimum so far (second level) -3 is maximum so far (top level)

a Cut example -3 Min -3 12 21-3 12-70 -4 100-73 -14 12 is minimum so far (second level) -3 is still maximum (can t use second node yet)

a Cut example -3 Min -3-70 21-3 12-70 -4 100-73 -14-70 is now minimum so far (second level) -3 is still maximum (can t use second node yet)

a Cut example -3 Min -3-70 21-3 12-70 -4 100-73 -14 Since second level node will never be > -70, it will never be chosen by the previous level We can stop exploring that node

a Cut example -3 Min -3-70 -73 21-3 12-70 -4 100-73 -14 Evaluation at second level is -73

a Cut example -3 Min -3-70 -73 21-3 12-70 -4 100-73 -14 Again, can apply a cut since the second level node will never be > -73, and thus will never be chosen by the previous level

a Cut example -3 Min -3-70 -73 21-3 12-70 -4 100-73 -14 As a result, we evaluated the node without evaluating several of the possible paths

b cuts Similar idea to a cuts, but the other way around If the current minimum is less than the successor s max value, don t look down that max tree any more

b Cut example Min 21 21 70 73 Min 21-3 12 70-4 100 73-14 Some subtrees at second level already have values > min from previous, so we can stop evaluating them.

a-b Pruning Pruning by these cuts does not affect final result May allow you to go much deeper in tree Good ordering * of moves can make this pruning much more efficient Evaluating best branch first yields better likelihood of pruning later branches Perfect ordering reduces time to b m/2 i.e. doubles the depth you can search to! *Will come back to it in a bit

a-b Pruning Can store information along an entire path, not just at most recent levels! Keep along the path: a: best MAX value found on this path (initialize to most negative utility value) b: best MIN value found on this path (initialize to most positive utility value)

Pruning at MAX node a is possibly updated by the MAX of successors evaluated so far If the value that would be returned is ever > b, then stop work on this branch If all children are evaluated without pruning, return the MAX of their values

Pruning at MIN node b is possibly updated by the MIN of successors evaluated so far If the value that would be returned is ever < a, then stop work on this branch If all children are evaluated without pruning, return the MIN of their values

Idea of a-b Pruning 21 21 21-3 We know b on this path is 21 So, when we get max=70, we know this will never be used, so we can stop here 12 70-4 100 70

Refined Minimax Tree With Alpha-Beta Pruning function TERNINAL-TEST (state, depth) if LEAF-NODE (state) OR depth >= MAX_DEPTH return TRUE return FALSE function MAX-VALUE (state, depth, alpha, beta) if TERMINAL-TEST (state, depth) return UTILITY (state) v = INT_MIN // minimum possible integer, emulating inf foreach s in SUCCESSORS (state) v = MAX (v, MIN-VALUE (s, depth+1, alpha, beta)) alpha = MAX (v, alpha) // update the current alpha if (v > beta) return v //prune this branch if v>beta return v

Idea of a-b Pruning Pruning gives the exact same result that you would have gotten without pruning It just allows you to go deeper Pruning and searching the minimax tree are independent of the particular game being studied The game influences: The utility function The branching ratio/options at any one level

Evaluation Functions for Ordering As mentioned earlier, order of branch evaluation can make a big difference in how well you can prune A good evaluation function might help you order your available moves First order the SUCCESSOR nodes on the UTILITY value This happens before completely expanding that node Then, expand DFS on the node with best value

FAQs What kind of tree data structure for the minimax tree? You do not really need to allocate a tree. We are just referring to the recursion tree inherently being created Our game works fine without alpha-beta pruning not much delay for the AI. Why do we still need pruning? This delay would be very prominent for more complicated games (e.g., chess) Why do we need to re-order the successor nodes? Again, you may not see a difference for Kalah, but it is feature and you will get points for it. The motivation is that this gives you much more speedup in a more complicated game What type of GUI do we need? Will we just do any GUI, will we full 10% points? To get full GUI points, you need to handle the game using mouse clicks and keyboard events both