Announcements § Project 1: Search § Due tomorrow at 5pm. § Solo or in group of two. For group of two: both of you need to submit your code into edX! § Homework 2: CSPs § Has been released! Due Monday, 2/9, at 11:59pm. CS 188: ArKficial Intelligence Adversarial Search Instructor: Pieter Abbeel University of California, Berkeley [These slides were created by Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley (ai.berkeley.edu).] Game Playing State-‐of-‐the-‐Art § Checkers: 1950: First computer player. 1994: First computer champion: Chinook ended 40-‐year-‐reign of human champion Marion Tinsley using complete 8-‐piece endgame. 2007: Checkers solved! § Chess: 1997: Deep Blue defeats human champion Gary Kasparov in a six-‐game match. Deep Blue examined 200M posiKons per second, used very sophisKcated evaluaKon and undisclosed methods for extending some lines of search up to 40 ply. Current programs are even be]er, if less historic. § Go: Human champions are now starKng to be challenged by machines, though the best humans sKll beat the best machines. In go, b > 300! Classic programs use pa]ern knowledge bases, but big recent advances use Monte Carlo (randomized) expansion methods. § Pacman Behavior from ComputaKon [Demo: mystery pacman (L6D1)] Video of Demo Mystery Pacman Adversarial Games Types of Games § Many different kinds of games! § Axes: § § § § DeterminisKc or stochasKc? One, two, or more players? Zero sum? Perfect informaKon (can you see the state)? § Want algorithms for calculaKng a strategy (policy) which recommends a move from each state DeterminisKc Games § Many possible formalizaKons, one is: § § § § § § States: S (start at s0) Players: P={1...N} (usually take turns) AcKons: A (may depend on player / state) TransiKon FuncKon: SxA → S Terminal Test: S → {t,f} Terminal UKliKes: SxP → R § SoluKon for a player is a policy: S → A Zero-‐Sum Games § Zero-‐Sum Games § General Games § Agents have opposite uKliKes (values on outcomes) § Lets us think of a single value that one maximizes and the other minimizes § Adversarial, pure compeKKon § Agents have independent uKliKes (values on outcomes) § CooperaKon, indifference, compeKKon, and more are all possible § More later on non-‐zero-‐sum games Adversarial Search Single-‐Agent Trees 8 2 0 … 2 6 … 4 6 Value of a State Value of a state: The best achievable outcome (uKlity) from that state Non-‐Terminal States: 8 2 0 … 2 6 … 4 6 Terminal States: Adversarial Game Trees -‐20 -‐8 … -‐18 -‐5 … -‐10 +4 -‐20 +8 Minimax Values States Under Agent’s Control: -‐8 States Under Opponent’s Control: -‐5 -‐10 Terminal States: +8 Tic-‐Tac-‐Toe Game Tree Adversarial Search (Minimax) § DeterminisKc, zero-‐sum games: § Tic-‐tac-‐toe, chess, checkers § One player maximizes result § The other minimizes result § Minimax search: § A state-‐space search tree § Players alternate turns § Compute each node’s minimax value: the best achievable uKlity against a raKonal (opKmal) adversary Minimax values: computed recursively 5 max 5 2 8 2 5 Terminal values: part of the game min 6 Minimax ImplementaKon def max-‐value(state): iniKalize v = -∞ for each successor of state: v = max(v, min-‐value(successor)) return v def min-‐value(state): iniKalize v = +∞ for each successor of state: v = min(v, max-‐value(successor)) return v Minimax ImplementaKon (Dispatch) def value(state): if the state is a terminal state: return the state’s uKlity if the next agent is MAX: return max-‐value(state) if the next agent is MIN: return min-‐value(state) def max-‐value(state): iniKalize v = -∞ for each successor of state: v = max(v, value(successor)) return v def min-‐value(state): iniKalize v = +∞ for each successor of state: v = min(v, value(successor)) return v Minimax Example 3 12 8 2 4 6 14 Minimax Efficiency § How efficient is minimax? § Just like (exhausKve) DFS § Time: O(bm) § Space: O(bm) § Example: For chess, b ≈ 35, m ≈ 100 § Exact soluKon is completely infeasible § But, do we need to explore the whole tree? 5 2 Minimax ProperKes max min 10 10 9 100 OpKmal against a perfect player. Otherwise? [Demo: min vs exp (L6D2, L6D3)] Video of Demo Min vs. Exp (Min) Video of Demo Min vs. Exp (Exp) Resource Limits Resource Limits § Problem: In realisKc games, cannot search to leaves! § SoluKon: Depth-‐limited search § Instead, search only to a limited depth in the tree § Replace terminal uKliKes with an evaluaKon funcKon for non-‐terminal posiKons max 4 -‐2 -‐1 4 -‐2 4 ? ? min 9 § Example: § Suppose we have 100 seconds, can explore 10K nodes / sec § So can check 1M nodes per move § α-‐β reaches about depth 8 – decent chess program § Guarantee of opKmal play is gone § More plies makes a BIG difference § Use iteraKve deepening for an anyKme algorithm ? ? Depth Ma]ers § EvaluaKon funcKons are always imperfect § The deeper in the tree the evaluaKon funcKon is buried, the less the quality of the evaluaKon funcKon ma]ers § An important example of the tradeoff between complexity of features and complexity of computaKon [Demo: depth limited (L6D4, L6D5)] Video of Demo Limited Depth (2) Video of Demo Limited Depth (10) EvaluaKon FuncKons EvaluaKon FuncKons § EvaluaKon funcKons score non-‐terminals in depth-‐limited search § Ideal funcKon: returns the actual minimax value of the posiKon § In pracKce: typically weighted linear sum of features: § e.g. f1(s) = (num white queens – num black queens), etc. EvaluaKon for Pacman [Demo: thrashing d=2, thrashing d=2 (fixed evaluaKon funcKon), smart ghosts coordinate (L6D6,7,8,10)] Video of Demo Thrashing (d=2) Why Pacman Starves § A danger of replanning agents! § § § § He knows his score will go up by eaKng the dot now (west, east) He knows his score will go up just as much by eaKng the dot later (east, west) There are no point-‐scoring opportuniKes aver eaKng the dot (within the horizon, two here) Therefore, waiKng seems just as good as eaKng: he may go east, then back west in the next round of replanning! Video of Demo Thrashing -‐-‐ Fixed (d=2) Video of Demo Smart Ghosts (CoordinaKon) Video of Demo Smart Ghosts (CoordinaKon) – Zoomed In Game Tree Pruning Minimax Example 3 12 8 2 4 6 14 5 2 Minimax Pruning 3 12 8 2 14 5 2 Alpha-‐Beta Pruning § General configuraKon (MIN version) § We’re compuKng the MIN-‐VALUE at some node n MAX § We’re looping over n’s children § n’s esKmate of the childrens’ min is dropping MIN a § Who cares about n’s value? MAX § Let a be the best value that MAX can get at any choice point along the current path from the root § If n becomes worse than a, MAX will avoid it, so we can stop considering n’s other children (it’s already bad enough that it won’t be played) § MAX version is symmetric MAX MIN n Alpha-‐Beta ImplementaKon α: MAX’s best opKon on path to root β: MIN’s best opKon on path to root def max-‐value(state, α, β): iniKalize v = -∞ for each successor of state: v = max(v, value(successor, α, β)) if v ≥ β return v α = max(α, v) return v def min-‐value(state , α, β): iniKalize v = +∞ for each successor of state: v = min(v, value(successor, α, β)) if v ≤ α return v β = min(β, v) return v Alpha-‐Beta Pruning ProperKes § This pruning has no effect on minimax value computed for the root! § Values of intermediate nodes might be wrong max § Important: children of the root may have the wrong value § So the most naïve version won’t let you do acKon selecKon min § Good child ordering improves effecKveness of pruning § With “perfect ordering”: § Time complexity drops to O(bm/2) § Doubles solvable depth! § Full search of, e.g. chess, is sKll hopeless… 10 10 § This is a simple example of metareasoning (compuKng about what to compute) 0 Alpha-‐Beta Quiz Alpha-‐Beta Quiz 2 Next Time: Uncertainty! IteraKve Deepening IteraKve deepening uses DFS as a subrouKne: 1. Do a DFS which only searches for paths of length 1 or less. (DFS gives up on any path of length 2) 2. If “1” failed, do a DFS which only searches paths of length 2 or less. 3. If “2” failed, do a DFS which only searches paths of length 3 or less. ….and so on. Why do we want to do this for mulKplayer games? Note: wrongness of eval funcKons ma]ers less and less the deeper the search goes! … b
© Copyright 2024