SlideShare a Scribd company logo
CSE 412: Artificial IntelligenceCSE 412: Artificial Intelligence
Spring 2019Spring 2019
Topic – 5: Game PlayingTopic – 5: Game Playing
Tajim Md. Niamat Ullah Akhund
Lecturer
Department of Computer Science and Engineering
Daffodil International University
Email: tajim.cse@diu.edu.bd
1
Case Studies: Playing Grandmaster ChessCase Studies: Playing Grandmaster Chess
Game Playing as SearchGame Playing as Search
Optimal Decisions in GamesOptimal Decisions in Games
 Greedy search algorithmGreedy search algorithm
 The minimax algorithmThe minimax algorithm
Alpha-Beta PruningAlpha-Beta Pruning
Topic ContentsTopic Contents
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund 2
• The real success of AI in game-playing was achieved much
later after many years’ effort.
• It has been shown that this search based approach works
extremely well.
• In 1996 IBM Deep Blue beat Gary Kasparov for the first time.
and in 1997 an upgraded version won an entire match against
the same opponent.
Case Studies: PlayingCase Studies: Playing
Grandmaster ChessGrandmaster Chess
33Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
44
Case Studies: PlayingCase Studies: Playing
Grandmaster Chess…Grandmaster Chess…
Kasparov vs. Deep Blue, May 1997
• 6 game full-regulation match sponsored by ACM
• Kasparov lost the match 1 wins to 2 wins and 3 tie
• This was a historic achievement for computer chess
being the first time a computer became
the best chess player on the planet.
• Note that Deep Blue plays by “brute force” (i.e. raw
power from computer speed and memory). It uses
relatively little that is similar to human intuition and
cleverness.
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
5
Game Playing and AIGame Playing and AI
Why would game playing be a good problem for AI
research?
– game playing is non-trivial
• players need “human-like” intelligence
• games can be very complex (e.g. chess, go)
• requires decision making within limited time
– game playing can be usefully viewed as a search problem in
a space defined by a fixed set of rules
• Nodes are either white or black corresponding to reflect the
adversaries’ turns.
• The tree of possible moves can be searched for favourable positions.
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
6
Game Playing and AI…Game Playing and AI…
Why would game playing be a good problem for AI
research?
– games often are:
• well-defined and repeatable
• easy to represent
• fully observable and limited environments
– can directly compare humans and computers
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
7
Game Playing as SearchGame Playing as Search
• Consider two-player, turn-taking, board
games
– e.g., tic-tac-toe, checkers, chess
• Representing these as search problem:
– states: board configurations
– edges: legal moves
– initial state:start board configuration
– goal state: winning/terminal board configuration
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
8
Game Playing as Search:Game Playing as Search:
Game TreeGame Tree
X X X
X
…
OX OX
O
X
O
X
…
How can this be handled?
What's the new aspect
to the search problem?
There’s an opponent
that we cannot control!
X
O
X
X O
X
X O
X
O
X X
…
OX
X
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
9
Game Playing as Search:Game Playing as Search:
ComplexityComplexity
• Assume the opponent’s moves can be
predicted given the computer's moves.
• How complex would search be in this case?
– worst case: O(bd
) ; b is branching factor, d is depth
– Tic-Tac-Toe: ~5 legal moves, 9 moves max game
• 59
= 1,953,125 states
– Chess: ~35 legal moves, ~100 moves per game
• 35100
~10154
states, but only ~1040
legal states
 Common games produce enormous search trees.
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
10
Greedy Search Game PlayingGreedy Search Game Playing
 A utility function maps each terminal state of the
board to a numeric value corresponding to the
value of that state to the computer.
– positive for winning, > + means better for computer
– negative for losing, > - means better for opponent
– zero for a draw
– typical values (lost to win):
• -infinity to +infinity
• -1.0 to +1.0
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
11Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
12
EDB C E
3
D
2
B
-5
C
9
• Expand each branch to the terminal states
• Evaluate the utility of each terminal state
• Choose the move that results in the board
configuration with the maximum value
M N OK LF G H I J
computer's
possible moves
opponent's
possible moves
board evaluation from computer's perspective
A
terminal states
A
9
Greedy Search Game PlayingGreedy Search Game Playing
M
1
N
3
O
2
K
0
L
2
F
-7
G
-5
H
3
I
9
J
-6
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
13
Assuming a reasonable search space,
what's the problem with greedy search?
It ignores what the opponent might do!
e.g. Computer chooses C. Opponent
chooses J and defeats computer.
M
1
N
3
O
2
K
0
L
2
F
-7
G
-5
H
3
I
9
J
-6
E
3
D
2
B
-5
C
9
computer's
possible moves
opponent's
possible moves
board evaluation from computer's perspective
A
9
terminal states
Greedy Search Game PlayingGreedy Search Game Playing
14
Minimax: IdeaMinimax: Idea
• Assuming the worst (i.e. opponent plays
optimally):
given there are two plays till the terminal states
– If high utility numbers favor the computer
Computer should choose which moves?
maximizing moves
– If low utility numbers favor the opponent
Smart opponent chooses which moves?
minimizing moves
15
EDB C
A
• The computer assumes after it moves the
opponent will choose the minimizing move.
E
1
D
0
B
-7
C
-6
A
1
M
1
N
3
O
2
K
0
L
2
F
-7
G
-5
H
3
I
9
J
-6
computer's
possible moves
opponent's
possible moves
board evaluation from computer's perspective terminal states
Minimax: IdeaMinimax: Idea
• It chooses its best move considering
both its move and opponent’s best move.
16
• Explore the game tree to the terminal states
• Evaluate the utility of the terminal states
• Computer chooses the move to put the
board
in the best configuration for it assuming
the opponent makes best moves on her
turns:
– start at the leaves
– assign value to the parent node as follows
• use minimum of children when opponent’s moves
• use maximum of children when computer's moves
Minimax: Passing Values upMinimax: Passing Values up
Game TreeGame Tree
17
ED
0B C
R
0
N
4 O P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MF G
-5
H
3
I
8 J L
2
W
-3
X
-5
A
Deeper Game TreesDeeper Game Trees
• Minimax can be generalized for > 2 moves
• Values backed up in minimax way
terminal states
O
-5
K
5
M
-7
F
4
J
9
E
-7
B
-5
C
3
A
3
opponent
min
computer
max
opponent
min
computer max
18
Minimax: Direct AlgorithmMinimax: Direct Algorithm
For each move by the computer:
1. Perform depth-first search to a terminal state
2. Evaluate each terminal state
3. Propagate upwards the minimax values
if opponent's move minimum value of children backed up
if computer's move maximum value of children backed up
4. choose move with the maximum of minimax values of
children
Note:
• minimax values gradually propagate upwards as DFS
proceeds: i.e., minimax values propagate up
in “left-to-right” fashion
• minimax values for sub-tree backed up “as we go”,
so only O(bd) nodes need to be kept in memory at any
time
19
Minimax: Algorithm ComplexityMinimax: Algorithm Complexity
Assume all terminal states are at depth d
Space complexity?
depth-first search, so O(bd)
Time complexity?
given branching factor b, so O(bd
)
 Time complexity is a major problem!
Computer typically only has a
finite amount of time to make a move.
20
Minimax: Algorithm ComplexityMinimax: Algorithm Complexity
• Direct minimax algorithm is impractical in practice
– instead do depth-limited search to ply (depth) m
What’s the problem for stopping at any ply?
– evaluation defined only for terminal states
– we need to know the value of non-terminal states
 Static board evaluator (SBE) function uses
heuristics to estimate the value of non-terminal
states.
21
Minimax:Minimax:
Static Board Evaluator (SBE)Static Board Evaluator (SBE)
 A static board evaluation function estimates how
good a board configuration is for the computer.
– it reflects the computer’s chances of winning from that
state
– it must be easy to calculate from the board configuration
• For Example, Chess:
SBE = α * materialBalance + β * centerControl + γ * …
material balance = Value of white pieces - Value of black pieces
(pawn = 1, rook = 5, queen = 9, etc).
22
int minimax (Node s, int depth, int limit) {
if (isTerminal(s) || depth == limit) //base case
return(staticEvaluation(s));
else {
Vector v = new Vector();
//do minimax on successors of s and save their values
while (s.hasMoreSuccessors())
v.addElement(minimax(s.getNextSuccessor(),
depth+1, limit));
if (isComputersTurn(s))
return maxOf(v); //computer's move returns max of
kids
else
return minOf(v); //opponent's move returns min of
kids
}
}
Minimax: Algorithm with SBEMinimax: Algorithm with SBE
23
• The same as direct minimax, except
– only goes to depth m
– estimates non-terminal states using SBE
function
• How would this algorithm perform at chess?
– if could look ahead ~4 pairs of moves (i.e. 8 ply)
would be consistently beaten by average players
– if could look ahead ~8 pairs as done in typical
pc, is as good as human master
Minimax: Algorithm with SBEMinimax: Algorithm with SBE
24
• Can't minimax search to the end of the
game.
– if could, then choosing move is easy
• SBE isn't perfect at estimating.
– if it was, just choose best move without
searching
• Since neither is feasible for interesting
games, combine minimax and SBE
concepts:
– minimax to depth m
– use SBE to estimate board configuration
RecapRecap
25
Alpha-Beta Pruning IdeaAlpha-Beta Pruning Idea
• Some of the branches of the game tree won't be
taken if playing against a smart opponent.
• Use pruning to ignore those branches.
• While doing DFS of game tree, keep track of:
– alpha at maximizing levels (computer’s move)
• highest SBE value seen so far (initialize to -infinity)
• is lower bound on state's evaluation
– beta at minimizing levels (opponent’s move)
• lowest SBE value seen so far (initialize to +infinity)
• is higher bound on state's evaluation
26
Alpha-Beta Pruning IdeaAlpha-Beta Pruning Idea
• Beta cutoff pruning occurs when maximizing
if child’s alpha ≥ parent's beta
Why stop expanding children?
opponent won't allow computer to take this move
• Alpha cutoff pruning occurs when minimizing
if parent's alpha ≥ child’s beta
Why stop expanding children?
computer has a better move than this
27
AAA
α=-
O
W
-3
B
N
4
F G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
Alpha-Beta Search ExampleAlpha-Beta Search Example
minimax(A,0,4)
max
Call
Stack
A
alpha initialized to -infinity
Expand A? Yes since there are successors, no cutoff test for root
28
BBB
β=+
O
W
-3
N
4
F G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
B
min
Expand B? Yes since A’s alpha >= B’s beta is false, no alpha cutoff
minimax(B,1,4) beta initialized to +infinity
29
FFF
α=-
O
W
-3
B
β=+
N
4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
B
min
max
F
Expand F? Yes since F’s alpha >= B’s beta is false, no beta cutoff
minimax(F,2,4) alpha initialized to -infinity
30
O
W
-3
B
β=+
N
4
F
α=-
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
N
4
B
min
max
F
green: terminal state
N
minimax(N,3,4) evaluate and return SBE value
31
F
α=-
F
α=4
O
W
-3
B
β=+
N
4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
B
min
max
F
Keep expanding F? Yes since F’s alpha >= B’s beta is false, no beta cutoff
alpha = 4, since 4 >= -infinity (maximizing)back to
minimax(F,2,4)
32
OOO
β=+
W
-3
B
β=+
N
4
F
α=4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
B
min
max
F
O
min
Expand O? Yes since F’s alpha >= O’s beta is false, no alpha cutoff
minimax(O,3,4) beta initialized to +infinity
33
blue: non-terminal state (depth limit)
O
β=+
W
-3
B
β=+
N
4
F
α=4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
B
min
max
F
O
W
-3
min
W
minimax(W,4,4) evaluate and return SBE value
34
O
β=+
O
β=-3
W
-3
B
β=+
N
4
F
α=4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
B
min
max
F
O
min
Keep expanding O?
beta = -3, since -3 <= +infinity (minimizing)back to
minimax(O,3,4)
No since F’s alpha >= O’s beta is true: alpha cutoff
35
red: pruned state
O
β=-3
W
-3
B
β=+
N
4
F
α=4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
Why?
Smart opponent will choose W or worse, thus O's upper bound is –3.
Computer already has better move at N.
max
Call
Stack
A
B
min
max
F
O
min
X
-5
36
O
β=-3
W
-3
B
β=+
N
4
F
α=4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
B
min
max
F
min
X
-5
back to
minimax(F,2,4)
alpha doesn’t change, since -3 < 4 (maximizing)
Keep expanding F? No since no more successors for F
37
B
β=+
B
β=4
back to
minimax(B,1,4)
O
β=-3
W
-3
N
4
F
α=4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
B
min
max
min
X
-5
beta = 4, since 4 <= +infinity (minimizing)
Keep expanding B? Yes since A’s alpha >= B’s beta is false, no alpha cutoff
38
O
β=-3
W
-3
B
β=4
N
4
F
α=4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
B
min
max
min
X
-5
G
G
-5
minimax(G,2,4)
green: terminal state
evaluate and return SBE value
39
B
β=4
B
β=-5
O
β=-3
W
-3
N
4
F
α=4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=-
Alpha-Beta Search Example
max
Call
Stack
A
B
min
max
min
X
-5
back to
minimax(B,1,4)
beta = -5, since -5 <= 4 (minimizing)
Keep expanding B? No since no more successors for B
40
A
α=
A
α=-5
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0C
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
Alpha-Beta Search Example
max
Call
Stack
A
min
max
min
X
-5
back to
minimax(A,0,4)
alpha = -5, since -5 >= -infinity (maximizing)
Keep expanding A? Yes since there are more successors, no cutoff test
41
CCC
β=+
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=
Alpha-Beta Search Example
max
Call
Stack
A
min
max
min
X
-5
A
α=-5
C
minimax(C,1,4) beta initialized to +infinity
Expand C? Yes since A’s alpha >= C’s beta is false, no alpha cutoff
42
green: terminal state
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=+
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=
Alpha-Beta Search Example
minimax(H,2,4)
max
Call
Stack
A
min
max
min
X
-5
A
α=-5
C
H
3
H
evaluate and return SBE value
43
C
β=+
C
β=3
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=
Alpha-Beta Search Example
max
Call
Stack
A
min
max
min
X
-5
A
α=-5
C
back to
minimax(C,1,4)
beta = 3, since 3 <= +infinity (minimizing)
Keep expanding C? Yes since A’s alpha >= C’s beta is false, no alpha cutoff
44
green: terminal state
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=
Alpha-Beta Search Example
minimax(I,2,4)
max
Call
Stack
A
min
max
min
X
-5
A
α=-5
C
I
8
I
evaluate and return SBE value
45
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8 J L
2
A
α=
Alpha-Beta Search Example
max
Call
Stack
A
min
max
min
X
-5
A
α=-5
C
back to
minimax(C,1,4)
beta doesn’t change, since 8 > 3 (minimizing)
Keep expanding C? Yes since A’s alpha >= C’s beta is false, no alpha cutoff
46
JJJ
α=-
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8
L
2
A
α=
Alpha-Beta Search Example
minimax(J,2,4)
max
Call
Stack
A
min
max
min
X
-5
A
α=-5
C
J
alpha initialized to -infinity
Expand J? Yes since J’s alpha >= C’s beta is false, no beta cutoff
47
green: terminal state
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8
J
α=-
L
2
A
α=
Alpha-Beta Search Example
minimax(P,3,4)
max
Call
Stack
A
min
max
min
X
-5
A
α=-5
C
J
P
P
9
evaluate and return SBE value
48
J
α=-
J
α=9
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8
L
2
A
α=
Alpha-Beta Search Example
max
Call
Stack
A
min
max
min
X
-5
A
α=-5
C
J
back to
minimax(J,2,4)
alpha = 9, since 9 >= -infinity (maximizing)
Keep expanding J?
Q
-6
R
0
red: pruned states
No since J’s alpha >= C’s beta is true: beta cutoff
49
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8
J
α=9
L
2
A
α=
Alpha-Beta Search Example
max
Call
Stack
A
min
max
min
X
-5
A
α=-5
C
J
Why?
Computer will choose P or better, thus J's lower bound is 9.
Smart opponent won’t let computer take move to J
(since opponent already has better move at H).
red: pruned states
50
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8
J
α=9
L
2
A
α=
Alpha-Beta Search Example
max
Call
Stack
A
min
max
min
X
-5
A
α=-5
C
back to
minimax(C,1,4)
beta doesn’t change, since 9 > 3 (minimizing)
Keep expanding C? No since no more successors for C
51
A
α=-5
A
α=3
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8
J
α=9
L
2
Alpha-Beta Search Example
max
Call
Stack
A
min
max
min
X
-5
back to
minimax(A,0,4)
alpha = 3, since 3 >= -5 (maximizing)
Keep expanding A? Yes since there are more successors, no cutoff test
52
green: terminal state
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8
J
α=9
L
2
A
α=
Alpha-Beta Search Example
minimax(D,1,4)
max
Call
Stack
A
min
max
min
X
-5
A
α=3
D
D
0
evaluate and return SBE value
53
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8
J
α=9
L
2
A
α=
Alpha-Beta Search Example
max
Call
Stack
A
min
max
min
X
-5
A
α=3
back to
minimax(A,0,4)
alpha doesn’t change, since 0 < 3 (maximizing)
Keep expanding A? Yes since there are more successors, no cutoff test
54
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
ED
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K MH
3
I
8
J
α=9
L
2
A
α=
Alpha-Beta Search Example
How does the algorithm finish searching the tree?
max
Call
Stack
A
min
max
min
X
-5
A
α=3
55
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
E
β=2
D
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K
α=5 MH
3
I
8
J
α=9
L
2
A
α=
Alpha-Beta Search Example
Stop Expanding E since A's alpha >= E's beta is true: alpha cutoff
max
Call
Stack
A
min
max
min
X
-5
A
α=3
Why?
Smart opponent will choose L or worse, thus E's upper bound is 2.
Computer already has better move at C.
56
green: terminal states, red: pruned states
blue: non-terminal state (depth limit)
O
β=-3
W
-3
B
β=-5
N
4
F
α=4
G
-5
X
-5
E
β=2
D
0
C
β=3
R
0
P
9
Q
-6
S
3
T
5
U
-7
V
-9
K
α=5 MH
3
I
8
J
α=9
L
2
A
α=
Alpha-Beta Search Example
Result: Computer chooses move to C.
max
Call
Stack
A
min
max
min
X
-5
A
α=3
57
Alpha-Beta Effectiveness
 Effectiveness depends on the order
in which successors are examined.
What ordering gives more effective pruning?
More effective if best successors are examined first.
• Best Case: each player’s best move is left-most
• Worst Case: ordered so that no pruning occurs
– no improvement over exhaustive search
• In practice, performance is closer
to best case rather than worst case.
58
Alpha-Beta Effectiveness
If opponent’s best move where first
more pruning would result:
E
β=2
S
3
T
5
U
-7
V
-9
K
α=5 ML
2
A
α=3
E
β=2
S
3
T
5
U
-7
V
-9
K ML
2
A
α=3
59
Alpha-Beta Effectiveness
• In practice often get O(b(d/2)
) rather than
O(bd
)
– same as having a branching factor of sqrt(b)
recall (sqrt(b))d
= b(d/2)
• For Example: chess
– goes from b ~ 35 to b ~ 6
– permits much deeper search for the same
time
60
61
Other Issues: The Horizon
Effect
• Sometimes disaster lurks just
beyond search depth
– e.g. computer captures queen,
but a few moves later the opponent checkmates
• The computer has a limited horizon, it cannot
see that this significant event could happen
How do you avoid catastrophic losses
due to “short-sightedness”?
– quiescence search
– secondary search
62
Other Issues: The Horizon
Effect
• Quiescence Search
– when SBE value frequently changing,
look deeper than limit
– looking for point when game quiets down
• Secondary Search
1. find best move looking to depth d
2. look k steps beyond to verify that it still looks
good
3. if it doesn't, repeat step 2 for next best move
THANKS…
63
COURTESY:
Md. Tarek Habib
Assistant Professor
Daffodil International University
64
********** ********** If You Need Me ********** **********
Mail: tajim.cse@diu.edu.bd
Website: https://www.tajimiitju.blogspot.com
ORCID: https://orcid.org/0000-0002-2834-1507
LinkedIn: https://www.linkedin.com/in/tajimiitju
ResearchGate: https://www.researchgate.net/profile/Tajim_Md_Niamat_Ullah_Akhund
YouTube: https://www.youtube.com/tajimiitju?sub_confirmation=1
SlideShare: https://www.slideshare.net/TajimMdNiamatUllahAk
Facebook: https://www.facebook.com/tajim.mohammad
GitHub: https://github.com/tajimiitju
Google+: https://plus.google.com/+tajimiitju
Gmail: tajim.mohammad.3@gmail.com
Twitter: https://twitter.com/Tajim53
Thank you
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund 65

More Related Content

PDF
AI3391 ARTIFICIAL INTELLIGENCE UNIT II notes.pdf
PPTX
Game playing in AI
PDF
Recurrent neural networks rnn
PDF
Heuristic search-in-artificial-intelligence
PPTX
unit-4-dynamic programming
PDF
AI3391 Artificial Intelligence UNIT III Notes_merged.pdf
PPT
AI Lecture 2 (intelligent agents)
PDF
AI3391 ARTIFICIAL INTELLIGENCE Unit I notes.pdf
AI3391 ARTIFICIAL INTELLIGENCE UNIT II notes.pdf
Game playing in AI
Recurrent neural networks rnn
Heuristic search-in-artificial-intelligence
unit-4-dynamic programming
AI3391 Artificial Intelligence UNIT III Notes_merged.pdf
AI Lecture 2 (intelligent agents)
AI3391 ARTIFICIAL INTELLIGENCE Unit I notes.pdf

What's hot (20)

PPTX
First order logic
PDF
I. Hill climbing algorithm II. Steepest hill climbing algorithm
PDF
Informed search
PDF
An introduction to deep reinforcement learning
PPTX
AI: AI & Problem Solving
PPT
AI Lecture 3 (solving problems by searching)
PPTX
Adversarial search
PPTX
Artificial Intelligence Searching Techniques
PPTX
Informed and Uninformed search Strategies
PDF
Emily Stamm - Post-Quantum Cryptography
PDF
Block Ciphers and the Data Encryption Standard
PPTX
Adversarial search
PPTX
Alpha-beta pruning (Artificial Intelligence)
PPT
AI Lecture 1 (introduction)
PPTX
Local search algorithms
PPTX
Problem solving in Artificial Intelligence.pptx
PPT
Hill climbing
PDF
I. Alpha-Beta Pruning in ai
PPTX
AI_Session 11: searching with Non-Deterministic Actions and partial observati...
PDF
Artificial Intelligence in games
First order logic
I. Hill climbing algorithm II. Steepest hill climbing algorithm
Informed search
An introduction to deep reinforcement learning
AI: AI & Problem Solving
AI Lecture 3 (solving problems by searching)
Adversarial search
Artificial Intelligence Searching Techniques
Informed and Uninformed search Strategies
Emily Stamm - Post-Quantum Cryptography
Block Ciphers and the Data Encryption Standard
Adversarial search
Alpha-beta pruning (Artificial Intelligence)
AI Lecture 1 (introduction)
Local search algorithms
Problem solving in Artificial Intelligence.pptx
Hill climbing
I. Alpha-Beta Pruning in ai
AI_Session 11: searching with Non-Deterministic Actions and partial observati...
Artificial Intelligence in games
Ad

Similar to AI Lecture 5 (game playing) (20)

PPT
Topic - 6 (Game Playing).ppt
PPTX
PPTX
CptS 440/ 540 AI.pptx
PPT
Artificial intelligence games
PPT
artificial intelligence and Game development
PPT
Adversarial Search and Game-Playing .ppt
PPT
AI.ppt
PPT
PPT
ch_5 Game playing Min max and Alpha Beta pruning.ppt
PPT
GamePlaying numbert 23256666666666666662
PPTX
Artificial intelligence dic_SLIDE_3.pptx
PDF
Games.4
PPTX
AI subject - Game Theory and cps ppt pptx
PDF
Adversarial search
PPT
cs-171-07-Games and Adversarila Search.ppt
PPTX
Capgemini 1
PPT
It is an artificial document, please. regarding Ai topics
PPT
Game playing.ppt
PPTX
AI_unit3.pptx
Topic - 6 (Game Playing).ppt
CptS 440/ 540 AI.pptx
Artificial intelligence games
artificial intelligence and Game development
Adversarial Search and Game-Playing .ppt
AI.ppt
ch_5 Game playing Min max and Alpha Beta pruning.ppt
GamePlaying numbert 23256666666666666662
Artificial intelligence dic_SLIDE_3.pptx
Games.4
AI subject - Game Theory and cps ppt pptx
Adversarial search
cs-171-07-Games and Adversarila Search.ppt
Capgemini 1
It is an artificial document, please. regarding Ai topics
Game playing.ppt
AI_unit3.pptx
Ad

More from Tajim Md. Niamat Ullah Akhund (20)

PPT
AI Lecture 7 (uncertainty)
PPT
AI Lecture 6 (logical agents)
PPT
AI Lecture 4 (informed search and exploration)
PDF
Course outline (cse 412 - artificial intelligence)
PPTX
Artificial intelligence LAB 1 overview &amp; intelligent systems
PDF
Matlab lecture 9 – simpson 1,3 and trapezoidal method@taj
PDF
Matlab lecture 8 – newton's forward and backword interpolation@taj copy
PDF
Matlab lecture 7 – regula falsi or false position method@taj
PDF
Matlab lecture 6 – newton raphson method@taj copy
PDF
Matlab lecture 5 bisection method@taj
PDF
Matlab lecture 4 loops@taj
PDF
Matlab lecture 3 – commands, the m files, data types, bitwise op, set@taj
PDF
Matlab lecture 2 matlab basic syntax &amp; variables @taj
PDF
Matlab lecture 1 - installation of matlab, introduction and course outline@taj
PDF
Circuit lab 10 verification of norton's theorem@taj
PDF
Circuit lab 9 verification of maximum power transfer theorem@taj
PDF
Circuit lab 8 verification of thevenin's theorem@taj
PDF
Circuit lab 7 verification of superposition theorem@taj
PDF
Circuit lab 6 kirchoff’s current law (kcl)@taj
PDF
Circuit lab 5 kirchoff’s voltage law (kvl)@taj
AI Lecture 7 (uncertainty)
AI Lecture 6 (logical agents)
AI Lecture 4 (informed search and exploration)
Course outline (cse 412 - artificial intelligence)
Artificial intelligence LAB 1 overview &amp; intelligent systems
Matlab lecture 9 – simpson 1,3 and trapezoidal method@taj
Matlab lecture 8 – newton's forward and backword interpolation@taj copy
Matlab lecture 7 – regula falsi or false position method@taj
Matlab lecture 6 – newton raphson method@taj copy
Matlab lecture 5 bisection method@taj
Matlab lecture 4 loops@taj
Matlab lecture 3 – commands, the m files, data types, bitwise op, set@taj
Matlab lecture 2 matlab basic syntax &amp; variables @taj
Matlab lecture 1 - installation of matlab, introduction and course outline@taj
Circuit lab 10 verification of norton's theorem@taj
Circuit lab 9 verification of maximum power transfer theorem@taj
Circuit lab 8 verification of thevenin's theorem@taj
Circuit lab 7 verification of superposition theorem@taj
Circuit lab 6 kirchoff’s current law (kcl)@taj
Circuit lab 5 kirchoff’s voltage law (kvl)@taj

Recently uploaded (20)

PPT
Project quality management in manufacturing
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
composite construction of structures.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Geodesy 1.pptx...............................................
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Project quality management in manufacturing
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
additive manufacturing of ss316l using mig welding
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
composite construction of structures.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Geodesy 1.pptx...............................................
Foundation to blockchain - A guide to Blockchain Tech
Lecture Notes Electrical Wiring System Components
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
OOP with Java - Java Introduction (Basics)
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Digital Logic Computer Design lecture notes
Automation-in-Manufacturing-Chapter-Introduction.pdf
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx

AI Lecture 5 (game playing)

  • 1. CSE 412: Artificial IntelligenceCSE 412: Artificial Intelligence Spring 2019Spring 2019 Topic – 5: Game PlayingTopic – 5: Game Playing Tajim Md. Niamat Ullah Akhund Lecturer Department of Computer Science and Engineering Daffodil International University Email: tajim.cse@diu.edu.bd 1
  • 2. Case Studies: Playing Grandmaster ChessCase Studies: Playing Grandmaster Chess Game Playing as SearchGame Playing as Search Optimal Decisions in GamesOptimal Decisions in Games  Greedy search algorithmGreedy search algorithm  The minimax algorithmThe minimax algorithm Alpha-Beta PruningAlpha-Beta Pruning Topic ContentsTopic Contents Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund 2
  • 3. • The real success of AI in game-playing was achieved much later after many years’ effort. • It has been shown that this search based approach works extremely well. • In 1996 IBM Deep Blue beat Gary Kasparov for the first time. and in 1997 an upgraded version won an entire match against the same opponent. Case Studies: PlayingCase Studies: Playing Grandmaster ChessGrandmaster Chess 33Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
  • 4. 44 Case Studies: PlayingCase Studies: Playing Grandmaster Chess…Grandmaster Chess… Kasparov vs. Deep Blue, May 1997 • 6 game full-regulation match sponsored by ACM • Kasparov lost the match 1 wins to 2 wins and 3 tie • This was a historic achievement for computer chess being the first time a computer became the best chess player on the planet. • Note that Deep Blue plays by “brute force” (i.e. raw power from computer speed and memory). It uses relatively little that is similar to human intuition and cleverness. Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
  • 5. 5 Game Playing and AIGame Playing and AI Why would game playing be a good problem for AI research? – game playing is non-trivial • players need “human-like” intelligence • games can be very complex (e.g. chess, go) • requires decision making within limited time – game playing can be usefully viewed as a search problem in a space defined by a fixed set of rules • Nodes are either white or black corresponding to reflect the adversaries’ turns. • The tree of possible moves can be searched for favourable positions. Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
  • 6. 6 Game Playing and AI…Game Playing and AI… Why would game playing be a good problem for AI research? – games often are: • well-defined and repeatable • easy to represent • fully observable and limited environments – can directly compare humans and computers Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
  • 7. 7 Game Playing as SearchGame Playing as Search • Consider two-player, turn-taking, board games – e.g., tic-tac-toe, checkers, chess • Representing these as search problem: – states: board configurations – edges: legal moves – initial state:start board configuration – goal state: winning/terminal board configuration Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
  • 8. 8 Game Playing as Search:Game Playing as Search: Game TreeGame Tree X X X X … OX OX O X O X … How can this be handled? What's the new aspect to the search problem? There’s an opponent that we cannot control! X O X X O X X O X O X X … OX X Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
  • 9. 9 Game Playing as Search:Game Playing as Search: ComplexityComplexity • Assume the opponent’s moves can be predicted given the computer's moves. • How complex would search be in this case? – worst case: O(bd ) ; b is branching factor, d is depth – Tic-Tac-Toe: ~5 legal moves, 9 moves max game • 59 = 1,953,125 states – Chess: ~35 legal moves, ~100 moves per game • 35100 ~10154 states, but only ~1040 legal states  Common games produce enormous search trees. Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
  • 10. 10 Greedy Search Game PlayingGreedy Search Game Playing  A utility function maps each terminal state of the board to a numeric value corresponding to the value of that state to the computer. – positive for winning, > + means better for computer – negative for losing, > - means better for opponent – zero for a draw – typical values (lost to win): • -infinity to +infinity • -1.0 to +1.0 Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
  • 11. 11Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
  • 12. 12 EDB C E 3 D 2 B -5 C 9 • Expand each branch to the terminal states • Evaluate the utility of each terminal state • Choose the move that results in the board configuration with the maximum value M N OK LF G H I J computer's possible moves opponent's possible moves board evaluation from computer's perspective A terminal states A 9 Greedy Search Game PlayingGreedy Search Game Playing M 1 N 3 O 2 K 0 L 2 F -7 G -5 H 3 I 9 J -6 Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
  • 13. 13 Assuming a reasonable search space, what's the problem with greedy search? It ignores what the opponent might do! e.g. Computer chooses C. Opponent chooses J and defeats computer. M 1 N 3 O 2 K 0 L 2 F -7 G -5 H 3 I 9 J -6 E 3 D 2 B -5 C 9 computer's possible moves opponent's possible moves board evaluation from computer's perspective A 9 terminal states Greedy Search Game PlayingGreedy Search Game Playing
  • 14. 14 Minimax: IdeaMinimax: Idea • Assuming the worst (i.e. opponent plays optimally): given there are two plays till the terminal states – If high utility numbers favor the computer Computer should choose which moves? maximizing moves – If low utility numbers favor the opponent Smart opponent chooses which moves? minimizing moves
  • 15. 15 EDB C A • The computer assumes after it moves the opponent will choose the minimizing move. E 1 D 0 B -7 C -6 A 1 M 1 N 3 O 2 K 0 L 2 F -7 G -5 H 3 I 9 J -6 computer's possible moves opponent's possible moves board evaluation from computer's perspective terminal states Minimax: IdeaMinimax: Idea • It chooses its best move considering both its move and opponent’s best move.
  • 16. 16 • Explore the game tree to the terminal states • Evaluate the utility of the terminal states • Computer chooses the move to put the board in the best configuration for it assuming the opponent makes best moves on her turns: – start at the leaves – assign value to the parent node as follows • use minimum of children when opponent’s moves • use maximum of children when computer's moves Minimax: Passing Values upMinimax: Passing Values up Game TreeGame Tree
  • 17. 17 ED 0B C R 0 N 4 O P 9 Q -6 S 3 T 5 U -7 V -9 K MF G -5 H 3 I 8 J L 2 W -3 X -5 A Deeper Game TreesDeeper Game Trees • Minimax can be generalized for > 2 moves • Values backed up in minimax way terminal states O -5 K 5 M -7 F 4 J 9 E -7 B -5 C 3 A 3 opponent min computer max opponent min computer max
  • 18. 18 Minimax: Direct AlgorithmMinimax: Direct Algorithm For each move by the computer: 1. Perform depth-first search to a terminal state 2. Evaluate each terminal state 3. Propagate upwards the minimax values if opponent's move minimum value of children backed up if computer's move maximum value of children backed up 4. choose move with the maximum of minimax values of children Note: • minimax values gradually propagate upwards as DFS proceeds: i.e., minimax values propagate up in “left-to-right” fashion • minimax values for sub-tree backed up “as we go”, so only O(bd) nodes need to be kept in memory at any time
  • 19. 19 Minimax: Algorithm ComplexityMinimax: Algorithm Complexity Assume all terminal states are at depth d Space complexity? depth-first search, so O(bd) Time complexity? given branching factor b, so O(bd )  Time complexity is a major problem! Computer typically only has a finite amount of time to make a move.
  • 20. 20 Minimax: Algorithm ComplexityMinimax: Algorithm Complexity • Direct minimax algorithm is impractical in practice – instead do depth-limited search to ply (depth) m What’s the problem for stopping at any ply? – evaluation defined only for terminal states – we need to know the value of non-terminal states  Static board evaluator (SBE) function uses heuristics to estimate the value of non-terminal states.
  • 21. 21 Minimax:Minimax: Static Board Evaluator (SBE)Static Board Evaluator (SBE)  A static board evaluation function estimates how good a board configuration is for the computer. – it reflects the computer’s chances of winning from that state – it must be easy to calculate from the board configuration • For Example, Chess: SBE = α * materialBalance + β * centerControl + γ * … material balance = Value of white pieces - Value of black pieces (pawn = 1, rook = 5, queen = 9, etc).
  • 22. 22 int minimax (Node s, int depth, int limit) { if (isTerminal(s) || depth == limit) //base case return(staticEvaluation(s)); else { Vector v = new Vector(); //do minimax on successors of s and save their values while (s.hasMoreSuccessors()) v.addElement(minimax(s.getNextSuccessor(), depth+1, limit)); if (isComputersTurn(s)) return maxOf(v); //computer's move returns max of kids else return minOf(v); //opponent's move returns min of kids } } Minimax: Algorithm with SBEMinimax: Algorithm with SBE
  • 23. 23 • The same as direct minimax, except – only goes to depth m – estimates non-terminal states using SBE function • How would this algorithm perform at chess? – if could look ahead ~4 pairs of moves (i.e. 8 ply) would be consistently beaten by average players – if could look ahead ~8 pairs as done in typical pc, is as good as human master Minimax: Algorithm with SBEMinimax: Algorithm with SBE
  • 24. 24 • Can't minimax search to the end of the game. – if could, then choosing move is easy • SBE isn't perfect at estimating. – if it was, just choose best move without searching • Since neither is feasible for interesting games, combine minimax and SBE concepts: – minimax to depth m – use SBE to estimate board configuration RecapRecap
  • 25. 25 Alpha-Beta Pruning IdeaAlpha-Beta Pruning Idea • Some of the branches of the game tree won't be taken if playing against a smart opponent. • Use pruning to ignore those branches. • While doing DFS of game tree, keep track of: – alpha at maximizing levels (computer’s move) • highest SBE value seen so far (initialize to -infinity) • is lower bound on state's evaluation – beta at minimizing levels (opponent’s move) • lowest SBE value seen so far (initialize to +infinity) • is higher bound on state's evaluation
  • 26. 26 Alpha-Beta Pruning IdeaAlpha-Beta Pruning Idea • Beta cutoff pruning occurs when maximizing if child’s alpha ≥ parent's beta Why stop expanding children? opponent won't allow computer to take this move • Alpha cutoff pruning occurs when minimizing if parent's alpha ≥ child’s beta Why stop expanding children? computer has a better move than this
  • 27. 27 AAA α=- O W -3 B N 4 F G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 Alpha-Beta Search ExampleAlpha-Beta Search Example minimax(A,0,4) max Call Stack A alpha initialized to -infinity Expand A? Yes since there are successors, no cutoff test for root
  • 28. 28 BBB β=+ O W -3 N 4 F G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A B min Expand B? Yes since A’s alpha >= B’s beta is false, no alpha cutoff minimax(B,1,4) beta initialized to +infinity
  • 29. 29 FFF α=- O W -3 B β=+ N 4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A B min max F Expand F? Yes since F’s alpha >= B’s beta is false, no beta cutoff minimax(F,2,4) alpha initialized to -infinity
  • 30. 30 O W -3 B β=+ N 4 F α=- G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A N 4 B min max F green: terminal state N minimax(N,3,4) evaluate and return SBE value
  • 31. 31 F α=- F α=4 O W -3 B β=+ N 4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A B min max F Keep expanding F? Yes since F’s alpha >= B’s beta is false, no beta cutoff alpha = 4, since 4 >= -infinity (maximizing)back to minimax(F,2,4)
  • 32. 32 OOO β=+ W -3 B β=+ N 4 F α=4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A B min max F O min Expand O? Yes since F’s alpha >= O’s beta is false, no alpha cutoff minimax(O,3,4) beta initialized to +infinity
  • 33. 33 blue: non-terminal state (depth limit) O β=+ W -3 B β=+ N 4 F α=4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A B min max F O W -3 min W minimax(W,4,4) evaluate and return SBE value
  • 34. 34 O β=+ O β=-3 W -3 B β=+ N 4 F α=4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A B min max F O min Keep expanding O? beta = -3, since -3 <= +infinity (minimizing)back to minimax(O,3,4) No since F’s alpha >= O’s beta is true: alpha cutoff
  • 35. 35 red: pruned state O β=-3 W -3 B β=+ N 4 F α=4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example Why? Smart opponent will choose W or worse, thus O's upper bound is –3. Computer already has better move at N. max Call Stack A B min max F O min X -5
  • 36. 36 O β=-3 W -3 B β=+ N 4 F α=4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A B min max F min X -5 back to minimax(F,2,4) alpha doesn’t change, since -3 < 4 (maximizing) Keep expanding F? No since no more successors for F
  • 37. 37 B β=+ B β=4 back to minimax(B,1,4) O β=-3 W -3 N 4 F α=4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A B min max min X -5 beta = 4, since 4 <= +infinity (minimizing) Keep expanding B? Yes since A’s alpha >= B’s beta is false, no alpha cutoff
  • 38. 38 O β=-3 W -3 B β=4 N 4 F α=4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A B min max min X -5 G G -5 minimax(G,2,4) green: terminal state evaluate and return SBE value
  • 39. 39 B β=4 B β=-5 O β=-3 W -3 N 4 F α=4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α=- Alpha-Beta Search Example max Call Stack A B min max min X -5 back to minimax(B,1,4) beta = -5, since -5 <= 4 (minimizing) Keep expanding B? No since no more successors for B
  • 40. 40 A α= A α=-5 O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0C R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 Alpha-Beta Search Example max Call Stack A min max min X -5 back to minimax(A,0,4) alpha = -5, since -5 >= -infinity (maximizing) Keep expanding A? Yes since there are more successors, no cutoff test
  • 41. 41 CCC β=+ O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α= Alpha-Beta Search Example max Call Stack A min max min X -5 A α=-5 C minimax(C,1,4) beta initialized to +infinity Expand C? Yes since A’s alpha >= C’s beta is false, no alpha cutoff
  • 42. 42 green: terminal state O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=+ R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α= Alpha-Beta Search Example minimax(H,2,4) max Call Stack A min max min X -5 A α=-5 C H 3 H evaluate and return SBE value
  • 43. 43 C β=+ C β=3 O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α= Alpha-Beta Search Example max Call Stack A min max min X -5 A α=-5 C back to minimax(C,1,4) beta = 3, since 3 <= +infinity (minimizing) Keep expanding C? Yes since A’s alpha >= C’s beta is false, no alpha cutoff
  • 44. 44 green: terminal state O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α= Alpha-Beta Search Example minimax(I,2,4) max Call Stack A min max min X -5 A α=-5 C I 8 I evaluate and return SBE value
  • 45. 45 O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J L 2 A α= Alpha-Beta Search Example max Call Stack A min max min X -5 A α=-5 C back to minimax(C,1,4) beta doesn’t change, since 8 > 3 (minimizing) Keep expanding C? Yes since A’s alpha >= C’s beta is false, no alpha cutoff
  • 46. 46 JJJ α=- O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 L 2 A α= Alpha-Beta Search Example minimax(J,2,4) max Call Stack A min max min X -5 A α=-5 C J alpha initialized to -infinity Expand J? Yes since J’s alpha >= C’s beta is false, no beta cutoff
  • 47. 47 green: terminal state O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J α=- L 2 A α= Alpha-Beta Search Example minimax(P,3,4) max Call Stack A min max min X -5 A α=-5 C J P P 9 evaluate and return SBE value
  • 48. 48 J α=- J α=9 O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 L 2 A α= Alpha-Beta Search Example max Call Stack A min max min X -5 A α=-5 C J back to minimax(J,2,4) alpha = 9, since 9 >= -infinity (maximizing) Keep expanding J? Q -6 R 0 red: pruned states No since J’s alpha >= C’s beta is true: beta cutoff
  • 49. 49 O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J α=9 L 2 A α= Alpha-Beta Search Example max Call Stack A min max min X -5 A α=-5 C J Why? Computer will choose P or better, thus J's lower bound is 9. Smart opponent won’t let computer take move to J (since opponent already has better move at H). red: pruned states
  • 50. 50 O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J α=9 L 2 A α= Alpha-Beta Search Example max Call Stack A min max min X -5 A α=-5 C back to minimax(C,1,4) beta doesn’t change, since 9 > 3 (minimizing) Keep expanding C? No since no more successors for C
  • 51. 51 A α=-5 A α=3 O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J α=9 L 2 Alpha-Beta Search Example max Call Stack A min max min X -5 back to minimax(A,0,4) alpha = 3, since 3 >= -5 (maximizing) Keep expanding A? Yes since there are more successors, no cutoff test
  • 52. 52 green: terminal state O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J α=9 L 2 A α= Alpha-Beta Search Example minimax(D,1,4) max Call Stack A min max min X -5 A α=3 D D 0 evaluate and return SBE value
  • 53. 53 O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J α=9 L 2 A α= Alpha-Beta Search Example max Call Stack A min max min X -5 A α=3 back to minimax(A,0,4) alpha doesn’t change, since 0 < 3 (maximizing) Keep expanding A? Yes since there are more successors, no cutoff test
  • 54. 54 O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 ED 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K MH 3 I 8 J α=9 L 2 A α= Alpha-Beta Search Example How does the algorithm finish searching the tree? max Call Stack A min max min X -5 A α=3
  • 55. 55 O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 E β=2 D 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K α=5 MH 3 I 8 J α=9 L 2 A α= Alpha-Beta Search Example Stop Expanding E since A's alpha >= E's beta is true: alpha cutoff max Call Stack A min max min X -5 A α=3 Why? Smart opponent will choose L or worse, thus E's upper bound is 2. Computer already has better move at C.
  • 56. 56 green: terminal states, red: pruned states blue: non-terminal state (depth limit) O β=-3 W -3 B β=-5 N 4 F α=4 G -5 X -5 E β=2 D 0 C β=3 R 0 P 9 Q -6 S 3 T 5 U -7 V -9 K α=5 MH 3 I 8 J α=9 L 2 A α= Alpha-Beta Search Example Result: Computer chooses move to C. max Call Stack A min max min X -5 A α=3
  • 57. 57 Alpha-Beta Effectiveness  Effectiveness depends on the order in which successors are examined. What ordering gives more effective pruning? More effective if best successors are examined first. • Best Case: each player’s best move is left-most • Worst Case: ordered so that no pruning occurs – no improvement over exhaustive search • In practice, performance is closer to best case rather than worst case.
  • 58. 58 Alpha-Beta Effectiveness If opponent’s best move where first more pruning would result: E β=2 S 3 T 5 U -7 V -9 K α=5 ML 2 A α=3 E β=2 S 3 T 5 U -7 V -9 K ML 2 A α=3
  • 59. 59 Alpha-Beta Effectiveness • In practice often get O(b(d/2) ) rather than O(bd ) – same as having a branching factor of sqrt(b) recall (sqrt(b))d = b(d/2) • For Example: chess – goes from b ~ 35 to b ~ 6 – permits much deeper search for the same time
  • 60. 60
  • 61. 61 Other Issues: The Horizon Effect • Sometimes disaster lurks just beyond search depth – e.g. computer captures queen, but a few moves later the opponent checkmates • The computer has a limited horizon, it cannot see that this significant event could happen How do you avoid catastrophic losses due to “short-sightedness”? – quiescence search – secondary search
  • 62. 62 Other Issues: The Horizon Effect • Quiescence Search – when SBE value frequently changing, look deeper than limit – looking for point when game quiets down • Secondary Search 1. find best move looking to depth d 2. look k steps beyond to verify that it still looks good 3. if it doesn't, repeat step 2 for next best move
  • 64. COURTESY: Md. Tarek Habib Assistant Professor Daffodil International University 64
  • 65. ********** ********** If You Need Me ********** ********** Mail: tajim.cse@diu.edu.bd Website: https://www.tajimiitju.blogspot.com ORCID: https://orcid.org/0000-0002-2834-1507 LinkedIn: https://www.linkedin.com/in/tajimiitju ResearchGate: https://www.researchgate.net/profile/Tajim_Md_Niamat_Ullah_Akhund YouTube: https://www.youtube.com/tajimiitju?sub_confirmation=1 SlideShare: https://www.slideshare.net/TajimMdNiamatUllahAk Facebook: https://www.facebook.com/tajim.mohammad GitHub: https://github.com/tajimiitju Google+: https://plus.google.com/+tajimiitju Gmail: tajim.mohammad.3@gmail.com Twitter: https://twitter.com/Tajim53 Thank you Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund 65

Editor's Notes

  • #32: 4 maximum seen so far
  • #35: -3 minimum seen so far
  • #40: -5 minimum seen so far
  • #41: -5 maximum seen so far