Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMSC 421: Intro to Artificial Intelligence October 6, 2003 Lecture 7: Games Professor: Bonnie J. Dorr TA: Nate Waisbrot.

Similar presentations


Presentation on theme: "CMSC 421: Intro to Artificial Intelligence October 6, 2003 Lecture 7: Games Professor: Bonnie J. Dorr TA: Nate Waisbrot."— Presentation transcript:

1 CMSC 421: Intro to Artificial Intelligence October 6, 2003 Lecture 7: Games Professor: Bonnie J. Dorr TA: Nate Waisbrot

2 Reading Finish Chapter 6; start Chapter 7.

3 Games  Games are a form of multiagent environment  Why study games? –Fun; historically entertaining –Interesting subject of study because they are hard –Easy to represent and agents restricted to small number of actions

4 Relation of Games to Search  Search – no adversary –Solution is (heuristic) method for finding goal –Heuristics and CSP techniques can find optimal solution –Evaluation function: estimate of cost from start to goal through given node –Examples: path planning, scheduling activities  Games – adversary –Solution is strategy –Time limits force an approximate solution –Evaluation function: evaluate “goodness” of game position –Examples: chess, checkers, Othello, backgammon

5 Types of Games

6 Game Playing  Two players: MAX and MIN  MAX moves first and they take turns until the game is over  A move is planned and executed as follows: –consider all legal moves –evalute resulting position for each one –pick best position and move there –opponent moves –repeat

7 Partial Game Tree for Tic-Tac-Toe Utility values: f(n)=+1 if position is a win for X; f(n)=-1 if position is a win for O; f(n)=0 if position is a draw UTILITY -1 0 +1

8 Minimax Algorithm function MINIMAX-DECISION(state) returns an action inputs: state, current state in game v← MAX-VALUE(state) return the action in SUCCESSORS(state) with value v function MIN-VALUE(state) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v←∞ for a,s in SUCCESSORS(state) do v← MIN(v,MAX-VALUE(s)) return v function MAX-VALUE(state) returns a utility value if TERMINAL-TEST(state) then return UTILITY(state) v←−∞ for a,s in SUCCESSORS(state) do v← MAX(v,MIN-VALUE(s)) return v

9 Two-Ply Game Tree

10

11

12

13 Properties of Minimax  CriterionMinimax Complete?Yes TimeO(b m ) SpaceO(bm) Optimal?Yes 

14 How do we deal with resource limits?  Evaluation function: return an estimate of the expected utility of the game from a given position  Alpha-beta pruning: return appropriate minimax decision without exploring entire tree

15 Heuristic Evaluation Function: Tic Tac Toe 6-5=1 6-3=3 8-5=38-6=28-5=3 6-6=0 6-5=1 6-4=26-2=4 f(n) = [# of 3-lengths open for MAX] – [# of 3-lengths open for MIN]

16 Heuristic Evaluation Functions Eval(s) = w 1 f 1 (s) + w 2 f 2 (s) + … + w n f n (s)

17 What is Alpha-Beta Cutoff? MAX MIN MAX ≥ 3 3122 X 3 ≤ 2 [3,+∞] [−∞,2]

18 Alpha-beta Pruning Replace TERMINAL-TEST and UTILITY in Minimax: if TERMINAL-TEST(state) then return UTILITY(state) if CUTOFF-TEST(state) then return EVAL(state)

19 Minimax with Alpha-Beta Pruning  Set alpha-beta values for all game-tree nodes to [-∞, +∞]  For each move, run DFS to generate game tree (DFS) to a given depth  Back-up evaluation estimates whenever possible: –For MAX node n set alpha(n) to be max value found so far –For MIN node n set beta(n) to be min value found so far  Prune branches that do not change final decision: –Alpha cutoff: stop searching below MIN node if its beta value is less than or equal to the alpha value of its ancestor –Beta cutoff: stop searching below MAX node if its alpha value is greater than or equal to the beta value of its ancestor

20 Alpha-Beta Example [−∞, −∞] [−∞,+∞]

21 Alpha-Beta Example (continued) [−∞,3] [3,+∞]

22 Alpha-Beta Example (continued) [−∞,3] [3,+∞]

23 Alpha-Beta Example (continued) [3,+∞] [3,3]

24 Alpha-Beta Example (continued) [−∞,2] [3,+∞] [3,3]

25 Alpha-Beta Example (continued) [−∞,2] [3,14] [3,3][−∞,14],

26 Alpha-Beta Example (continued) [−∞,2] [3,5] [3,3][−∞,5],

27 Alpha-Beta Example (continued) [2,2] [−∞,2] [3,3]

28 Alpha-Beta Example (continued) [2,2] [−∞,2] [3,3]

29 Final Comments about Alpha- Beta Pruning  Pruning does not affect final results  Good move ordering improves effectiveness of pruning  With “perfect ordering,” time complexity is O(b m/2 )  Definition of optimal play for MAX assumes MIN plays optimally: maximizes worst-case outcome for MAX.  But if MIN does not play optimally, MAX will do even better. [Can be proved.]


Download ppt "CMSC 421: Intro to Artificial Intelligence October 6, 2003 Lecture 7: Games Professor: Bonnie J. Dorr TA: Nate Waisbrot."

Similar presentations


Ads by Google