Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 171 Discussion Session Week 3

Similar presentations


Presentation on theme: "CS 171 Discussion Session Week 3"— Presentation transcript:

1 CS 171 Discussion Session Week 3
Jia Chen

2 Quiz 1 return First letter of your last name
A - H:  Kyoungwon Kim (Office hours Tuesday 9-10am in ICS 424A) I - P:  Zephyr Yao (Office hours Monday 9-10am in ICS 424F) Q - Z:  Dongxu Zhao (Office hours Friday 9-10am in ICS 424F) If time conflicts, send to the Reader to which you are assigned, and to a Reader with whom you do not have a time conflict, asking to be reassigned.  

3 Schedule Games (Minimax, Alpha-beta pruning) CSP

4 Game playing as a search problem
Idea: we cannot predict the behavior of the opponent, so we consider the worst case (the opponent makes the “optimal” move) Generate game tree Apply utility function to leaves Bottom up calculation At root, choose node leading to the highest value

5 Minimax

6 Can we do better? When we visit this green node, we know the value of its parent is min(2, some other numbers), which cannot be larger than 2

7 Alpha Beta Pruning

8 At root alpha = -Inf, beta = Inf, MIN Node MIN tests if new value is less than current value, so v = Inf [any number is < Inf] MIN updates beta (and use alpha from its parent MAX to prune children) MIN can prune if alpha >= beta MAX Node MAX tests if new value is greater than current value, so v=-Inf [any number is > -Inf] MAX updates Alpha (and use beta from its parent MIN to prune children) MAX can prune if alpha >= beta

9 alpha=-Inf beta=Inf v=-Inf (always less than any number) MAX

10 v=-Inf alpha=-Inf v=+Inf beta=Inf MIN

11 v=-Inf v=+Inf v=-Inf alpha=-Inf beta=Inf MAX Compare 1 and v=-Inf → 1 > v=-Inf → update v=1, alpha=1 Test if alpha >= beta; 1 >=Inf? No Compare 2 and v=1 → 2 > v=1 → update v=2, alpha=2 Test if alpha >= beta; 2 >=Inf? No

12 v=-Inf alpha=-Inf beta=2 v=2 v=2 MIN Compare 2 and v=+Inf → 2 < +inf → update v=2, alpha=-Inf, beta = 2

13 v=-Inf v=2 v=-Inf alpha=-Inf beta=2 MAX Compare 3 and v=-Inf → 3 > -Inf → update v = 3, update alpha = 3 Test if alpha >= beta → 3 >=2 Yes! Prune “MAX: Even if I return 3 or something greater than 3, MIN will enforce me to get only 2. I should check if there is a possibility of getting Lower score than 2 under this branch”

14 v=-Inf v=2 alpha=-Inf beta=2 v=3 Min Compare new value 3 and current best 2 3 > 2 ? No → keep current v=2 and beta = 2

15 v=-Inf v=2 v=-Inf alpha=-Inf beta=2 MAX Compare 5 and v=-Inf 5 > v=-Inf, update v=5 and update alpha=5 Test if v alpha >= beta → 5 >=2 Prune!

16 v=-Inf v=2 alpha=-Inf beta=2 v=5 MIN Compare 5 and v=2 Keep v=2

17 v=2 alpha=2 beta=Inf v=2 MAX Compare 2 (from MIN) and v=-Inf 2 > -Inf? → yes → update v=2, update alpha=2

18 v=2 alpha=2 beta=Inf alpha=2 v=Inf beta=Inf MIN

19 v=2 alpha=2 beta=Inf alpha=2 v=Inf beta=Inf alpha=2 v=7 beta=Inf MAX Compare 1 and v=-Inf 1 > -Inf → update v=1, update alpha? 1 > 2 No → alpha is 2 Test if alpha >= beta( Inf) ? No Compare 7 and v=1 7 > 1 → update v=7, update alpha 7 > 2 Yes→ alpha is 7 Test if alpha >=Inf? No

20 v=2 alpha=2 beta=Inf alpha=2 v=7 beta=7 v=7 MIN Compare 7 from MAX and v=Inf 7 < INF → update v=7, update beta = 7 Test if alpha >= beta? 2 >=7 No (if MAX branch was (1,2) then beta would become 2 Then alpha >= 2? Yes) MIN updates beta from INF to 7 If beta <= alpha then Prune not!! 7 <=2

21 v=2 alpha=2 beta=Inf alpha=2 v=7 beta=7 v=7 MIN MIN player wishes to search for some score which is less than or equal to 2 from the search space below (B)

22 v=2 alpha=2 beta=Inf v=7 v=7 v=8 alpha=8 MAX update v=8; alpha=8 Test if alpha >=beta; 8 >=7 Yes, Because…. MIN (B) will choose 7 anyway beta=7

23 v=2 alpha=2 beta=Inf v=7 v=7 v=8 v=8 alpha=2 (from B) MAX v =3; alpha=3 Test if alpha >= beta; 3 >=7 No MAX player cannot prune v=8; alpha = 8 Could test… but no more nodes.. beta=7

24 v=7 alpha=7 beta=Inf v=INF alpha=7 beta=Inf v=7 v=8 v=8 MIN

25 v=7 alpha=7 beta=Inf v=INF alpha=7 beta=Inf v=1 v=7 v=8 v=8 alpha=7 beta=Inf MAX Update v as 0; alpha remains 7; Alpha >= beta? 7>= INF? No Update v as 1; alpha remains 7;

26 v=7 alpha=7 beta=Inf v=INF alpha=7 beta=1 v=1 v=7 v=8 v=8 alpha=7 MIN Update v as 1; update beta as 1 Test if alpha >= beta; 7>=1 Yes, Prune beta=Inf

27 CSP

28 CSP

29

30

31 TFFF

32

33 NW BC SA all 2 values remaining

34 B [from 3 possible choice R,G,B]
R (ON 1 NU1 SA 1 total 3) G (ON 1 NU 1 SA 1 total 3) B (ON 1 NU 1 SA 0 total 2)


Download ppt "CS 171 Discussion Session Week 3"

Similar presentations


Ads by Google