Data Structures and Algorithms

Similar documents
Game Engineering CS F-24 Board / Strategy Games

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

ARTIFICIAL INTELLIGENCE (CS 370D)

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

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

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

Adversary Search. Ref: Chapter 5

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

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

Multiple Agents. Why can t we all just get along? (Rodney King)

CS188 Spring 2014 Section 3: Games

CS188 Spring 2010 Section 3: Game Trees

CSE 40171: Artificial Intelligence. Adversarial Search: Game Trees, Alpha-Beta Pruning; Imperfect Decisions

Adversarial Search 1

CS 331: Artificial Intelligence Adversarial Search II. Outline

CS 4700: Foundations of Artificial Intelligence

mywbut.com Two agent games : alpha beta pruning

Foundations of Artificial Intelligence

Games and Adversarial Search

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

Game playing. Outline

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

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

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

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

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

Artificial Intelligence

Adversarial Search: Game Playing. Reading: Chapter

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

CS188 Spring 2010 Section 3: Game Trees

Game Playing. Philipp Koehn. 29 September 2015

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

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

Ar#ficial)Intelligence!!

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

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

4. Games and search. Lecture Artificial Intelligence (4ov / 8op)

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

Game playing. Chapter 6. Chapter 6 1

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

Games CSE 473. Kasparov Vs. Deep Junior August 2, 2003 Match ends in a 3 / 3 tie!

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

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

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

Game-playing AIs: Games and Adversarial Search I AIMA

More Adversarial Search

Game-Playing & Adversarial Search

CS 188: Artificial Intelligence

Games (adversarial search problems)

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

More on games (Ch )

CS325 Artificial Intelligence Ch. 5, Games!

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

CSC384: Introduction to Artificial Intelligence. Game Tree Search

More on games (Ch )

Adversarial Search Aka Games

Theory and Practice of Artificial Intelligence

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

Artificial Intelligence

Artificial Intelligence. Topic 5. Game playing

Game Playing State-of-the-Art

Game Playing Part 1 Minimax Search

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

School of EECS Washington State University. Artificial Intelligence

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

CSC 380 Final Presentation. Connect 4 David Alligood, Scott Swiger, Jo Van Voorhis

2 person perfect information

Adversarial search (game playing)

Foundations of Artificial Intelligence

CS 5522: Artificial Intelligence II

CS510 \ Lecture Ariel Stolerman

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

COMP219: Artificial Intelligence. Lecture 13: Game Playing

Artificial Intelligence

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

CS 380: ARTIFICIAL INTELLIGENCE

Game Playing AI Class 8 Ch , 5.4.1, 5.5

Game Playing: Adversarial Search. Chapter 5

Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning

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

Game playing. Chapter 5, Sections 1 6

Adversarial Search (Game Playing)

Foundations of Artificial Intelligence

Game playing. Chapter 5. Chapter 5 1

CS 188: Artificial Intelligence Spring Announcements

Adversarial Search. CMPSCI 383 September 29, 2011

Artificial Intelligence 1: game playing

Contents. Foundations of Artificial Intelligence. Problems. Why Board 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

CS 771 Artificial Intelligence. Adversarial Search

Computer Game Programming Board Games

Adversarial Search. Chapter 5. Mausam (Based on slides of Stuart Russell, Andrew Parks, Henry Kautz, Linda Shapiro) 1

Algorithms for solving sequential (zero-sum) games. Main case in these slides: chess. Slide pack by Tuomas Sandholm

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

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

Artificial Intelligence Adversarial Search

Lecture 5: Game Playing (Adversarial Search)

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

Solving Problems by Searching: Adversarial Search

Transcription:

Data Structures and Algorithms CS245-2015S-P4 Two Player Games David Galles Department of Computer Science University of San Francisco

P4-0: Overview Example games (board splitting, chess, Network) /Max trees Alpha-Beta Pruning Evaluation Functions

P4-1: Two player games Board-Splitting Game Two players, V & H V splits the board vertically, selects one half H splits the board horizontally, selects one half V tries to maximize the final value, H tries to minimize the final value 14 5 11 4 13 9 7 15 13 10 8 16 1 6 2

P4-2: Two player games Board-Splitting Game We assume that both players are rational (make the best possible move) How can we determine who will win the game?

P4-3: Two player games Board-Splitting Game We assume that both players are rational (make the best possible move) How can we determine who will win the game? Examine all possible games!

P4-4: Two player games Vertical 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 Horizontal 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 Horizontal 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 14 5 11 4 14 5 11 4 14 5 11 4 13 19 7 13 19 7 13 19 7 rtical Vertical Vertical Vertical 15 3 10 8 15 3 10 8 15 3 10 8 16 1 6 2 16 1 6 2 16 1 6 2 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 5 11 4 13 19 7 3 10 8 1 6 2 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 14 5 11 4 13 19 7 15 3 10 8 16 1 6 2 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-5: Two player games Max Max Max Max Max Max 4 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-6: Two player games Max 6 15 11 6 Max Max Max Max 5 15 1 11 4 6 2 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-7: Two player games Game playing agent can do this to figure out which move to make Examine all possible moves Examine all possible responses to each move... all the way to the last move Caclulate the value of each move (assuming opponent plays perfectly)

P4-8: imax Algorithm Max(node) if terminal(node) return utility(node) maxval = MIN_VALUE children = successors(node) for child in children maxval = max(maxval, (child)) return maxval (node) if terminal(node) return utility(node) minval = MAX_VALUE children = successors(node) for child in children minval = min(minval, Max(child)) return minval

P4-9: imax Algorithm Branching factor of b, game length of d moves, what are the time and space requirements for imax?

P4-10: imax Algorithm Branching factor of b, game length of d moves, what are the time and space requirements for imax? Time: O(b d ) Space: O(d) Not managable for any real games chess has an average b of 35, can t search the entire tree Need to make this more managable

P4-11: Alpha-Beta Pruning Does it matter what value is in the yellow circle? Max 6 15 11 6 Max Max Max Max 5 15 1 11 4 6 2 14 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-: Alpha-Beta Pruning If the yellow leaf has a value > 5, parent won t pick it If the yellow leaf has a value <, grandparent won t pick it To affect the root, value must be < 5 and > Max 6 15 11 6 Max Max Max Max 5 15 1 11 4 6 2 14 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-13: Alpha-Beta Pruning Value of nodes in neither yellow circle matter. Are there more? Max 6 15 11 6 Max Max Max Max 5 15 1 11 4 6 2 14 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-14: Alpha-Beta Pruning Value of nodes in none of the yellow circles matter. Max 6 15 11 6 Max Max Max Max 5 15 1 11 4 6 2 14 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-15: Alpha-Beta Pruning Player Opponent m Player Opponent n If m is better than n for Player, we will never reach n (player would pick m instead)

P4-16: Alpha-Beta Pruning Maintain two bounds, lower bound α, and an upper bound β Bounds represent the values the node must have to possibly affect the root As you search the tree, update the bounds Max nodes increase α, min nodes decrease β If the bounds ever cross, this branch cannot affect the root, we can prune it.

P4-17: Alpha-Beta Pruning Max α = -inf, β = inf Max Max Max Max 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-18: Alpha-Beta Pruning Max α = -inf, β = inf α = -inf, β = inf Max α = -inf, β = inf Max Max Max -inf, β = inf 14 5 13 15 16 3 1 11 19 4 7 10 6 8 2 -inf, β = inf

P4-19: Alpha-Beta Pruning Max α = -inf, β = inf α = -inf, β = inf Max α = -inf, β = inf Max Max Max -inf, β = 14 14 14 5 13 15 16 3 1 11 19 4 7 10 6 8 2 α = -inf, β = 14

P4-20: Alpha-Beta Pruning Max α = -inf, β = inf α = -inf, β = inf Max α =, β = inf Max Max Max α =, β = inf 5 13 15 16 3 1 11 19 4 7 10 6 8 2 α =, β = inf

P4-21: Alpha-Beta Pruning Max α = -inf, β = inf α = -inf, β = inf Max α =, β = inf Max Max Max 5 α =, β = -5 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-22: Alpha-Beta Pruning Max α = -inf, β = inf α = -inf, β = Max Max Max Max 5 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-23: Alpha-Beta Pruning Max α = -inf, β = inf α = -inf, β = Max Max α = -inf, β = Max Max α = -inf, β = 5 5 13 15 16 3 1 11 19 4 7 10 6 8 2 α = -inf, β =

P4-24: Alpha-Beta Pruning Max α = -inf, β = inf α = -inf, β = Max Max α = -inf, β = Max Max α = -inf, β = 5 15 5 13 15 16 3 1 11 19 4 7 10 6 8 2 α = -inf, β =

P4-25: Alpha-Beta Pruning Max α = -inf, β = inf α = -inf, β = 15 Max Max α = 15, β = Max Max 5 15 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-26: Alpha-Beta Pruning Max α =, β = inf 15 Max Max Max Max 5 15 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-27: Alpha-Beta Pruning Max α =, β = inf α =, β = inf α =, β = inf Max Max Max Max α =, β = inf 5 15 15 5 13 15 16 3 1 11 19 4 7 10 6 8 2 α =, β = inf

P4-28: Alpha-Beta Pruning Max α =, β = inf α =, β = inf α =, β = inf Max Max Max Max α =, β = 11 5 15 15 5 13 15 16 3 1 11 19 4 7 10 6 8 2 11

P4-29: Alpha-Beta Pruning Max α =, β = inf α =, β = inf α =, β = inf Max Max Max Max α =, β = inf 5 15 15 5 13 15 16 3 1 11 19 4 7 10 6 8 2 11 11 α =, β = inf

P4-30: Alpha-Beta Pruning Max α =, β = inf α =, β = inf α =, β = inf Max Max Max Max α =, β = 4 5 15 15 5 13 15 16 3 1 11 19 4 7 10 6 8 2 11 11 4

P4-31: Alpha-Beta Pruning Max α =, β = inf 11 α =, β = 11 15 11 Max Max Max Max 5 15 11 4 5 13 15 16 3 1 11 19 4 7 10 6 8 2

P4-32: Alpha-Beta Pruning We can cut large branches from the search tree In the previous example, what would happen with similar values and a deeper tree? If we choose the order that we evaluate nodes (more on this in a minute...), we can dramatically cut down on how much we need to search

P4-33: Evaluation Functions We can t search all the way to the bottom of the search tree Trees are just too big Search a few levels down, use an evaluation function to see how good the board looks at the moment Back up the result of the evaluation function, as if it was the utility function for the end of the game

P4-34: Evaluation Functions Chess: Material - value for each piece (pawn = 1, bishop = 3, etc) Sum of my material - sum of your material Positional advantages King protected Pawn structure Network: Partial Networks Number and length of partial networks

P4-35: Evaluation Functions If we have an evaluation function that tells us how good a move is, why do we need to search at all? Could just use the evaluation function If we are only using the evalution function, does search do us any good?

P4-36: Evaluation Functions & α-β How can we use the evaluation function to maximize the pruning in alpha-beta pruning?

P4-37: Evaluation Functions & α-β How can we use the evaluation function to maximize the pruning in alpha-beta pruning? Order children of max nodes, from highest to lowest Order children of min node, from lowest to highest (Other than for ordering, eval function is not used for interior nodes) With perfect ordering, we need to search only b d/2 (instead of b d ) to find the optimal move can search up to twice as far

P4-38: Stopping the Search We can t search all the way to the endgame Not enough time Search a set number of moves ahead Search Depth

P4-39: Stopping the Search We can t search all the way to the endgame Not enough time Search a set number of moves ahead What if we are in the middle of a piece trade? In general, what if our opponent is about to capture one of our pieces

P4-40: Stopping the Search (a) White to move (b) White to move

P4-41: Stopping the Search Quiescence Search Only apply the evaluation function to nodes that do not swing wildly in value If the next move makes a large change to the evaluation function, look ahead a few more moves Not increasing the search depth for the entire tree, just around where the action is To prevent the search from going too deep, may restrict the kinds of moves (captures only, for instance)

P4-42: Stopping the Search Horizon Problem Sometimes, we can push a bad move past the horizon of our search Not preventing the bad move, just delaying it A position will look good, even though it is utlimately bad

P4-43: Horizon Problem Black to move

P4-44: Horizon Problem Singular Extensions When we are going to stop, see if there is one move that is clearly better than all of the others. If so, do a quick search, looking only at the best move for each player Stop when there is no clearly better move Helps with the horizon problem, for a series of forced moves Similar to quiescence search