AI L6 - Game Theory
AI L6 - Game Theory
Motivation
• examine the role of AI methods in games
• some game provide challenges that can be formulated
as abstract competitions with clearly defined states
and rules
• programs for some games can be derived from
search methods
• narrow view of games
• games can be used to demonstrate the power of
computer-based techniques and methods
• more challenging games require the incorporation of
specific knowledge and information
• expansion of the use of games
• from entertainment to training and education
Objectives
• explore the combination of AI and games
• understand the use and application of search
methods to game programs
• apply refined search methods such as
minimax to simple game configurations
• use alpha-beta pruning to improve the
efficiency of game programs
• understand the influence of chance on the
solvability of chance-based games
• evaluation of methods
• suitability of game techniques for specific
games
• suitability of AI methods for games
games offer concrete or abstract
competitions
• “I’m better than you!”
[Zyda, 2005] Michael Zyda, “From Visual Simulation to Virtual Reality to Games,”
IEEE Computer, vol. 39, no. 9, pp. 25-32.
Aspects of Computer
Games
• story
• defines the context and content of the game
• art
• presentation of the game to the user
• emphasis on visual display, sound
• software
• implementation of the game on a computer
• purpose
• entertainment
• training
• education
Games and AI
• traditionally, the emphasis has been on a narrow view of
games
• formal treatment, often as an expansion of search
algorithms
• more recently, AI techniques have become more important in
computer games
• computer-controlled characters (agents)
• more sophisticated story lines
• more complex environments
• better overall user experience
• Games (especially chess) have been a great focus for AI
research.Why?
• Uncertainty makes them like the real world
• The rules can be well defined
• The game position is easily represented
• There are no moral or ethical problems
• We can match computers against both other computers
and humans
• Playing games is seen as an ”intelligent activity
Cognitive Game Design
• story development
• generation of interesting and appealing story lines
• variations in story lines
• analysis of large-scale game play
• character development
• modeling and simulation of computer-controlled
agents
• possibly enhancement of user-controlled agents
• immersion
• strong engagement of the player’s mind
• emotion
• integration of plausible and believable motion in
characters
• consideration of the user’s emotion
• pedagogy
• achievement of “higher” goals through
entertainment
Game Analysis
• often deterministic
• the outcome of actions is known
• sometimes an element of chance is part of the game
• e.g. dice
• two-player, turn-taking
• one move for each player
• zero-sum utility function
• what one player wins, the other must lose
• often perfect information
• fully observable, everything is known to both players about the state
of the environment (game)
• not for all games
• e.g. card games with “private” or “hidden” cards
• Scrabble
Games as Adversarial Search
• example: chess
• size of the search space
• branching factor around 35
• about 50 moves per player
• about 35100 or 10154 nodes
• about 1040 distinct nodes (size of the search graph)
Search Problem Formulation
• initial state
• board, positions of pieces
• whose turn is it
• successor function (operators)
• list of (move, state)
• defines the legal moves, and the resulting states
• terminal test
• also called goal test
• determines when the game is over
• calculate the result
• usually win, lose, draw, sometimes a score
(see below)
• utility or payoff function
• numeric value for the outcome of a game
Single-Person Game
• conventional search problem
• identify a sequence of moves that
leads to a winning state
• examples: Solitaire, dragons and
dungeons, Rubik’s cube
• little attention in AI
• some games can be quite
challenging
• some versions of solitaire
• a heuristic for Rubik’s cube was
found by the Absolver program
Contingency Problem
• uncertainty due to the moves and
motivations of the opponent
• tries to make the game as difficult
as possible for the player
• attempts to maximize its own, and
thus minimize the player’s utility
function value
• different from contingency due to
neutral factors, such as
• chance
• outside influence
Two-Person Game
• How do we think when we play chess?
MIN moves
MIN moves
MIN moves
3 2 2
MIN
3 12 8 2 ? ? 14 5 2
Alpha-Beta Algorithm
function Max-Value(state, alpha, beta) returns a utility value
if Terminal-Test (state) then return Utility(state)
for each s in Successors(state) do
alpha := Max (alpha, Min-Value(s, alpha, beta))
if alpha >= beta then return beta
end
return alpha
• 1-ply lookahead
• start at the top of the tree
• evaluate all 9 choices for player 1
• pick the maximum E-value
• 2-ply lookahead
• also looks at the opponents possible move
• assuming that the opponents picks the minimum E-value
Tic-Tac-Toe 1-Ply
E(s0) = Max{E(s11), E(s1n)} = Max{2,3,4} = 4
• Red single on 23 9 10 11 12
king on 22 13 14 15 16
• evaluation function 17 18 19 20
where 25 26 27 28
9 10 11 12
13 14 15 16
MAX
17 18 19 20
21 22 23 24
25 26 27 28
1 0 -8 -8
29 30 31 32
MIN
6 1 1 6 1 2 0 -4 -8 -8
MAX
6 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 2 0 0 0 -4 -4 -8 -8 -8 -8
Checkers Alpha-Beta Example
1 2 3 4
1 5 6 7 8
9 10 11 12
13 14 15 16
1 MAX 17 18 19 20
6 21 22 23 24
25 26 27 28
29 30 31 32
1 0 -4 -8
MIN
6 1 1 6 1 2 0 -4 -8 -8
MAX
6 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 2 0 0 0 -4 -4 -8 -8 -8 -8
Checkers Alpha-Beta Example
1 2 3 4
1 5 6 7 8
9 10 11 12
13 14 15 16
1 MAX 17 18 19 20
1 21 22 23 24
25 26 27 28
29 30 31 32
1 0 -4 -8
MIN
6 1 1 6 1 2 0 -4 -8 -8
MAX
6 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 2 0 0 0 -4 -4 -8 -8 -8 -8
Checkers Alpha-Beta Example
1 2 3 4
1
1 5 6 7 8
9 10 11 12
1 13 14 15 16
MAX
− cutoff: no need to
17 18 19 20
21 22 23 24
MIN
6 1 1 6 1 2 0 -4 -8 -8
MAX
6 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 2 0 0 0 -4 -4 -8 -8 -8 -8
Checkers Alpha-Beta Example
1 2 3 4
1
1 5 6 7 8
9 10 11 12
1 13 14 15 16
MAX 17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32
1 0 -4 -8
MIN
6 1 1 6 1 2 0 -4 -8 -8
MAX
6 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 2 0 0 0 -4 -4 -8 -8 -8 -8
Checkers Alpha-Beta Example
1 2 3 4
1
1 5 6 7 8
9 10 11 12
1 13 14 15 16
MAX
− cutoff: no need to
17 18 19 20
21 22 23 24
MIN
6 1 1 6 1 2 0 -4 -8 -8
MAX
6 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 2 0 0 0 -4 -4 -8 -8 -8 -8
Checkers Alpha-Beta Example
1 2 3 4
1
1 5 6 7 8
9 10 11 12
1 13 14 15 16
MAX 17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32
1 0 -4 -8
MIN
6 1 1 6 1 2 0 -4 -8 -8
MAX
6 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 2 0 0 0 -4 -4 -8 -8 -8 -8
Checkers Alpha-Beta Example
1 2 3 4
1
1 5 6 7 8
9 10 11 12
0 13 14 15 16
MAX 17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32
1 0 -4 -8
MIN
6 1 1 6 1 2 0 -4 -8 -8
MAX
6 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 2 0 0 0 -4 -4 -8 -8 -8 -8
Checkers Alpha-Beta Example
1 2 3 4
1
1 5 6 7 8
9 10 11 12
-4 13 14 15 16
MAX
− cutoff: no need to
17 18 19 20
21 22 23 24
MIN
6 1 1 6 1 2 0 -4 -8 -8
MAX
6 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 2 0 0 0 -4 -4 -8 -8 -8 -8
Checkers Alpha-Beta Example
1 2 3 4
1
1 5 6 7 8
9 10 11 12
-8 13 14 15 16
MAX 17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32
1 0 -4 -8
MIN
6 1 1 6 1 2 0 -4 -8 -8
MAX
6 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 2 0 0 0 -4 -4 -8 -8 -8 -8
Horizon Problem