Part4.Game Playing
Part4.Game Playing
Game playing
Games. Why?
Minimax search
Alpha-beta pruning
Some games:
Ball games
Card games
Board games
Computer games
...
2
Why study board
games ?
One of the oldest sub-fields of AI
3
Game playing
Up till now we have assumed the situation is not
going to change whilst we search.
4
Why study board
games ?
“A chess (or draughts) playing computer would
be proof of a machine doing something thought
to require intelligence”
Game playing research has contributed ideas on how
to make the best use of time to reach good decisions,
when reaching optimal decisions is impossible.
These ideas are applicable in tackling real-world
search problems.
Our limit here: 2-person games, with no chance
5
Why new techniques for
games?
“Contingency” problem:
6
Types of games
Deterministic Chance
7
Game Playing - Chess
Shannon - March 9th 1949 - New York
Size of search space (10120 - average of 40 moves)
8
Game Playing - Chess
1957 - Newell and Simon predicted that a computer
would be chess champion within ten years
Simon : “I was a little far-sighted with chess, but there
was no way to do it with machines that were as slow as
the ones way back then”
1958 - First computer to play chess was an IBM 704 -
about one millionth capacity of deep blue.
1967 : Mac Hack competed successfully in human
tournaments
1983 : “Belle” obtained expert status from the United
States Chess Federation
Mid 80’s : Scientists at Carnegie Mellon University
started work on what was to become Deep Blue.
Project moved to IBM in 1989
9
Game Playing - Chess
May 11th 1997, Gary Kasparov lost a six match game to
Deep blue
3.5 to 2.5
Two wins for deep blue, one win for Kasparov and
three draws
Many computer scientists were excited at this
development
But social scientists had there own feelings, a game is
10
Game Playing - Checkers
(draughts)
Arthur Samuel - 1952
Written for an IBM 701
1954 - Re-wrote for an IBM 704
10,000 words of main memory
11
Game Playing - Checkers
(draughts)
Jonathon Schaeffer - 1996
Developed Chinook
Uses Alpha-Beta search
Plays a perfect end game by means of a database
12
Game Playing - Checkers
(draughts)
In August 1994 there was a re-match but Marion Tinsley
withdrew for health reasons
Chinook became the official world champion
Schaeffer claimed Chinook was rated at 2814
The best human players are rated at 2632 and 2625
Chinook did not include any learning mechanism
13
Game Playing - Checkers
(draughts)
Kumar - 2000
“Learnt” how to play a good game of checkers
The program used a population of games with the best
competing for survival
Learning was done using a neural network with the
synapses being changed by an evolutionary strategy
The best program beat a commercial application 6-0
14
Game Playing - Minimax
Game Playing: An opponent tries to thwart your
every move
1944 - John von Neumann outlined a search
method (Minimax) that maximised your position
whilst minimising your opponents
15
Game Playing - Minimax
Restrictions:
2 players: MAX (computer) and MIN
(opponent)
deterministic, perfect information
Select a depth-bound (say: 2) and evaluation function
MIN 1 B -3 C
MAX 4 D 1 E 2 F -3 G
4 -5 -5 1 -7 2 -3 -8
18
Alpha-Beta idea:
Principles:
generate the tree depth-first, left-to-right
propagate final values of nodes as initial
estimates for their parent node.
MAX 2 - The MIN-value (1) is already
smaller than the MAX-value
of the parent (2)
- The MIN-value can only
decrease further,
MIN 2 =2 1
- The MAX-value is only
allowed to increase,
- No point in computing
further below this node
MAX
2 5 1
19
Terminology:
- The (temporary) values at MAX-nodes are ALPHA-
values
- The (temporary) values at MIN-nodes are BETA-values
MAX 2 Alpha-value
MIN 2 =2 1 Beta-value
MAX
2 5 1
20
The Alpha-Beta principles
(1):
- If an ALPHA-value is larger or equal than the Beta-
value of a descendant node:
stop generation of the children of the
descendant
MAX 2 Alpha-value
MIN 2 =2 1 Beta-value
MAX
2 5 1
21
The Alpha-Beta principles
(2):
- If an Beta-value is smaller or equal than the Alpha-
value of a descendant node:
stop generation of the children of the
descendant
MAX 2
MIN 2 =2 1 Beta-value
MAX Alpha-value
2 5 3
22
example
A
MAX
<=6 B C
MIN
6 D >=8 E
MAX
H I J K
6 5 8
= agent = opponent
23
Alpha-Beta Pruning example
>=6 A
MAX
6 B <=2 C
MIN
6 D >=8 E 2 F G
MAX
H I J K L M
6 5 8 2 1
= agent = opponent
24
Alpha-Beta Pruning example
>=6 A
MAX
6 B 2 C
MIN
6 D >=8 E 2 F G
MAX
H I J K L M
6 5 8 2 1
= agent = opponent
25
Alpha-Beta Pruning example
6 A
MAX
6 B 2 C beta
cutoff
MIN
6 D >=8 E alpha 2 F G
cutoff
MAX
H I J K L M
6 5 8 2 1
= agent = opponent
26
Mini-Max with at work:
4 16 5 31 = 5 39
MAX
86 5 23
= 4 15 = 5 30 3 38
MIN
82 2 10 1 18 1 33
4 12 3 20 3 25 2 35
=85 9 8 9 27 6 29 = 3 37
= 4 14 = 5 22
MAX
8 7 3 9 1 6 2 4 1 1 3 5 3 9 2 6 5 2 1 2 3 9 7 2 8 6 4
1 3 4 7 9 11 13 17 19 21 24 26 28 32 34 36
11 static evaluations 27
“DEEP” cut-offs
- For game trees with at least 4 Min/Max layers:
the Alpha - Beta rules apply also to deeper
levels.
4
4
4
4 2
4 2
28
The Gain: Best case:
- If at every layer: the best node is the left-most one
MAX
MIN
MAX
21 MAX
21 12 3 MIN
21 24 27 12 15 18 3 6 9
MAX
21 20 19 24 23 22 27 26 2512 11 10 15 14 13 18 17 163 2 1 6 5 4 9 8 7
30
Best case gain pictured:
# Static evaluations b = 10
No pruning
100000
10000 Alpha-Beta
Best case
1000
100
10
Depth
1 2 3 4 5 6 7
Queen lost
depth-bound
33
Time bounds:
How to play within reasonable time bounds?
Even with fixed depth-bound, times can vary strongly!
Solution:
Iterative Deepening !!!
34
Summary
35