CS61B Lecture #22. Today: Backtracking searches, game trees (DSIJ, Section 6.5) Last modified: Mon Oct 17 20:55: CS61B: Lecture #22 1

Similar documents
CS61B Lecture #33. Today: Backtracking searches, game trees (DSIJ, Section 6.5)

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

Adversary Search. Ref: Chapter 5

ARTIFICIAL INTELLIGENCE (CS 370D)

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

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

mywbut.com Two agent games : alpha beta pruning

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

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

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

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

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

Game-Playing & Adversarial Search

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

More Recursion: NQueens

COMP219: Artificial Intelligence. Lecture 13: Game Playing

CS 188: Artificial Intelligence Spring 2007

CS 771 Artificial Intelligence. Adversarial Search

CS 4700: Artificial Intelligence

Foundations of Artificial Intelligence

Games and Adversarial Search II

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

Games (adversarial search problems)

Adversarial Search 1

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

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

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

Adversarial Search Aka Games

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

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

CS188 Spring 2010 Section 3: Game Trees

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

CS 540-2: Introduction to Artificial Intelligence Homework Assignment #2. Assigned: Monday, February 6 Due: Saturday, February 18

Programming Project 1: Pacman (Due )

Artificial Intelligence Search III

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

CSC384: Introduction to Artificial Intelligence. Game Tree Search

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

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

ADVERSARIAL SEARCH. Chapter 5

Game-playing AIs: Games and Adversarial Search I AIMA

CS188 Spring 2010 Section 3: Game Trees

UNIVERSITY of PENNSYLVANIA CIS 391/521: Fundamentals of AI Midterm 1, Spring 2010

More on games (Ch )

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

CMPUT 396 Tic-Tac-Toe Game

CS 5522: Artificial Intelligence II

Adversarial Search (Game Playing)

Game Tree Search. Generalizing Search Problems. Two-person Zero-Sum Games. Generalizing Search Problems. CSC384: Intro to Artificial Intelligence

: Principles of Automated Reasoning and Decision Making Midterm

Game Playing Part 1 Minimax Search

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

2 person perfect information

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

game tree complete all possible moves

Game Playing State-of-the-Art

CS 331: Artificial Intelligence Adversarial Search II. Outline

Foundations of Artificial Intelligence

CS 188: Artificial Intelligence

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

CS 188: Artificial Intelligence Spring Announcements

More on games (Ch )

Game playing. Chapter 5. Chapter 5 1

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

Tree representation Utility function

CS 387/680: GAME AI BOARD GAMES

Foundations of Artificial Intelligence

Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning

Computer Game Programming Board Games

Game Playing: Adversarial Search. Chapter 5

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

CS 188: Artificial Intelligence

Game-playing: DeepBlue and AlphaGo

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

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

CSE : Python Programming

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

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

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

CSC 396 : Introduction to Artificial Intelligence

Written examination TIN175/DIT411, Introduction to Artificial Intelligence

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

Midterm Examination. CSCI 561: Artificial Intelligence

Prepared by Vaishnavi Moorthy Asst Prof- Dept of Cse

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

Artificial Intelligence

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

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

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

Artificial Intelligence

CS 380: ARTIFICIAL INTELLIGENCE

Game Playing AI. Dr. Baldassano Yu s Elite Education

Adversarial Search. Hal Daumé III. Computer Science University of Maryland CS 421: Introduction to Artificial Intelligence 9 Feb 2012

Game playing. Chapter 6. Chapter 6 1

Project 1. Out of 20 points. Only 30% of final grade 5-6 projects in total. Extra day: 10%

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

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

Artificial Intelligence Lecture 3

COMP9414: Artificial Intelligence Adversarial Search

Problem 1. (15 points) Consider the so-called Cryptarithmetic problem shown below.

Transcription:

CS61B Lecture #22 Today: Backtracking searches, game trees (DSIJ, Section 6.5) Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 1

Searching by Generate and Test We vebeenconsideringtheproblemofsearchingasetofdatastored in some kind of data structure: Is x S? But suppose we don t have a set S, but know how to recognize what we re after if we find it: Is there an x such that P(x)? If we know how to enumerate all possible candidates, can use approach of Generate and Test: test all possibilities in turn. Can sometimes be more clever: avoid trying things that won t work, for example. What happens if the set of possible candidates is infinite? Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 2

Backtracking Search Backtracking search is one way to enumerate all possibilities. Example: Knight s Tour. Find all paths a knight can travel on a chessboard such that it touches every square exactly once and ends up one knight move from where it started. In the example below, the numbers indicate position numbers(knight starts at 0). Here, knight (N) is stuck; how to handle this? 6 5 4 7 10 2 8 3 0 N 9 1 Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 3

General Recursive Algorithm / Append to PATH a sequence of knight moves starting at ROW, COL that avoids all squares that have been hit already and that ends up one square away from ENDROW, ENDCOL. B[i][j] is true iff row i and column j have been hit on PATH so far. Returns true if it succeeds, else false (with no change to PATH). Call initially with PATH containing the starting square, and the starting square (only) marked in B. / boolean findpath(boolean[][] b, int row, int col, int endrow, int endcol, List path) { if (path.size() == 64) return isknightmove(row, col, endrow, endcol); for (r, c = all possible moves from (row, col)) { if (!b[r][c]) { b[r][c] = true; // Mark the square path.add(new Move(r, c)); if (findpath(b, r, c, endrow, endcol, path)) return true; b[r][c] = false; // Backtrack out of the move. path.remove(path.size()-1); return false; Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 4

Another Kind of Search: Best Move Considertheproblemoffindingthebest moveinatwo-persongame. One way: assign a heuristic value to each possible move and pick highest (aka static evaluation). Examples: number of black pieces number of white pieces in checkers. weighted sum of white piece values weighted sum of black pieces in chess (Queen=9, Rook=5, etc.) Nearness of pieces to strategic areas (center of board). But this is misleading. A move might give us more pieces, but set up a devastating response from the opponent. So, for each move, look at opponent s possible moves, assume he picks the best one for him, and use that as the value. But what if you have a great response to his response? How do we organize this sensibly? Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 5

Game Trees Think of the space of possible continuations of the game as a tree. Each node is a position, each edge a move. My move (maximizing) Opponent s move (minimizing) My move -30-5 5 15-20 -30 9 10 Opponent s move Suppose numbers at the bottom are the values of those final positions to me. Smaller numbers are of more value to my opponent. What should I move? What value can I get if my opponent plays as well as possible? Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 6

Game Trees, Minimax Think of the space of possible continuations of the game as a tree. Each node is a position, each edge a move. -5 My move -5-20 -5 15-20 10 Opponent s move My move -30-5 5 15-20 -30 9 10 Opponent s move Numbers are the values we guess for the positions (larger means better for me). Starred nodes would be chosen. I always choose child (next position) with maximum value; opponent chooses minimum value ( Minimax algorithm ) Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 7

Alpha-Beta Pruning We can prune this tree as we search it. -5 My move -5-20 Opponent s move -5 5-30 -5 5-20 -20-30 My move Opponent s move At the 5 position, I know that the opponent will not choose to move here (since he already has a 5 move). At the 20 position, my opponent knows that I will never choose to move here (since I already have a 5 move). Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 8

Cutting off the Search If you could traverse game tree to the bottom, you d be able to force a win (if it s possible). Sometimes possible near the end of a game. Unfortunately, game trees tend to be either infinite or impossibly large. So, we choose a maximum depth, and use a heuristic value computed on the position alone (called a static valuation) as the value at that depth. Or we might use iterative deepening (kind of breadth-first search), and repeat the search at increasing depths until time is up. Much more sophisticated searches are possible, however(take CS188). Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 9

Overall Search Algorithm Depending on whose move it is(maximizing player or minimizing player), we ll search for a move estimated to be optimal in one direction or the other. Search will be exhaustive down to a particular depth in the game tree; below that, we guess values. Also pass α and β limits: High player does not care about exploring a position further once he knows its value is largerthanwhat the minimizingplayer knows he can get (β), because the minimizing player will never allow that position to come about. Likewise, minimizing player won t explore a positions whose value is less than what the maximizing player knows he can get (α). To start, a maximizing player will find a move with findmax(current position, search depth, + ) minimizing player: findmin(current position, search depth, + ) Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 10

Some Pseudocode for Searching (One Level) The most basic kind of game-tree search is to assign some heuristic value to any given position, looking at just the next possible move: Move simplefindmax(position posn, double alpha, double beta) { if (posn.maxplayerwon()) return artificial Move with value + ; else if (posn.minplayerwon()) return artificial Move with value ; Move bestsofar = artificial Move with value ; for (each M = a legal move for maximizing player from posn) { Position next = posn.makemove(m); next.setvalue(heuristicestimate(next)); if (next.value() >= bestsofar.value()) { bestsofar = next; alpha = max(alpha, next.value()); if (beta <= alpha) break; return bestsofar; Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 11

One-Level Search for Minimizing Player Move simplefindmin(position posn, double alpha, double beta) { if (posn.maxplayerwon()) return artificial Move with value + ; else if (posn.minplayerwon()) return artificial Move with value ; Move bestsofar = artificial Move with value + ; for (each M = a legal move for minimizing player from posn) { Position next = posn.makemove(m); next.setvalue(heuristicestimate(next)); if (next.value() <= bestsofar.value()) { bestsofar = next; beta = min(beta, next.value()); if (beta <= alpha) break; return bestsofar; Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 12

Some Pseudocode for Searching (Maximizing Player) / Return a best move for maximizing player from POSN, searching to depth DEPTH. Any move with value >= BETA is also "good enough". / Move findmax(position posn, int depth, double alpha, double beta) { if (depth == 0 gameover(posn)) return simplefindmax(posn, alpha, beta); Move bestsofar = artificial Move with value ; for (each M = a legal move for maximizing player from posn) { Position next = posn.makemove(m); Move response = findmin(next, depth-1, alpha, beta); if (response.value() >= bestsofar.value()) { bestsofar = next; next.setvalue(response.value()); alpha = max(alpha, response.value()); if (beta <= alpha) break; return bestsofar; Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 13

Some Pseudocode for Searching (Minimizing Player) / Return a best move for minimizing player from POSN, searching to depth DEPTH. Any move with value <= ALPHA is also "good enough". / Move findmin(position posn, int depth, double alpha, double beta) { if (depth == 0 gameover(posn)) return simplefindmin(posn, alpha, beta); Move bestsofar = artificial Move with value + ; for (each M = a legal move for minimizing player from posn) { Position next = posn.makemove(m); Move response = findmax(next, depth-1, alpha, beta); if (response.value() <= bestsofar.value()) { bestsofar = next; next.setvalue(response.value()); beta = min(beta, response.value()); if (beta <= alpha) break; return bestsofar; Last modified: Mon Oct 17 20:55:07 2016 CS61B: Lecture #22 14