Backtracking and Games Eric Roberts CS 106B January 28, 2013.

Slides:



Advertisements
Similar presentations
Adversarial Search Chapter 6 Sections 1 – 4. Outline Optimal decisions α-β pruning Imperfect, real-time decisions.
Advertisements

Adversarial Search Chapter 6 Section 1 – 4. Types of Games.
Games & Adversarial Search Chapter 5. Games vs. search problems "Unpredictable" opponent  specifying a move for every possible opponent’s reply. Time.
Games & Adversarial Search
Artificial Intelligence Adversarial search Fall 2008 professor: Luigi Ceccaroni.
CS 484 – Artificial Intelligence
Adversarial Search Chapter 6 Section 1 – 4.
Adversarial Search Chapter 5.
Lecture 12 Last time: CSPs, backtracking, forward checking Today: Game Playing.
Adversarial Search CSE 473 University of Washington.
Hoe schaakt een computer? Arnold Meijster. Why study games? Fun Historically major subject in AI Interesting subject of study because they are hard Games.
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.
G51IAI Introduction to AI Minmax and Alpha Beta Pruning Garry Kasparov and Deep Blue. © 1997, GM Gabriel Schwartzman's Chess Camera, courtesy IBM.
Chess AI’s, How do they work? Math Club 10/03/2011.
Minimax and Alpha-Beta Reduction Borrows from Spring 2006 CS 440 Lecture Slides.
State Space 4 Chapter 4 Adversarial Games. Two Flavors Games of Perfect Information ◦Each player knows everything that can be known ◦Chess, Othello Games.
Backtracking COP Backtracking  Backtracking is a technique used to solve problems with a large search space, by systematically trying and eliminating.
November 10, 2009Introduction to Cognitive Science Lecture 17: Game-Playing Algorithms 1 Decision Trees Many classes of problems can be formalized as search.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Ch.6: Adversarial Search Fall 2008 Marco Valtorta.
MAE 552 – Heuristic Optimization Lecture 28 April 5, 2002 Topic:Chess Programs Utilizing Tree Searches.
Adversarial Search: Game Playing Reading: Chess paper.
Games & Adversarial Search Chapter 6 Section 1 – 4.
Alpha-Beta Search. 2 Two-player games The object of a search is to find a path from the starting position to a goal position In a puzzle-type problem,
Backtracking.
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.
Game Trees: MiniMax strategy, Tree Evaluation, Pruning, Utility evaluation Adapted from slides of Yoonsuck Choe.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 2 Adapted from slides of Yoonsuck.
Lecture 5 Note: Some slides and/or pictures are adapted from Lecture slides / Books of Dr Zafar Alvi. Text Book - Aritificial Intelligence Illuminated.
KU NLP Heuristic Search Heuristic Search and Expert Systems (1) q An interesting approach to implementing heuristics is the use of confidence.
Game Playing.
1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah
Agents that can play multi-player games. Recall: Single-player, fully-observable, deterministic game agents An agent that plays Peg Solitaire involves.
Section 3.1: Proof Strategy Now that we have a fair amount of experience with proofs, we will start to prove more difficult theorems. Our experience so.
Adversarial Search Chapter 6 Section 1 – 4. Outline Optimal decisions α-β pruning Imperfect, real-time decisions.
For Wednesday Read Weiss, chapter 12, section 2 Homework: –Weiss, chapter 10, exercise 36 Program 5 due.
Instructor: Vincent Conitzer
Game Playing. Towards Intelligence? Many researchers attacked “intelligent behavior” by looking to strategy games involving deep thought. Many researchers.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
1 Adversarial Search CS 171/271 (Chapter 6) Some text and images in these slides were drawn from Russel & Norvig’s published material.
GAME PLAYING 1. There were two reasons that games appeared to be a good domain in which to explore machine intelligence: 1.They provide a structured task.
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.
Adversarial Search. Regular Tic Tac Toe Play a few games. –What is the expected outcome –What kinds of moves “guarantee” that?
Adversarial Search Chapter 6 Section 1 – 4. Games vs. search problems "Unpredictable" opponent  specifying a move for every possible opponent reply Time.
February 25, 2016Introduction to Artificial Intelligence Lecture 10: Two-Player Games II 1 The Alpha-Beta Procedure Can we estimate the efficiency benefit.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 5 Adversarial Search (Thanks Meinolf Sellman!)
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.
Understanding AI of 2 Player Games. Motivation Not much experience in AI (first AI project) and no specific interests/passion that I wanted to explore.
1 Chapter 6 Game Playing. 2 Chapter 6 Contents l Game Trees l Assumptions l Static evaluation functions l Searching game trees l Minimax l Bounded lookahead.
Instructor: Vincent Conitzer
Pengantar Kecerdasan Buatan
David Kauchak CS52 – Spring 2016
Adversarial Search Chapter 5.
Adversarial Search.
Alpha-Beta Search.
NIM - a two person game n objects are in one pile
Alpha-Beta Search.
Instructor: Vincent Conitzer
Alpha-Beta Search.
Alpha-Beta Search.
Games & Adversarial Search
Adversarial Search CS 171/271 (Chapter 6)
Alpha-Beta Search.
Games & Adversarial Search
Adversarial Search Chapter 6 Section 1 – 4.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

Backtracking and Games Eric Roberts CS 106B January 28, 2013

Searching in a Branching Structure The recursive structure for finding the solution path in a maze comes up in a wide variety of applications, characterized by the need to explore a range of possibilities at each of a series of choice points. The primary advantage of using recursion in these problems is that doing so dramatically simplifies the bookkeeping. Each level of the recursive algorithm considers one choice point. The historical knowledge of what choices have already been tested and which ones remain for further exploration is maintained automatically in the execution stack. Many such applications are like the maze-solving algorithm in which the process searches a branching structure to find a particular solution. Others, however, use the same basic strategy to explore every path in a branching structure in some systematic way.

Exercise: Generating Subsets Write a function that generates a vector showing all subsets of the set formed from the letters in set. Vector generateSubsets(string set); For example, calling generateSubsets("abc") should return a vector containing the following eight strings, in some order: """a" "b" "c" "ab" "ac" "bc" "abc" The solution process requires a branching structure similar to that used to solve a maze. At each level of the recursion, you can either exclude or include the current letter from the list of subsets, as illustrated on the following slide.

The Subset Tree The set of all subsets of { a, b, c } is Has no 'b' Has a 'b' Those that don’t include 'a' Those that do include 'a' Has no 'c' Has a 'c' { }{ }{ c }{ c } Has no 'c' Has a 'c' { b }{ b }{ b, c } Has no 'b' Has a 'b' Has no 'c' Has a 'c' Has no 'c' Has a 'c' { a }{ a }{ a, c }{ a, b }{ a, b, c }

The Eight Queens Problem

bool solveNQueens(Grid & board) { int n = board.numRows(); for (int c1 = 0; c1 < n; c1++) { board[0][c1] = 'Q'; for (int c2 = 0; c2 < n; c2++) { board[1][c2] = 'Q'; for (int c3 = 0; c3 < n; c3++) { board[2][c2] = 'Q';... if (solutionFound(board)) return true;... board[2][c2] = ' '; } board[1][c2] = ' '; } board[0][c2] = ' '; } return false; } What Most Students Want to Do

Deep Blue Beats Gary Kasparov 30. b6 30. Bb8 ?? Kasparov Deep Blue Game 6 In 1997, IBM’s Deep Blue program beat Gary Kasparov, who was then the world’s human champion. In 1996, Kasparov had won in play that is in some ways more instructive abcdefgh

Recursion and Games In 1950, Claude Shannon wrote an article for Scientific American in which he described how to write a chess-playing computer program. Shannon’s strategy was to have the computer try every possible move for white, followed by all of black’s responses, and then all of white’s responses to those moves, and so on. Even with modern computers, it is impossible to use this strategy for an entire game, because there are too many possibilities. Positions evaluated: ~... millions of years later...

Game Trees As Shannon observed in 1950, most two-player games have the same basic form: –The first player (red) must choose between a set of moves –For each move, the second player (blue) has several responses. –For each of these responses, red has further choices. –For each of these new responses, blue makes another decision. –And so on...

A Simpler Game Chess is far too complex a game to serve as a useful example. The text uses a much simpler game called Nim, which is representative of a large class of two-player games. In Nim, the game begins with a pile of coins between two players. The starting number of coins can vary and should therefore be easy to change in the program. In alternating turns, each player takes one, two, or three coins from the pile in the center. The player who takes the last coin loses.

A Sample Game of Nim There are 11 coins left. I'll take 2. There are 9 coins left. Your move: There are 8 coins left. I'll take 3. There are 5 coins left. Your move: There are 3 coins left. I'll take 2. There is only one coin left. You lose. Nim 1 2

Good Moves and Bad Positions The essential insight behind the Nim program is bound up in the following mutually recursive definitions: –A good move is one that leaves your opponent in a bad position. –A bad position is one that offers no good moves. The implementation of the Nim game is really nothing more than a translation of these definitions into code.

/* * Looks for a winning move, given the specified number of coins. * If there is a winning move in that position, findGoodMove returns * that value; if not, the method returns the constant NO_GOOD_MOVE. * This implementation depends on the recursive insight that a good move * is one that leaves your opponent in a bad position and a bad position * is one that offers no good moves. */ int findGoodMove(int nCoins) { int limit = (nCoins < MAX_MOVE) ? nCoins : MAX_MOVE; for (int nTaken = 1; nTaken <= limit; nTaken++) { if (isBadPosition(nCoins - nTaken)) return nTaken; } return NO_GOOD_MOVE; } /* * Returns true if nCoins is a bad position. Being left with a single * coin is clearly a bad position and represents the simple case. */ bool isBadPosition(int nCoins) { if (nCoins == 1) return true; return findGoodMove(nCoins) == NO_GOOD_MOVE; } Coding the Nim Strategy

The Minimax Algorithm Games like Nim are simple enough that it is possible to solve them completely in a relatively small amount of time. For more complex games, it is necessary to cut off the analysis at some point and then evaluate the position, presumably using some function that looks at a position and returns a rating for that position. Positive ratings are good for the player to move; negative ones are bad. When your game player searches the tree for best move, it can’t simply choose the one with the highest rating because you control only half the play. What you want instead is to choose the move that minimizes the maximum rating available to your opponent. This strategy is called the minimax algorithm.

A Minimax Illustration +7+6 –9–9 –5–5+9 –4–4 –1–1+1 –2–2 Suppose that the ratings two turns from now are as shown. From your perspective, the +9 initially looks attractive. Unfortunately, your can’t get there, since the –5 is better for your opponent. The best you can do is choose the move that leads to the –2.

The End