![Page 1: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/1.jpg)
slide 1
Game PlayingPart 2 Alpha-Beta Pruning
Yingyu [email protected]
Computer Sciences DepartmentUniversity of Wisconsin, Madison
[based on slides from A. Moore, C. Dyer, J. Skrentny, Jerry Zhu]
![Page 2: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/2.jpg)
slide 2
S
A
C200
D100
B
E120
F20
max
min
max
min
G
H150
I100
Review: Game Theoretic Value
150
20100
100
The bottom-up approach: needs the whole game tree. Too much space! The minimax algorithm: a variant of DFS to save space.
![Page 3: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/3.jpg)
slide 3
Review: Minimax algorithmfunction Max-Value(s)inputs:
s: current state in game, Max about to playoutput: 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’))return α
function Min-Value(s)output: 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’))return β
• Time complexity?O(bm) bad
• Space complexity? O(bm)
![Page 4: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/4.jpg)
slide 4
Minimax algorithm in execution
S
A
C200
D100
B
E120
F20
max
min
max
min
G
H150
I100
α=-∞
![Page 5: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/5.jpg)
slide 5
Minimax algorithm in execution
S
A
C200
D100
B
E120
F20
max
min
max
min
G
α=-∞
β=+∞
H150
I100
![Page 6: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/6.jpg)
slide 6
Minimax algorithm in execution
S
A
C200
D100
B
E120
F20
max
min
max
min
G
α=-∞
β=200
H150
I100
The execution on the terminal nodes is omitted.
![Page 7: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/7.jpg)
slide 7
Minimax algorithm in execution
S
A100
C200
D100
B
E120
F20
max
min
max
min
G
α=-∞
β=100
H150
I100
![Page 8: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/8.jpg)
slide 8
Minimax algorithm in execution
S
A100
C200
D100
B
E120
F20
max
min
max
min
G
α=100
β=100
H150
I100
![Page 9: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/9.jpg)
slide 9
Minimax algorithm in execution
S
B
E120
F20
max
min
max
min
G
α=100
β=+∞A100
C200
D100
H150
I100
![Page 10: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/10.jpg)
slide 10
Minimax algorithm in execution
S
B
E120
F20
max
min
max
min
G
β=120A100
C200
D100
α=100
H150
I100
![Page 11: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/11.jpg)
slide 11
Minimax algorithm in execution
S
B
E120
F20
max
min
max
min
G
β=20A100
C200
D100
α=100
H150
I100
![Page 12: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/12.jpg)
slide 12
Minimax algorithm in execution
S
B
E120
F20
max
min
max
min
G
β=20A100
C200
D100
α=100
H150
I100
α=-∞
![Page 13: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/13.jpg)
slide 13
Minimax algorithm in execution
S
B
E120
F20
max
min
max
min
G
β=20A100
C200
D100
α=100
H150
I100
α=150
![Page 14: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/14.jpg)
slide 14
Minimax algorithm in execution
S
B
E120
F20
max
min
max
min
G
β=20A100
C200
D100
α=100
H150
I100
α=150
![Page 15: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/15.jpg)
slide 15
Minimax algorithm in execution
S
B
E120
F20
max
min
max
min
G150
β=20A100
C200
D100
α=100
H150
I100
![Page 16: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/16.jpg)
slide 16
Minimax algorithm in execution
S
B20
E120
F20
max
min
max
min
G150
A100
C200
D100
α=100
H150
I100
![Page 17: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/17.jpg)
slide 17
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
![Page 18: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/18.jpg)
slide 18
Recall: Minimax algorithm in execution
S
B
E120
F20
max
min
max
min
G
β=20A100
C200
D100
α=100
The subtree below G is omitted
No matter what the subtree of G looks like, B’s value <=20
![Page 19: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/19.jpg)
slide 19
Recall: Minimax algorithm in execution
S
E120
F20
max
min
max
min
G
A100
C200
D100
α=100
The subtree below G is omitted
B<=20
![Page 20: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/20.jpg)
slide 20
Recall: Minimax algorithm in execution
S
E120
F20
max
min
max
min
G
A100
C200
D100
α=100
The subtree below G is omitted
Max on S must choose A rather than B.B
<=20
![Page 21: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/21.jpg)
slide 21
Recall: Minimax algorithm in execution
S
E120
F20
max
min
max
min
G
A100
C200
D100
α=100
The subtree below G is omitted
No need to check G!
B<=20
X
![Page 22: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/22.jpg)
slide 22
Alpha-Beta Motivation Summary
S
A100
C200
D100
B
E120
F20
max
min
• 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.
GX
![Page 23: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/23.jpg)
slide 23
Alpha-beta pruning example 1
S
A
C200
D100
B
E120
F20
max
min
G
α=-∞β=+∞
• 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. Case 1: happens on a Min node Case 2: happens on a Max node
The subtree below G is omitted
![Page 24: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/24.jpg)
slide 24
Alpha-beta pruning example 1
S
A
C200
D100
B
E120
F20
max
min
G
α=-∞β=+∞
α=-∞β=+∞
![Page 25: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/25.jpg)
slide 25
Alpha-beta pruning example 1
S
A
C200
D100
B
E120
F20
max
min
G
α=-∞β=+∞
α=-∞β=200
![Page 26: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/26.jpg)
slide 26
Alpha-beta pruning example 1
S
A100
C200
D100
B
E120
F20
max
min
G
α=-∞β=+∞
α=-∞β=100
![Page 27: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/27.jpg)
slide 27
Alpha-beta pruning example 1
S
A100
C200
D100
B
E120
F20
max
min
G
α=100β=+∞
α=-∞β=100
![Page 28: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/28.jpg)
slide 28
Alpha-beta pruning example 1
S
B
E120
F20
max
min
G
α=100β=+∞
α=100β=+∞
A100
C200
D100
![Page 29: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/29.jpg)
slide 29
Alpha-beta pruning example 1
S
B
E120
F20
max
min
G
α=100β=120
A100
C200
D100
α=100β=+∞
![Page 30: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/30.jpg)
slide 30
Alpha-beta pruning example 1
S
B
E120
F20
max
min
G
α=100β=20
X
A100
C200
D100
α=100β=+∞
![Page 31: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/31.jpg)
slide 31
Alpha-beta pruning example 2
A
B
D20
E-10
F-20
G25
max
min
max
H30
• 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. Case 1: on a Min node; Case 2: on a Max node
Sα=-∞β=+∞
C
![Page 32: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/32.jpg)
slide 32
Alpha-beta pruning example 2
A
B
D20
E-10
F-20
G25
max
min
max
• 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.
S
α=-∞β=+∞
α=-∞β=+∞
C
H30
![Page 33: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/33.jpg)
slide 33
Alpha-beta pruning example 2
A
B
D20
E-10
F-20
G25
max
min
max
• 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.
S
α=-∞β=+∞
α=-∞β=+∞
α=-∞β=+∞
C
H30
![Page 34: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/34.jpg)
slide 34
Alpha-beta pruning example 2
A
B
D20
E-10
F-20
G25
max
min
max
• 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.
S
α=20β=+∞
α=-∞β=+∞
α=-∞β=+∞
C
H30
![Page 35: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/35.jpg)
slide 35
Alpha-beta pruning example 2
A
B20
D20
E-10
F-20
G25
max
min
max
• 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.
S
α=20β=+∞
α=-∞β=+∞
α=-∞β=+∞
C
H30
![Page 36: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/36.jpg)
slide 36
Alpha-beta pruning example 2
A
B20
D20
E-10
F-20
G25
max
min
max
• 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.
S
α=-∞β=20
α=-∞β=+∞
C
H30
![Page 37: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/37.jpg)
slide 37
Alpha-beta pruning example 2
A
B20
D20
E-10
F-20
G25
max
min
max
• 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.
S
α=-∞β=20
α=-∞β=20
α=-∞β=+∞
C
H30
![Page 38: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/38.jpg)
slide 38
Alpha-beta pruning example 2
A
B20
D20
E-10
F-20
G25
max
min
max
• 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.
S
α=-20β=20
α=-∞β=20
α=-∞β=+∞
C
H30
![Page 39: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/39.jpg)
slide 39
Alpha-beta pruning example 2
A
B20
D20
E-10
F-20
G25
max
min
max
• 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.
S
X
α=25β=20C
H30
![Page 40: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/40.jpg)
slide 40
Alpha-beta pruningfunction Max-Value (s,α,β)inputs:
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 β
Starting from the root:Max-Value(root, -∞, +∞)
![Page 41: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/41.jpg)
slide 41
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.
AAAα=-
O
W-3
B
N4
F G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
max– = – ∞+ = + ∞
[Example from James Skrentny]
![Page 42: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/42.jpg)
slide 42
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.
BBBβ=+
O
W-3
N4
F G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-
max
min
[Example from James Skrentny]
![Page 43: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/43.jpg)
slide 43
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.
FFFα=-
O
W-3
Bβ=+
N4
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-
max
min
max
[Example from James Skrentny]
![Page 44: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/44.jpg)
slide 44
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.
[Example from James Skrentny]
O
W-3
Bβ=+
N4
Fα=-
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-
max
N4
min
max
![Page 45: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/45.jpg)
slide 45
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.
[Example from James Skrentny]
Fα=-
Fα=4
O
W-3
Bβ=+
N4
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-
max
min
max
α updated
![Page 46: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/46.jpg)
slide 46
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.
[Example from James Skrentny]
OOOβ=+
W-3
Bβ=+
N4
Fα=4
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-
max
min
max
min
![Page 47: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/47.jpg)
slide 47
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.
[Example from James Skrentny]
Oβ=+
W-3
Bβ=+
N4
Fα=4
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
K MH3
I8 J L
2
Aα=-
max
min
W-3
min
V-9
![Page 48: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/48.jpg)
slide 48
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.
[Example from James Skrentny]
Oβ=+
Oβ=-3
W-3
Bβ=+
N4
Fα=4
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-
max
min
max
min
![Page 49: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/49.jpg)
slide 49
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.
[Example from James Skrentny]
Oβ=-3
W-3
Bβ=+
N4
Fα=4
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-
max
min
max
minX-5
Pruned!
![Page 50: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/50.jpg)
slide 50
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.
[Example from James Skrentny]
Bβ=+
Bβ=4
Oβ=-3
W-3
N4
Fα=4
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-
max
min
max
minX-5
![Page 51: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/51.jpg)
slide 51
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.
[Example from James Skrentny]
Oβ=-3
W-3
Bβ=4
N4
Fα=4
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-
max
min
max
minX-5
G-5
![Page 52: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/52.jpg)
slide 52
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.
[Example from James Skrentny]
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-
max
min
max
minX-5
G-5
![Page 53: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/53.jpg)
slide 53
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.
[Example from James Skrentny]
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0C
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=-5
max
min
max
minX-5
G-5
![Page 54: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/54.jpg)
slide 54
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.
[Example from James Skrentny]
CCCβ=+
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=
max
min
max
minX-5
Aα=-5
![Page 55: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/55.jpg)
slide 55
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.
[Example from James Skrentny]
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0
Cβ=+
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=
max
min
max
minX-5
Aα=-5
H3
![Page 56: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/56.jpg)
slide 56
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.
[Example from James Skrentny]
Cβ=+
Cβ=3
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=
max
min
max
minX-5
Aα=-5
![Page 57: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/57.jpg)
slide 57
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.
[Example from James Skrentny]
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0
Cβ=3
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8 J L
2
Aα=
max
min
max
minX-5
Aα=-5
I8
![Page 58: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/58.jpg)
slide 58
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.
[Example from James Skrentny]
JJJα=-5
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0
Cβ=3
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8
L2
Aα=
max
min
minX-5
Aα=-5
![Page 59: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/59.jpg)
slide 59
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.
[Example from James Skrentny]
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0
Cβ=3
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8
Jα=-5
L2
Aα=
max
min
max
minX-5
Aα=-5
P9
![Page 60: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/60.jpg)
slide 60
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.
[Example from James Skrentny]
Jα=9
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0
Cβ=3
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8
L2
Aα=
max
min
max
minX-5
Aα=-5
Q-6
R0
![Page 61: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/61.jpg)
slide 61
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.
[Example from James Skrentny]
Jα=-
Jα=9
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0
Cβ=3
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8
L2
Aα=
max
min
max
minX-5
Aα=3
Q-6
R0
![Page 62: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/62.jpg)
slide 62
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.
[Example from James Skrentny]
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
ED0
Cβ=3
R0
P9
Q-6
S3
T5
U-7
V-9
K MH3
I8
Jα=9
L2
Aα=
max
min
max
minX-5
Aα=3
![Page 63: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/63.jpg)
slide 63
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.
[Example from James Skrentny]
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
Eβ=2
D0
Cβ=3
R0
P9
Q-6
S3
T5
U-7
V-9
Kα=5
MH3
I8
Jα=9
L2
Aα=
max
min
max
minX-5
Aα=3
![Page 64: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/64.jpg)
slide 64
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.
[Example from James Skrentny]
Oβ=-3
W-3
Bβ=-5
N4
Fα=4
G-5
X-5
Eβ=2
D0
Cβ=3
R0
P9
Q-6
S3
T5
U-7
V-9
Kα=5
MH3
I8
Jα=9
L2
Aα=
max
min
max
minX-5
Aα=3
![Page 65: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/65.jpg)
slide 65
How effective is alpha-beta pruning?• Depends on the order of successors!
• In the best case, the number of nodes to search is O(bm/2), the square root of minimax’s cost.
• This occurs when each player's best move is the leftmost child. • In DeepBlue (IBM Chess), the average branching factor was
about 6 with alpha-beta instead of 35-40 without.• The worst case is no pruning at all.
Eβ=2
S3
T5
U4
V3
Kα=5
ML2
Eβ=2
S3
T5
U4
V3
Kα=5
M α=4
L2
Eβ=2
S3
T5
U4
V3
K ML2
Aα=3
Aα=3
Aα=3
![Page 66: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/66.jpg)
slide 66
Game-playing for large games• We’ve seen how to find game theoretic values. But it
is too expensive for large games.• What do real chess-playing programs do? They can’t possibly search the full game tree They must respond in limited time They can’t pre-compute a solution
![Page 67: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/67.jpg)
slide 67
Game-playing for large games• The most popular solution: heuristic evaluation
functions for games ‘Leaves’ are intermediate nodes at a depth cutoff,
not terminals Heuristically estimate their values Huge amount of knowledge engineering (R&N 6.4) Example: Tic-Tac-Toe: (number of 3-lengths open for me)-(number of 3-lengths open for you)
• Each move is a new depth-cutoff game-tree search (as opposed to search the complete game-tree once).
![Page 68: Game Playing - GitHub Pages · slide 1 Game Playing. Part 2 Alpha-Beta Pruning. Yingyu Liang. yliang@cs.wisc.edu. Computer Sciences Department. University of Wisconsin, Madison [based](https://reader035.vdocuments.mx/reader035/viewer/2022071413/610a3fb2711cef5b920fb3d5/html5/thumbnails/68.jpg)
slide 68
Prelude• Heuristic estimation of the values of intermediate
nodes can be done via Machine Learning
Game state Machine Learning model Estimated value