Professional Documents
Culture Documents
Adversarial Search
Introduction
• The first successes of artificial intelligence researches
can be connected to games
• The computer program, that was able to play through a
full game of chess was created by Alan Turing in 1951.
• When we try to transplant a game to computer, we
have to give the following information in some way:
• the possible states of the game
• the number of players
• the regular moves
• the initial state
• if randomness has any part in the game
• when will the game end and who will win
Introduction
• A game can be categorized as follows:
– By the number of players:
• 2-player games
• 3-player games etc..
– By the role of randomness
• Deterministic games: randomness plays no role
• Stochastic games: randomness plays role
– By finiteness
• Finite games: all players have finite moves and the game will end
after finite moves
– By profit and loss: Evaluation Function
• Zero-sum games: the total of the players' profit and loss is zero
• Here, we will first deal with 2-player, finite,
deterministic, full information, zero-sum games
Types of Games
Deterministic Chance
Imperfect
Information Battleship Bridge, Poker,
State-space representation
• Any game can be represented by state-space
representation as follows:
• Function of applying:
• removemound , pcs(a1 ,.., an , p)=(a '1 ,.., a 'n , p ‘)
where
• a 'i={ai− pcs , if i=mound
ai , otherwise where 1≤i≤n
• p '={MIN , if p=MAX
MAX , if p=MIN
Example: TIC-TAC-TOE
• On the 3x3 game board, the players put their own
marks in turns. The winner is who puts 3 of his or
her marks in a row, in a column, or in a diagonal
line. The outcome of the game can be a drawn if the
game board is full but no one has 3 marks abreast.
• Set of states: In the states we need to store the
whole 3x3 game boards, and of course the mark of
the player with the next move. One cell of the 3x3
matrix is 0 if none of the players has put a mark
there.
Example: TIC-TAC-TOE
• So the set of states is defined as follows:
• A={(T3×3 , p) ∣ ∀ i , j, Ti , j∈{0,MAX ,MIN} , p∈{MAX
,MIN}}
• Initial state: In the initial state the game board is
completely empty, and player MAX is going to put
his or her mark first
Example: TIC-TAC-TOE
• Set of goal states: The game may end because of
two reasons:
• One of the players has 3 marks abreast.
• The game board is full.
• Namely: C=C1∪ C2 , where
x x x
x x x MIN (o)
x o x o x
MAX (x)
o ……
MINIMAX Algorithm
• Perfect play for deterministic, perfect-information
games
MIN 3 2 2
3 12 8 2 4 6 14 5 2
MIN x
x x
x x x x x o o o o
o o x ox x x x x o x o
o o o
Example: Tic-Tac-Toe
MAX 1
-2
-1
MIN x
1
x x
x x x x x o o o o
o o x ox x x x x o x o
o o o
6-5=1 5-5=0 6-5=1 5-5=0 4-5 = -1 5-4=1 6-4=2 5-6=-1 6-6=0 5-6=-1 6-6=0 4-6=-2
Evaluation function: Chess
• Typical evaluation function for chess
• Weighted sum of features – weighted linear function
• EVAL(s) = w1 f1(s)+w2 f2(s)+···+wn fn(s), where the
w's are the weights, and the f's are the features of
the particular position.
• The w's would be the values of the pieces (1 for
pawn, 3 for bishop, etc.)
• The f's would be the numbers of each kind of piece
on the board.
• e.g. f1(s) = (number of white queens)−(number of
black queens)
Properties: MINIMAX
• Complete? Yes, if the tree is finite
• Time complexity? O(bm)
• Space Complexity? O(bm)
• Disadvantages:
– If we choose a high value for maxDepth , then the
generated tree (and also, the time-demand of the
minimax algorithm) will be very large.
– So, it is worth optimizing the algorithm, based on the
observation that it is often unnecessary to generate
certain parts of the tree.
– Eliminating these parts is the main goal of the alpha-
beta pruning.
ALPHA-BETA Pruning
• With the alpha-beta pruning, we can interrupt the
expansion of a certain vertex.
20 -10 -20 25
200 100 120 20
• B C D MIN
E F G H I J K
4 8 9 3 2 -2 9 -1 8 4 3 6 5 7 1
ALPHA-BETA Pruning Example
• A MAX
• B C D MIN
E F G H I J K
4 8 9 3 2 -2 9 -1 8 4 3 6 5 7 1
• β
• α α
ALPHA-BETA Pruning Example
a MAX
b c MIN
d e f g MAX
MIN h I j k l m n o
10 11 9 12 14 15 13 14 5 2 4 1 3 22 20 21
ALPHA-BETA Pruning Example
>=10 a MAX
10 h <=9 i j 14 k l 2 1 m n o
10 11 9 12 14 15 13 14 5 2 4 1 3 22 20 21
α β
α
Remarks: ALPHA-BETA Pruning
• Alpha-beta pruning is guaranteed to compute the
same minimax value for the root node as computed
by MINIMAX algorithm
• In the worst case, alpha-beta does NO pruning
• In the best case, it will examine only (2b)d/2 leaves
• The best case occurs when each player’s best move
is the leftmost alternative
• In the chess program Deep Blue, Alpha-Beta
pruning finds that the average branching factor at
each node is about 6 instead of about 35 – 40
Choice of Value?
Nondeterministic Game: Backgammon
• Each side of the board has a track of 12 long triangles, called points. The points
are numbered from 1 to 24. In the most commonly used setup, each player
begins with fifteen checkers, two are placed on their 24-point, three on their 8-
point, and five each on their 13-point and their 6-point. The two players move
their chips in opposing directions, from the 24-point towards the 1-point. Points
1 through 6 are called the home board or inner board, and points 7 through 12
are called the outer board. The 7-point is referred to as the bar point, and the
13-point as the midpoint. Usually the 5-point for each player is called the
"golden point". To start the game, each player rolls one die, and the player with
the higher number moves first using the numbers shown on both dice. The
players then take alternate turns, rolling two dice at the beginning of each turn.
The objective is for players to remove (bear off) all their checkers from the
board before their opponent can do the same.
Nondeterministic Game: Backgammon
A typical backgammon position. The aim of the game is to move all one's pieces off the board.
White moves clockwise toward 25, and black moves counterclockwise toward 0. A piece can
move to any position except one where there are two or more of the opponent's pieces. If it
moves to a position with one opponent piece, that piece is captured and has to start its journey
again from the beginning. In this position, white has just rolled 6-5 and has four legal moves:
(5-10,5-11), (5-11,19-24), (5-10,10-16), and (5-11,11-16).
Game Tree: Backgammon
Game Tree: Backgammon
• A game tree in backgammon must include chance
nodes in addition to MAX and MIN nodes
• The branches leading from each chance node denote
the possible dice rolls, and each is labelled with the roll
and the chance that it will occur.
• There are 36 ways to roll two dice, each equally likely
• but because a 6-5 is the same as a 5-6, there are only
21 distinct rolls
• The six doubles (1-1 through 6-6) have a 1/36 chance of
coming up, the other fifteen distinct rolls a 1/18 chance
Game Tree: Backgammon
Choice of Utility Values
Complexity
• it will take O(bmnm), where n is the number of
distinct rolls and b is the branching factor
• Even if the depth of the tree is limited to some
small depth d, the extra cost compared to minimax
makes it unrealistic to consider looking ahead very
far in games such as backgammon
• where n is 21 and b is usually around 20, two ply is
probably all we could manage.