Adversarial Search

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

1

Artificial Intelligence
2

Adversarial Search
Minimax • MAX (X) aims to maximize score.
3
• MIN (O) aims to minimize score.

O X X X O X O X
O O O O X X O
O X X X X O X O X

-1 0 1
Game 4

• S0 : initial state
• PLAYER(s) : returns which player to move in state s
• ACTIONS(s) : returns legal moves in state s
• RESULT(s, a) : returns state after action a taken in state s
• TERMINAL(s) : checks if state s is a terminal state
• UTILITY(s) : final numerical value for terminal state s
MIN-VALUE:
PLAYER(s) = O 0
X O 5
O X X
X O

MAX-VALUE: O X O MAX-VALUE: X O
1 O X X 0 O X X
X O X OO

O X O VALUE:
X X O
VALUE:
1 O X X 0 O X X
X X O X OO
MAX-VALUE: 6
1 XO
PLAYER(s) = X OX
X O
MIN-VALUE: X O MIN-VALUE: X X O VALUE: X O
0 O X X -1 O X 1 O X
X O X O X X O

O X O X O X X O X X O
MAX-VALUE: MAX-VALUE: VALUE: MAX-VALUE:
1 O X X 0 O X X -1 O X O 0 O X
X O X OO X O X OO

O X O X X O X X O
VALUE: VALUE: VALUE:
1 O X X 0 O X X 0 O X X
X X O X OO X OO
7
Minimax 8

• Given a state s:
• MAX picks action a in ACTIONS(s) that produces
highest value of MIN-VALUE(RESULT(s, a))
• MIN picks action a in ACTIONS(s) that produces
smallest value of MAX-VALUE(RESULT(s, a))
Minimax 9

function MAX-VALUE(state):
if TERMINAL(state):
return UTILITY(state)
v = -∞
for action in ACTIONS(state):
v = MAX(v, MIN-VALUE(RESULT(state, action)))
return v
Minimax 10

function MIN-VALUE(state):
if TERMINAL(state):
return UTILITY(state)
v=∞
for action in ACTIONS(state):
v = MIN(v, MAX-VALUE(RESULT(state, action)))
return v
Minimax 11
For node D max(-1, -∞) => max(-1,4)= 4
12
Minimax
For node B min(4,6) = 4 For node A max(4, -3)= 4
13
Properties of Mini-Max algorithm

Complete Yes
Optimal Yes
Time complexity O(bm)
Space Complexity O(bm)
14
4

4 3 2

4 8 5 9 3 7 2 4 6
15
4

4 ≤3 ≤2

4 8 5 9 3 2
16

Alpha-Beta Pruning
17
Alpha-beta pruning

modified version of the minimax

Alpha: The best (highest-value) choice we have found so far at any point along the
path of Maximizer. The initial value of alpha is -∞.

Beta: The best (lowest-value) choice we have found so far at any point along the
path of Minimizer. The initial value of beta is +∞.
18
Alpha-beta pruning

• The Max player will only update the value of alpha.

• The Min player will only update the value of beta.

• While backtracking the tree, the node values will be passed to upper nodes
instead of values of alpha and beta.

• We will only pass the alpha, beta values to the child nodes.

Condition for Alpha-beta pruning: α>=β


19
20
21
22
Bad and Good Cases for Alpha-Beta Pruning
23

Worst ordering:
• does not prune any of the leaves
• best move occurs on the right side
• O(bm)

Ideal ordering:
• lots of pruning happens
• best moves occur at the left side
• O(bm/2)
24

Thank you

You might also like