You are on page 1of 20

Problem Solving

Adversarial Search
Can we apply the recently discussed
search methods to all problems?
 Why or why not?
 How does the search change when there
are multiple actors involved?a
Game Playing
A second player (or more) is an adversary
 Examples: chess, checkers, go, tic-tac-toe, connect
four, backgammon, bridge, poker
 Adversarial search.

Players take turns or alternate play


 Unpredictable opponent.
 Solution specifies a move for every possible opponent
move.

Turn time limits


 How might they affect the search process?
Types of Games

deterministic chance

chess, checkers,
perfect connect four, backgammon
information othello

imperfect bridge, poker,


information scrabble
Example Game: Nim
Deterministic, Opposite Turns
Two players
 One pile of tokens in the middle of the
table.
 At each move, the player divides a pile into
two non-empty piles of different sizes.
 Player who cannot move looses the game.
Example Game: Nim
Assume a pile of seven tokens. 7 min

Max attempts to
maximize the advantage 6-1 5-2 4-3 max
and win.

4-2-1 3-2-2 3-3-1 min


Min always tries to 5-1-1
move to a state that is
the worst for Max. 2-2-2-1 max
4-1-1-1 3-2-1-1

3-1-1-1-1 2-2-1-1-1 min

2-1-1-1-1-1 max
Perfect Decision, Two person games
Two players
 MAX and MIN
MAX moves first; alternate turns thereafter.
Formal definition of game
 Initial State
 Successor Function
 Terminal Test
 Utility Function
No one player has full control, must develop a
strategy.
Minimax Algorithm: Basics
3 MAX

3 0 2 MIN

3 9 0 7 2 6 MAX

MIN
2 3 5 9 0 7 4 2 1 5 6

Process of Backing up: minimax decision


Assumption: Both players are knowledgeable and play
the best possible move
Minmax Algorithm
• Generate game tree to all terminal states.
• Apply utility function to each terminal state.
• Propagate utility of terminal states up one level.
• MAX’s turn: MAX tries to maximize utility value.
• MIN’s turn: MIN minimizes utility value.

• Continue backing-up values toward root, one layer


at a time.
• At root node, MAX chooses the value with highest
utility.
Minimax Search
What is the time complexity of the minimax
algorithm?

Minimax decision: maximizes utility for a player


assuming that the opponent will play perfectly
and minimize its utility.
 m – looking ahead m moves in game tree
 Search can be done in a depth first manner
 i.e. traverse down a path till terminal node reached, then
back up value using minimax decision function.
Minimax: Applied to Nim
1 7 min

1 6-1 1 5-2 1 4-3 max

1 4-2-1 0 3-2-2 1 3-3-1 min


0 5-1-1

0 4-1-1-1 1 3-2-1-1 0 2-2-2-1 max

1
0
3-1-1-1-1 2-2-1-1-1 min
What do we observe from tree?
0 2-1-1-1-1-1 max
Branch and Bound
The basic idea was to reduce the
search space by binding the paths
that exceed the path length from S
to G.
We will discuss the two most famous
ways to improve it.
1. Estimates
2. Dynamic Programming
Branch and Bound
Basic Observation
S

The length of complete path


from S to G, S-D-E-F-G is 9 D

Similarly the length of the


partial path S-D-A-B also is A E
9 and any additional
movement along a branch
will make it longer than 9
B F

9
Branch and Bound
3
A B 3 C
2

4
G
S

S
3 2
D E F
1 3
2 A D 3

5 B D 6 7 A E 4

8 7
8 9 7 10
C E E B B F

10 10 11 11 9
12 11
D F B F C E A C G

G C G F

G
Alpha Beta Pruning
=3
>=3
A Maximizing Level

=3
B =<2 C Minimizing Level

Maximizing Level
3 6 2
Alpha Beta Pruning
50
50
Maximizing Level

50 30 20

Minimizing Level

70 30 20
50
Maximizing Level

50 40 70 10 60 30 80 90 20 90 70 60
Alpha-Beta Pruning
Definitions
  value – lower bound on MAX node
  value – upper bound on MIN node
Observations
  value on MAX nodes never decrease
  values on MIN nodes never increase
Application
 Search is discontinued below any MIN node with min-
value v   :  cut off
 Search is discontinued below any MAX node with
max-value v   :  cut off
Alpha-Beta Search Algorithm
Computing  and 
  value of MAX node = current largest final backed-
up value of its successors.
 value of MIN node = current smallest final backed-

up value of its successors.


Start with AB(n; -, +)

Alpha-Beta Search Algorithm


Alpha-Beta-Search(state) returns an action
v = MAX-VALUE(state,-∞, +∞)
return the action in SUCCESSORS(state) with value v

MAX-VALUE(state, , ) MIN-VALUE(state, , )
if TERMINAL-TEST(state) then if TERMINAL-TEST(state) then
return UTILITY(state) return UTILITY(state)
v = -∞ v = +∞
for a, s in SUCCESSORS(state) do for a, s in SUCCESSORS(state) do
v = MAX(v, MIN-VALUE(s, )) v = MIN(v, MAX-VALUE(s, ))
if v >=  then return v if v <=  then return v
 = MAX(, v)  = MIN(, v)
return v (a utility value) return v (a utility value)
That’s All
Thank You.

You might also like