game playing
play

Game Playing Part 2 Alpha-Beta Pruning Yingyu Liang - PowerPoint PPT Presentation

Game Playing Part 2 Alpha-Beta Pruning Yingyu Liang yliang@cs.wisc.edu Computer Sciences Department University of Wisconsin, Madison [based on slides from A. Moore http://www.cs.cmu.edu/~awm/tutorials , C. Dyer, J. Skrentny, Jerry Zhu] slide 1


  1. Game Playing Part 2 Alpha-Beta Pruning Yingyu Liang yliang@cs.wisc.edu Computer Sciences Department University of Wisconsin, Madison [based on slides from A. Moore http://www.cs.cmu.edu/~awm/tutorials , C. Dyer, J. Skrentny, Jerry Zhu] slide 1

  2. alpha-beta pruning Gives the same game theoretic values as minimax, but prunes part of the game tree. "If you have an idea that is surely bad, don't take the time to see how truly awful it is." -- Pat Winston slide 2

  3. Alpha-Beta Motivation max S A min B 100 C D E F G 200 100 120 20 • Depth-first order • After returning from A, Max can get at least 100 at S • After returning from F, Max can get at most 20 at B • At this point, Max losts interest in B • There is no need to explore G. The subtree at G is pruned. Saves time. slide 3

  4. Alpha-beta pruning function Max-Value (s,α,β) Starting from the root: inputs: Max-Value(root, -  , +  ) s: current state in game, Max about to play α: best score (highest) for Max along path to s β: best score (lowest) for Min along path to s output: min (β , best-score (for Max) available from s ) if ( s is a terminal state ) then return ( terminal value of s ) else for each s ’ in Succ(s) α := max( α , Min-value(s ’,α,β)) if ( α ≥ β ) then return β /* alpha pruning */ return α slide 4

  5. Alpha-beta pruning function Max-Value (s,α,β) Starting from the root: inputs: Max-Value(root, -  , +  ) s: current state in game, Max about to play α: best score (highest) for Max along path to s β: best score (lowest) for Min along path to s output: min (β , best-score (for Max) available from s ) if ( s is a terminal state ) then return ( terminal value of s ) else for each s ’ in Succ(s) α := max( α , Min-value(s ’,α,β)) if ( α ≥ β ) then return β /* alpha pruning */ return α function Min-Value (s,α,β) output: max (α , best-score (for Min) available from s ) if ( s is a terminal state ) then return ( terminal value of s) else for each s ’ in Succs(s) β := min( β , Max-value(s ’,α,β)) if (α ≥ β ) then return α /* beta pruning */ return β slide 5

  6. Alpha-beta pruning example 1 α= -  max β=+  S A min B 100 C D E F G 200 100 120 20 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 6

  7. Alpha-beta pruning example 1 α= -  max β=+  S α= -  A min B β=+  100 C D E F G 200 100 120 20 slide 7

  8. Alpha-beta pruning example 1 α= -  max β=+  S α= -  A min B β= 200 100 C D E F G 200 100 120 20 slide 8

  9. Alpha-beta pruning example 1 α= -  max β=+  S α= -  A min B β= 100 100 C D E F G 200 100 120 20 slide 9

  10. Alpha-beta pruning example 1 α= 100 max β=+  S α= -  A min B β= 100 100 C D E F G 200 100 120 20 slide 10

  11. Alpha-beta pruning example 1 α= 100 max β=+  S α= 100 α= -  A min B β=+  β=100 100 C D E F G 200 100 120 20 slide 11

  12. Alpha-beta pruning example 1 α=100 max β=+  S α= 100 α= -  A min B β= 120 β= 100 100 C D E F G 200 100 120 20 slide 12

  13. Alpha-beta pruning example 1 α= 100 max β=+  S α=100 α= -  A min B β=20 β=100 100 X C D E F G 200 100 120 20 slide 13

  14. Alpha-beta pruning function Max-Value (s,α,β) Starting from the root: inputs: Max-Value(root, -  , +  ) s: current state in game, Max about to play α: best score (highest) for Max along path to s β: best score (lowest) for Min along path to s output: min (β , best-score (for Max) available from s ) if ( s is a terminal state ) then return ( terminal value of s ) else for each s ’ in Succ(s) α := max( α , Min-value(s ’,α,β)) if ( α ≥ β ) then return β /* alpha pruning */ return α function Min-Value (s,α,β) output: max (α , best-score (for Min) available from s ) if ( s is a terminal state ) then return ( terminal value of s) else for each s ’ in Succs(s) β := min( β , Max-value(s ’,α,β)) if (α ≥ β ) then return α /* beta pruning */ return β slide 14

  15. Alpha-beta pruning example 1 max S What are the alpha and beta values on S? min A max C B 25 20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 15

  16. Alpha-beta pruning example 2 max α= -  S β=+  min A max C B 25 20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 16

  17. Alpha-beta pruning example 2 max S α= -  min A β=+  max C B 25 20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 17

  18. Alpha-beta pruning example 2 max S min A max α= -  C B 25 β=+  20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 18

  19. Alpha-beta pruning example 2 max S min A max C α=20 B 25 β=+  20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 19

  20. Alpha-beta pruning example 2 max S min A max C α= 20 B 25 β=+  20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 20

  21. Alpha-beta pruning example 2 max S min A max C α= 20 B 25 β=+  20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 21

  22. Alpha-beta pruning example 2 max S min What are the alpha and beta A values on A? max C α= 20 B 25 β=+  20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 22

  23. Alpha-beta pruning example 2 max S min α= -  A β= 20 max C B 25 20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 23

  24. Alpha-beta pruning example 2 max S min A α= -  max C B β= 20 25 20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 24

  25. Alpha-beta pruning example 2 max S min A α= -20 max C B β=20 25 20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 25

  26. Alpha-beta pruning example 2 max S min A α= 25 max C B β= 20 25 20 X D E F G H 20 -10 -20 25 • Keep two bounds along the path ▪  : the best Max can do ▪  : the best (smallest) Min can do • If at anytime  exceeds  , the remaining children are pruned. slide 26

  27. Yet another alpha-beta pruning example • Keep two bounds along the path ▪  : the best Max can do on the path ▪  : the best (smallest) Min can do on the path • If at anytime  exceeds  , the remaining children are pruned. – = –  A + = +  A max α =- D B C E 0 G H I L F J K M -5 3 8 2 N P Q R S T U V O 4 9 -6 0 3 5 -7 -9 W X -3 -5 [Example from James Skrentny] slide 27

  28. Alpha-beta pruning example • Keep two bounds along the path ▪  : the best Max can do on the path ▪  : the best (smallest) Min can do on the path • If a max node exceeds  , it is pruned. • If a min node goes below  , it is pruned. A max α =- B D β B C E 0 = min + G H I L F J K M -5 3 8 2 N P Q R S T U V O 4 9 -6 0 3 5 -7 -9 W X -3 -5 [Example from James Skrentny] slide 28

  29. Alpha-beta pruning example • Keep two bounds along the path ▪  : the best Max can do on the path ▪  : the best (smallest) Min can do on the path • If a max node exceeds  , it is pruned. • If a min node goes below  , it is pruned. A max α =- B D β C E = 0 + min F G H I L F J K M α -5 3 8 2 =- max N P Q R S T U V O 4 9 -6 0 3 5 -7 -9 W X -3 -5 [Example from James Skrentny] slide 29

Recommend


More recommend