1
UNIT: 5
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
GAME PLAYING: ALPHA BETA PRUNING
Alpha-BetaPruning= MinimaxExcept
• This game search strategy is a modification to Minimax game
search that avoids exploring nodes that are not useful in the
search.
• It gives the same results as Minimax but avoids exploring
some nodes.
• In the previous example, the path explored using Minimax was
A-B-D-J.
• Also the Alpha-Beta Pruning path will be A-B-D-J but
without exploring all nodes as in Minimax.
Alpha-Beta PruningMotivation
Never explore values that are not useful.
• =Min(Max(1, 2, 5), Max(6, x, y), Max(1, 3, 4))
• =Min(5, Max(6, x, y), 4)
• =Min(Max(6, x, y), 4)
• =4
Alpha-BetaGameSearch
Alpha-BetaGameSearch
Alpha-BetaGameSearch
Alpha-BetaGameSearch
Alpha-BetaGameSearch
Alpha-BetaGameSearch
5
Alpha-BetaGameSearch
5
5
Alpha-BetaGameSearch
5
5
Alpha-BetaGameSearch
5
5
Alpha-BetaGameSearch
5
5
Alpha-BetaGameSearch
7
5
5
Alpha-BetaGameSearch
7
5
5
Min(5, max(7, x,
y))
=5
Alpha-BetaGameSearch
7
5
5
Alpha-BetaGameSearch
7
5
5
Alpha-BetaGameSearch
7
5
5
Alpha-BetaGameSearch
7
5
5
5
Alpha-BetaGameSearch
7
5
5
5
Alpha-BetaGameSearch
7
5
5
5
Alpha-BetaGameSearch
7
5
5
5
Alpha-BetaGameSearch
7
5
5
5
Alpha-BetaGameSearch
7
5
5
5
4
Alpha-BetaGameSearch
7
5
5
5
4
4
Max(5, min(4, x, y,
z))
=5
Alpha-BetaGameSearch
7
5
5
5
4
4
Alpha-BetaGameSearch
7
5
5
5
4
4
Alpha-BetaGameSearch
7
5
5
5
4
4
Same results as
Minimax with fewer
nodes explored.
5 Unexplored
Branches.
Introduction
34
• Alpha-beta pruning is a way of finding the optimal minimax solution while
avoiding searching subtrees of moves which won't be selected. In the
search tree for a two-player game, there are two kinds of nodes, nodes
representing your moves and nodes representing your opponent'smoves.
• Alpha-beta pruning gets its name from two parameters.
– They describe bounds on the values that appear anywhere along the
path under consideration:
• α = the value of the best (i.e., highest value) choice found so far
along the path for MAX
• β = the value of the best (i.e., lowest value) choice found so far
along the path for MIN
Alpha Beta Pruning
35
• Alpha-beta pruning gets its name from two bounds that are passed along
during the calculation, which restrict the set of possible solutions based on
the portion of the search tree that has already been seen. Specifically,
• Beta is the minimum upper bound of possiblesolutions
• Alpha is the maximum lower bound of possiblesolutions
• Thus, when any new node is being considered as a possible path to the
solution, it can only work if:
where N is the current estimate of the value of the node
Example
36
Initial Assumption for Alpha and Beta
37
Example
38
Example
39
Example
40
• And one more time
Example
41
Example
42
Example
43
Example
44
Example
45
• We generate the next child and pass the bounds along
Example
46
Example
47
Example
48
Example
49
Example
50
Example
51
Example
52
• ... it's first child min node ...
Example
53
Example
54
Example
55
Example
56
Example
57
Example
58
Example
59
Example
60
• ... and its first child ...
Example
61
Example
62
Example
63
Example
64
Example
65
Example
66
Example
67
Example
68
Example
69
Example
70
71
• Once again, we're at a point where alpha and beta are tied, so we prune.
Note that a real solution doesn't just indicate a number, but what move led
to that number.
• If you were to run minimax on the list version presented at the start of the
example, your minimax would return a value of 3 and 6 terminal nodes
would have been examined
SYLLABUS: UNIT - 5
Advanced Topics: Game Playing: Minimax search procedure-
Adding alpha-beta cutoffs. Expert System: Representation-
Expert System shells-Knowledge Acquisition. Robotics:
Hardware-Robotic Perception-Planning-Application domains
GAME PLAYING: MINMAX Search Procedure
What is MINIMAX ?
Minimax is a kind of backtracking algorithm that is used in decision
making and game theory to find the optimal move for a player,
assuming that your opponent also plays optimally. It is widely used in
two player turn-based games such as Tic-Tac-Toe, Backgammon,
Mancala, Chess, etc
GAME COMPONENTS
• Initial State
• Successor Function
• Terminal Test
• Utility Function
GAME
Game tree
Minimax GameSearch
Minimax Game
Search Two Players take
turns: Max and
Min
Minimax GameSearch
Two Players take
turns: Max and
Min
Max : Maximizes
Score. Min :
Minimizes Score.
MAX
Minimax GameSearch
Two Players take
turns: Max and
Min
MAX
MIN
Minimax GameSearch
Two Players take
turns: Max and
Min
Max : Maximizes
Score. Min :
Minimizes Score.
MAX
MIN
Minimax GameSearch
Two Players take
turns: Max and
Min
Max : Maximizes
Score. Min :
Minimizes Score.
Special Case.
Max is an
expert. Min is
a beginner.
MAX
MIN
Minimax Game
Search A
Minimax GameSearch
Which node to
follow?
No heuristic
values.
A
B C
Minimax GameSearch
Which node to
follow?
No heuristic
values.
A
B C
Minimax GameSearch
A
B C
Which node to follow?
No heuristic values.
Hot to find heuristic
values for other
nodes?
Minimax GameSearch
A
B C
Which node to follow?
No heuristic values.
Hot to find heuristic
values for other
nodes?
Use children
heuristics to
calculate parent
heuristic.
Minimax GameSearch
A
B C
Which node to follow?
No heuristic values.
Hot to find heuristic
values for other
nodes?
Use children
heuristics to
calculate parent
heuristic.
Minimax Game
Search Steps
Minimax GameSearch
Which node to
follow?
No heuristic
values.
A
B C
Hot to find heuristic
values for other
nodes?
Use children
heuristics to
calculate parent
heuristic.
Minimax Game Search Steps
Calculate Heuristics
Minimax GameSearch
Which node to
follow?
No heuristic
values.
A
B C
Hot to find heuristic
values for other
nodes?
Use children
heuristics to
calculate parent
heuristic.
Phase 1 :Heuristic ValueCalculation
Depth-FirstSearch
A
Phase 1 :Heuristic ValueCalculation
A
B
Phase 1 :Heuristic ValueCalculation
A
B C
Phase 1 :Heuristic ValueCalculation
A
B C
B C
Phase 1 :Heuristic ValueCalculation
A
B
B
C
Phase 1 :Heuristic ValueCalculation
A
B
B
C
D E
B C
Phase 1 :Heuristic ValueCalculation
A
B
B
C
D E
B C
D E
Phase 1 :Heuristic ValueCalculation
A
B
B
D
C
D E
B C
D E
Phase 1 :Heuristic ValueCalculation
A
B
B
D
H I
C
D E
J
B C
D E
Phase 1 :Heuristic ValueCalculation
A
B
B
D
H I
C
D E
J
B C
D E
H I
J
Phase 1 :Heuristic ValueCalculation
A
B
B
D
H I
C
D E
J
B C
D E
H I J
Phase 1 :Heuristic ValueCalculation
A
B
B
D
H I
C
D E
J
3 -2 5
B C
D E
H I J
Phase 1 :Heuristic ValueCalculation
A
B
B
D
H I
C
D E
J
3 -2 5
B C
D E
H I J
Max
Phase 1 :Heuristic ValueCalculation
A
B
B
D
H I
C
D E
J
3 -2 5
B C
D E
H I J
Max
5
Phase 1 :Heuristic ValueCalculation
A
B
B
D
H I
C
D E
J
3 -2 5
B C
D E
H I J
Ma
x
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
D
H I
C
D E
J
3 -2 5
B C
D E
H I J
Ma
x
5
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
D
H I
C
D E
J
3 -2 5
B C
D E
H I J
Ma
x
5
5
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
C
D E
B C
D E
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
C
D E
B C
D E
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
B C
D E
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
B C
D E
K L M
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
7 0 3
B C
D E
K L M
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
7 0 3
B C
D E
K L M
Max
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
7 0 3
B C
D E
K L M
Max
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
7 0 3
B C
D E
K L M
Ma
x
7
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
7 0 3
B C
D E
K L M
Ma
x
7
7
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
7 0 3
B C
D E
K L M
Ma
x
7
7
7
Min
5
7
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
7 0 3
B C
D E
K L M
Ma
x
7
7
7
Mi
n
5
5
5
7
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
7 0 3
B C
D E
K L M
Ma
x
7
7
7
Mi
n
5
5
5
5
7
5
Phase 1 :Heuristic ValueCalculation
A
B
B
E
K L
C
D E
M
7 0 3
B C
D E
K L M
Ma
x
7
7
7
Mi
n
5
5
5
5
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B C
B C
5
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
C
B C
5
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
C
F G
B C
5
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
C
F G
B C
5
F G
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
F
C
F G
B C
5
F G
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
F
N O
C
F G
P
B C
5
F G
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
F
N O
C
F G
P
B C
N O P
5
F G
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
F
N O
C
F G
P
0 -5 4
B C
N O P
5
F G
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
F
N O
C
F G
P
0 -5 4
B C
N O P
Max
5
F G
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
F
N O
C
F G
P
0 -5 4
B C
N O P
Max
4
5
F G
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
F
N O
C
F G
P
0 -5 4
B C
N O P
Ma
x
4
5
4
F G
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
F
N O
C
F G
P
0 -5 4
B C
N O P
Ma
x
4
5
4
F G
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
F
N O
C
F G
P
0 -5 4
B C
N O P
Ma
x
4
5
4
F G
4
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
C
F G
B C
5
F G
4
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
G
C
F G
B C
5
F G
4
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
B C
5
F G
4
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
B C
Q R S
5
F G
4
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
5
F G
4
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Max
5
F G
4
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Max
8
5
F G
4
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Ma
x
8
5
8
F G
4
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Ma
x
8
5
8
F G
4 8
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Ma
x
8
5
8
F G
4 8
Min
8
4
7
5
5
Phase 1 :Heuristic ValueCalculation
Depth-First
Search A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Ma
x
8
5
8
F G
4 8
Mi
n
4
4
8
4
7
5
5
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Ma
x
8
5
8
F G
4 8
Mi
n
4
4
4
8
4
7
5
5
4
Max
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Ma
x
8
5
8
F G
4 8
Mi
n
4
4
4
8
4
7
5
5
4
Max
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Ma
x
8
5
8
F G
4 8
Mi
n
4
4
4
5
8
4
4
7
5
5
Ma
x
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Ma
x
8
5
8
F G
4 8
Mi
n
4
4
4
5
5
8
4
4
7
5
5
Ma
x
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
-6 8 2
B C
Q R S
Ma
x
8
5
8
F G
4 8
Mi
n
4
4
4
5
5
8
4
5
4
7
5
5
Ma
x
Phase 1 :Heuristic ValueCalculation
A
B
C
G
Q R
C
F G
S
8
B C
Q R S
Ma
x
5
8
F G
4 8
Mi
n
4
4
4
5
5
8
4
5
4
7
5
5
-6 8 2
If both players play optimally then Max will win by a score 5.
Game TreeAfterHeuristic ValueCalculation
8
4
5
4
7
5
5
Phase 2 :GameSearch
8
4
5
4
7
5
5
Phase 2 :GameSearch
8
4
5
4
7
5
5
A
Phase 2 :GameSearch
8
4
5
4
7
5
5
B
Max
A
Phase 2 :GameSearch
8
4
5
4
7
5
5
B
D
Max
A
Min
Phase 2 :GameSearch
8
4
5
4
7
5
5
B
D
J
Max
Min
Max
A
Minimax Game Search
Drawback
• Expandsall the
tree
while not all
expanded nodes are
useful.
Minimax Game Search
Drawback
• Expandsall the
tree
while not all
expanded nodes are
useful.
• In this example, just
few nodes of the
whole tree was
useful in reaching
the goal.
Alpha-Beta
Pruning
Alpha-BetaPruning= Minimax
Except
• This game search strategy is a modification to Minimax game
search that avoids exploring nodes that are not useful in the
search.
• It gives the same results as Minimax but avoids exploring
some nodes.
• In the previous example, the path explored using Minimax was
A-B-D- J.
• Also the Alpha-Beta Pruning path will be A-B-D-J but
without exploring all nodes as in Minimax.
Alpha-BetaGameSearch
Alpha-BetaGameSearch
Alpha-BetaGameSearch
Alpha-BetaGameSearch
Alpha-BetaGameSearch
Alpha-BetaGameSearch
5
Alpha-BetaGameSearch
5
5
Alpha-BetaGameSearch
5
5
Alpha-BetaGameSearch
5
5
Alpha-BetaGameSearch
5
5
Alpha-BetaGameSearch
7
5
5
Alpha-BetaGameSearch
7
5
5
Min(5, max(7, x,
y))
=5
Alpha-BetaGameSearch
7
5
5
Alpha-BetaGameSearch
7
5
5
Alpha-BetaGameSearch
7
5
5
Alpha-BetaGameSearch
7
5
5
5
Alpha-BetaGameSearch
7
5
5
5
Alpha-BetaGameSearch
7
5
5
5
Alpha-BetaGameSearch
7
5
5
5
Alpha-BetaGameSearch
7
5
5
5
Alpha-BetaGameSearch
7
5
5
5
4
Alpha-BetaGameSearch
7
5
5
5
4
4
Max(5, min(4, x, y,
z))
=5
Alpha-BetaGameSearch
7
5
5
5
4
4
Alpha-BetaGameSearch
7
5
5
5
4
4
Alpha-BetaGameSearch
7
5
5
5
4
4
Same results as
Minimax with fewer
nodes explored.
5 Unexplored
Branches.

Artificial Intelligence Alpha Beta pruning.pptx