1 / 44

Games: Efficiency

Games: Efficiency. Andrea Danyluk September 23, 2013. Announcements. Programming Assignment 1: Search Autograding done Please sign up for a code review Programming Assignment 2: Games Remove your print statements before turning it in

nelia
Télécharger la présentation

Games: Efficiency

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Games:Efficiency Andrea Danyluk September 23, 2013

  2. Announcements • Programming Assignment 1: Search • Autograding done • Please sign up for a code review • Programming Assignment 2: Games • Remove your print statements before turning it in • Need help with buggy code? If I’m not in the office, email me your code and a description of the problem.

  3. Today’s Lecture • Heuristic evaluation functions for minimax • Making the search more efficient: • α-β pruning

  4. Minimax Reality • Can rarely explore entire search space to terminal nodes. • Choose a depth cutoff – i.e., a maximum ply • Need an evaluation function • Returns an estimate of the expected utility of the game from a given position • Must order the terminal states in the same way as the true utility function • Must be efficient to compute • Trading off plies for heuristic computation • More plies makes a difference • Consider iterative deepening

  5. Evaluation Functions • Ideal: returns the utility of the position • In practice: typically weighted linear sum of features: • Eval(s) = w1f1(s) + w2f2(s) + … + wnfn(s)

  6. Exercise • Evaluation function for Connect Four?

  7. An earlier example revisited 7 6 2 3 0 -2 6 2 5 6 9 2

  8. An earlier example revisited 7 7 6 2 3 0 -2 6 2 5 6 9 2

  9. An earlier example revisited 7 3 7 6 2 3 0 -2 6 2 5 6 9 2

  10. An earlier example revisited 3 7 3 7 6 2 3 0 -2 6 2 5 6 9 2

  11. An earlier example revisited Wow! 0 is a great score! 3 7 3 0 7 6 2 3 0 -2 6 2 5 6 9 2

  12. An earlier example revisited I wonder if I can do even better! 3 7 3 0 7 6 2 3 0 -2 6 2 5 6 9 2

  13. An earlier example revisited Too bad the maximizer won’t ever let me get here! 3 7 3 0 7 6 2 3 0 -2 6 2 5 6 9 2

  14. An earlier example revisited Better not to waste my time! 3 7 3 0 7 6 2 3 0 -2 6 2 5 6 9 2

  15. An earlier example revisited 3 7 3 0 7 6 2 3 0 -2 6 2 5 6 9 2

  16. An earlier example revisited 3 0 7 3 0 7 6 2 3 0 -2 6 2 5 6 9 2

  17. An earlier example revisited 3 0 7 3 0 6 7 6 2 3 0 -2 6 2 5 6 9 2

  18. An earlier example revisited 3 0 Wow! 9! 7 3 0 6 9 7 6 2 3 0 -2 6 2 5 6 9 2

  19. An earlier example revisited 3 0 Oh, wait! 7 3 0 6 9 7 6 2 3 0 -2 6 2 5 6 9 2

  20. An earlier example revisited 3 0 Min won’t let me go here! 7 3 0 6 9 7 6 2 3 0 -2 6 2 5 6 9 2

  21. An earlier example revisited 3 0 6 Min won’t let me go here! 7 3 0 6 9 7 6 2 3 0 -2 6 2 5 6 9 2

  22. An earlier example revisited 3 0 6 Min won’t let me go here! 7 3 0 6 9 7 6 2 3 0 -2 6 2 5 6 9 2

  23. α-β Pruning • If something looks too good to be true, it probably is. • One example of the class of branch and bound algorithms with two bounds • α : the value of the best choice for Max • β : the value of the best choice for min

  24. α-β Pruning • Given these two bounds • α : the value of the best choice for Max • β : the value of the best choice for min • Basic idea of the algorithm • On a minimizing level, if you find a value < α, cut the search • On a maximizing level, if you find a value > β, cut the search

  25. functionαβSEARCH(state) returns an action a v = MAX-VALUE(state, -infinity, +infinity) return action a in ACTIONS(state) with value v function MAX-VALUE(state, α, β) returns a utility value v if TERMINAL-TEST(state) then return UTILITY(state) v = -infinity for each ainACTIONS(state) do v = MAX(v, MIN-VALUE(RESULT(state, a), α, β)) ifv ≥ βthen returnv α = MAX(α, v) returnv function MIN-VALUE(state, α, β) returns a utility value v if TERMINAL-TEST(state) then return UTILITY(state) v = infinity for each ainACTIONS(state) do v = MIN(v, MAX-VALUE(RESULT(state, a), α, β)) ifv ≤ αthen returnv β = MIN(β, v) returnv

  26. α = -inf Β = +inf 2 8 7 9 1 6 11 19 8 3 4 5

  27. α = -inf Β = +inf α = -inf Β = +inf 2 8 7 9 1 6 11 19 8 3 4 5

  28. α = -inf Β = +inf α = -inf Β = +inf α = -inf Β = +inf 2 8 7 9 1 6 11 19 8 3 4 5

  29. α = -inf Β = +inf α = -inf Β = +inf α = 8 Β = +inf 2 8 7 9 1 6 11 19 8 3 4 5

  30. α = -inf Β = +inf α = -inf Β = +inf 2 8 8 7 9 1 6 11 19 8 3 4 5

  31. α = -inf Β = +inf α = -inf Β = 8 2 8 8 7 9 1 6 11 19 8 3 4 5

  32. α = -inf Β = +inf α = -inf Β = 8 α = -inf Β = 8 2 8 8 7 9 1 6 11 19 8 3 4 5

  33. α = -inf Β = +inf α = -inf Β = 8 2 8 9 8 7 9 1 6 11 19 8 3 4 5

  34. α = -inf Β = +inf 8 2 8 9 8 7 9 1 6 11 19 8 3 4 5

  35. α = 8 Β = +inf 8 2 8 9 8 7 9 1 6 11 19 8 3 4 5

  36. α = 8 Β = +inf α = 8 Β = +inf 8 2 8 9 8 7 9 1 6 11 19 8 3 4 5

  37. α = 8 Β = +inf 2 8 2 8 9 8 7 9 1 6 11 19 8 3 4 5

  38. α = 8 Β = +inf α = 8 Β = +inf 2 8 2 8 9 8 7 9 1 6 11 19 8 3 4 5

  39. α = 8 Β = +inf α = 8 Β = +inf 2 8 α = 8 Β = +inf 2 8 9 8 7 9 1 6 11 19 8 3 4 5

  40. α = 8 Β = +inf α = 8 Β = +inf 2 8 α = 8 Β = +inf 2 8 9 8 7 9 1 6 11 19 8 3 4 5

  41. α = 8 Β = +inf α = 8 Β = +inf 2 8 2 8 9 8 8 7 9 1 6 11 19 8 3 4 5

  42. Is there a problem here??? α = 8 Β = +inf α = 8 Β = +inf 2 8 2 8 9 8 8 7 9 1 6 11 19 8 3 4 5

  43. functionαβSEARCH(state) returns an action a v = MAX-VALUE(state, -infinity, +infinity) return action a in ACTIONS(state) with value v function MAX-VALUE(state, α, β) returns a utility value v if TERMINAL-TEST(state) then return UTILITY(state) v = -infinity for each ainACTIONS(state) do v = MAX(v, MIN-VALUE(RESULT(state, a), α, β)) ifv ≥ βthen returnv α = MAX(α, v) returnv function MIN-VALUE(state, α, β) returns a utility value v if TERMINAL-TEST(state) then return UTILITY(state) v = infinity for each ainACTIONS(state) do v = MIN(v, MAX-VALUE(RESULT(state, a), α, β)) ifv ≤ αthen returnv β = MIN(β, v) returnv

  44. Properties of α-β • Pruning does not affect the final result (but be careful) • Good move ordering improves effectiveness of pruning • If search depth is d, what is the time complexity of minimax? • O(bd) • With perfect pruning, get down to O(bd/2) • Doubles solvable depth [Adapted from Russell]

More Related