6 Game
6 Game
Artificial Intelligence
Contributors
2
Why Game
▪ Why games?
▪ Games like Chess or Go are compact settings that mimic the uncertainty of
interacting with the natural world involving other rational agents
▪ For centuries humans have used them to exert their intelligence
▪ Recently, there has been great success in building game programs that challenge
human supremacy
▪ Axes:
▪ Deterministic or stochastic?
▪ One, two, or more players?
▪ Zero sum?
▪ Perfect information (can you see the state)?
2 0 … 2 6 … 4 6
Value of a State
Value of a state: Non-Terminal States:
The best achievable
outcome (utility)
from that state
2 0 … 2 6 … 4 6
Terminal States:
Adversarial Game Trees
-8 -5 -10 +8
Terminal States:
Tic-Tac-Toe Game Tree
tictactoe – 9!=362880 terminal nodes
Adversarial Search (Minimax)
▪ Deterministic, zero-sum games: Minimax values:
computed recursively
▪ Tic-tac-toe, chess, checkers
▪ One player maximizes result 5 max
▪ The other minimizes result
2 5 min
▪ Minimax search:
▪ A state-space search tree
▪ Players alternate turns
8 2 5 6
▪ Compute each node’s minimax value:
the best achievable utility against a
Terminal values:
rational (optimal) adversary part of the game
Minimax algorithm
▪ Minimax algorithm
▪ Perfect play for deterministic, 2-player game
▪ Max tries to maximize its score
▪ Min tries to minimize Max’s score (Min)
▪ Goal: Max to move to position with highest minimax value
→ Identify best achievable payoff against best play
Minimax Implementation
3 2 2
3 12 8 2 4 6 14 5 2
Poll
What kind of search is Minimax Search?
A) BFS
B) DFS
C) UCS
D) A*
Minimax Example
Generalized minimax
▪ What if the game is not zero-sum, or has multiple players?
▪ Generalization of minimax: 8,8,1
▪ Terminals have utility tuples
▪ Node values are also utility tuples
▪ Each player maximizes its own component 8,8,1 7,7,2
▪ Can give rise to cooperation and
competition dynamically…
▪ Example:
▪ Suppose we have 100 seconds, can explore 10K nodes / sec
▪ So can check 1M nodes per move ? ? ? ?
▪ For chess, b=~35 so reaches about depth 4 – not so good
Depth Matters
▪ Evaluation functions are always
imperfect
▪ Deeper search => better play
(usually)
▪ Or, deeper search gives same quality
of play with a less accurate
evaluation function
▪ An important example of the tradeoff
between complexity of features and
complexity of computation
Evaluation Functions
Evaluation Function
▪ Function E: state s → number E(s)
▪ E(s) is a heuristics: estimates how favorable s is for MAX
▪ E(s) > 0 → s is favorable to MAX (the larger the better)
▪ E(s) < 0 → s is favorable to MIN
▪ Features may include
▪ E(s) = 0 → s is neutral ▪ Number of pieces of each type
▪ Number of possible moves
▪ Number of squares controlled
▪ Why using backed-up values?
▪ At each non-leaf node n, the backed-up value is the value of the best state that MAX
can reach at depth m if MIN plays well (by the same criterion as MAX applies to
itself)
▪ If E is to be trusted in the first place, then the backed-up value is a better estimate
of how favorable STATE(n) is than E(STATE(n))
Evaluation Functions
▪ Evaluation functions score non-terminals in depth-limited search
3 -1
Pruning
-1 This part of the tree can’t
have any effect on the value
that will be backed up to the
root
Game Tree Pruning
Intuition: prune the branches that can’t be chosen
3 2 2
3 12 8 2 4 6 14 5 2
Alpha-Beta Pruning Example
α = best option so far from any
MAX node on this path
α =3 α =3
β=3 β=2 β=14
β=5
β=2
3 12 8 2 14 5 2
We can prune when: min node won’t The order of generation matters: more pruning
be higher than 2, while parent max is possible if good moves come first
has seen something larger in another
branch
Alpha-Beta Implementation
3 12 8 2 4 6 14 5 2
max
min
10 10 0
Alpha-Beta Pruning Properties
▪ This pruning has no effect on minimax value computed for the root!
▪ Book Moves: for some parts of the game (especially initial and end moves),
keep a catalog of best moves to make.
48
Checkers: Tinsley vs. Chinook
5’10” Height 6’ 5”
176 lbs Weight 2,400 lbs
34 years Age 4 years
50 billion neurons Computers 32 RISC processors
+ 256 VLSI chess engines
2 pos/sec Speed 200,000,000 pos/sec
Extensive Knowledge Primitive
Electrical/chemical Power Source Electrical
Enormous Ego None
1997: Deep Blue wins by 3 wins, 1 loss, and 2 draws
Chess: Kasparov vs. Deep Junior
Deep Junior
▪ Pacman