Sie sind auf Seite 1von 35

ALPHA-BETA PRUNING

INTRODUCTION
Alpha-Beta Pruning is a search algorithm that seeks to decrease the number of nodes that are evaluated by the minimax algorithm in its search tree. It is an adversarial search algorithm used commonly for machine playing of two player games (Tic-Toc-Toe, Chess, etc.). It stop completely evaluating a move when atleast one possibility has been found that proves the move to be worse than previously examined move.

NEW IN ALPHA-BETA PRUNING


Main idea: Avoid processing subtrees that have no effect on the result

Two new parameters


: is used in MIN nodes, and is assigned in MAX nodes : is used in MAX nodes, and is assigned in MIN nodes

ALPHA-BETA EXAMPLE
Do DF-search until first leaf Range of possible values

[-,+]

[-, +]

ALPHA-BETA EXAMPLE (CONTINUED)

[-,+]

[-,3]

ALPHA-BETA EXAMPLE (CONTINUED)

[-,+]

[-,3]

ALPHA-BETA EXAMPLE (CONTINUED)

[3,+]

[3,3]

ALPHA-BETA EXAMPLE (CONTINUED)

[3,+]

This node is worse for MAX


[3,3] [-,2]

ALPHA-BETA EXAMPLE (CONTINUED)

[3,14]

[3,3]

[-,2]

[-,14]

ALPHA-BETA EXAMPLE (CONTINUED)

[3,5]

[3,3]

[,2]

[-,5]

10

ALPHA-BETA EXAMPLE (CONTINUED)

[3,3]

[3,3]

[,2]

[2,2]

11

ALPHA-BETA EXAMPLE (CONTINUED)

[3,3]

[3,3]

[-,2]

[2,2]

12

ALPHA-BETA ALGORITHM
Depth first search

only considers nodes along a single path from root at any time
a = highest-value choice found at any choice point of path for MAX (initially, a = infinity) b = lowest-value choice found at any choice point of path for MIN (initially, b = +infinity) Pass current values of a and b down to child nodes during search. Update values of a and b during search:

MAX updates a at MAX nodes MIN updates b at MIN nodes Prune remaining branches at a node when a b

13

WHEN TO PRUNE
Prune whenever a b. Prune below a Max node whose alpha value becomes greater than or equal to the beta value of its ancestors.
Max nodes update alpha based on childrens returned values.

Prune below a Min node whose beta value becomes less than or equal to the alpha value of its ancestors.
Min nodes update beta based on childrens returned values.

14

ALPHA-BETA EXAMPLE REVISITED


Do DF-search until first leaf

a, b, initial values

a= b =+

a, b, passed to kids

a= b =+

15

ALPHA-BETA EXAMPLE (CONTINUED)

a= b =+

a= b =3
MIN updates b, based on kids

16

ALPHA-BETA EXAMPLE (CONTINUED)

a= b =+

a= b =3
MIN updates b, based on kids. No change.

17

ALPHA-BETA EXAMPLE (CONTINUED) MAX updates a, based on kids.

a=3 b =+

3 is returned as node value.

18

ALPHA-BETA EXAMPLE (CONTINUED)

a=3 b =+
a, b, passed to kids

a=3 b =+

19

ALPHA-BETA EXAMPLE (CONTINUED)

a=3 b =+
MIN updates b, based on kids.

a=3 b =2

20

ALPHA-BETA EXAMPLE (CONTINUED)

a=3 b =+
a=3 b =2
a b,
so prune.

21

ALPHA-BETA EXAMPLE (CONTINUED) MAX updates a, based on kids. No change. a=3

b =+

2 is returned as node value.

22

ALPHA-BETA EXAMPLE (CONTINUED)

a=3 b =+

,
a, b, passed to kids

a=3 b =+

23

ALPHA-BETA EXAMPLE (CONTINUED)

a=3 b =+

MIN updates b, based on kids.

a=3 b =14

24

ALPHA-BETA EXAMPLE (CONTINUED)

a=3 b =+

, MIN updates b, based on kids.

a=3 b =5

25

ALPHA-BETA EXAMPLE (CONTINUED)

a=3 b =+

2 is returned as node value.

26

ALPHA-BETA EXAMPLE (CONTINUED)

Max calculates the same node value, and makes the same move!
2

27

EFFECTIVENESS OF ALPHA-BETA
Alpha-beta is guaranteed to compute the same value for the root node as computed by minimax, with less or equal computation Worst case: branches are ordered so that no pruning takes place. examining b^d leaf nodes, where each node has b children and a d-ply search is performed Best case: examine only (b)^(d/2) leaf nodes. Result is you can search twice as deep as minimax! Best case is when each players best move is the first alternative generated
In practice often get O(b(d/2)) rather than O(bd) e.g., in chess go from b ~ 35 to b ~ 6
this permits much deeper search in the same amount of time

28

FINAL COMMENTS ABOUT ALPHA-BETA PRUNING


Pruning does not affect final results

Entire subtrees can be pruned.

Good move ordering improves effectiveness of pruning

Repeated states are again possible. Store them in memory = transposition table

29

EXAMPLE

-which nodes can be pruned?

6 30

ANSWER TO EXAMPLE
Max -which nodes can be pruned?

Min

Max 6 5 3 4 1 2 7 8 Answer: NONE! Because the most favorable nodes for both are explored last (i.e., in the diagram, are on the right-hand side).

31

SECOND EXAMPLE (THE EXACT MIRROR IMAGE OF THE FIRST EXAMPLE) -which nodes can be pruned?

4 32

ANSWER TO SECOND EXAMPLE (THE EXACT MIRROR IMAGE OF THE FIRST EXAMPLE) -which nodes can be pruned?
Max

Min

Max
4 3 6 5 8 7 2 1 Answer: LOTS! Because the most favorable nodes for both are explored first (i.e., in the diagram, are on the left-hand side).

33

QUESTIONS ?

34

THANK YOU!
35

Das könnte Ihnen auch gefallen