UNIT II Adversarial Search
UNIT II Adversarial Search
Adversarial Search
• Competitive environments, in which two or more agents have
conflicting goals, giving rise to adversarial search problems.
• Adversarial search: In which we explore environments where other
agents are plotting against us.
• Ex: game problems
• Minmax search
• Alpha-Beta pruning
Game Theory
• adversarial agents, part of the environment—a part that makes the environment
nondeterministic.
• Games require different search procedures.
• Basically they are based on generate and test philosophy.
• The generator generates individual move in the search space, each of which is
then evaluated by the tester and the most promising one is chosen.
• Game playing is most practical and direct application of the heuristic search
problem solving paradigm.
• It is clear that to improve the effectiveness of a search for problem solving
programs, there are two things that can be done:
Improve the generate procedure so that only good moves (paths) are
generated.
Improve the test procedure so that the best moves (paths) will be recognized
and explored first.
Two-player zero-sum games
• Let us consider only two player discrete, perfect information
games, such as tic-tac-toe, chess, checkers etc.
• Discrete because they contain finite number of states or
configurations.
• Perfect-information because both players have access to the
same information about the game in progress (card games are
not perfect - information games).
• zero-sum” what is good for one player is just as bad for the
other: there is no “win-win” outcome
• Two-player games are easier to imagine & think and more
common to play.
• Typical characteristic of the games is to ‘look ahead’ at future
positions in order to succeed.
Correspondence with State
Space
MIN MIN->L
MAX L W L L W W W W L W
Examples:
• Checkers : Non-terminal nodes are 1040 and 1021
centuries required if 3 billion nodes could be generated
each second.
• Chess : 10120 nodes and 10101 centuries.
• So this approach is not practical
Evaluation Function
• Having no practical way of evaluating the exact status of successor
game positions, one may naturally use heuristic approximation.
Optimal Decisions in Games
• MINIMAX search algorithm
• Alpha–Beta Pruning
MINIMAX search
Procedure
• For games with multiple outcome scores, we need a slightly more general
algorithm called minimax search.
• Convention:
Positive number indicates favor to one player
0, an even match
• Total number of rows, columns and diagonals that are still open
for MAX (thick lines) = 6
• Total number of rows, columns and diagonals that are still open
for MIN (dotted lines) = 4
f(P) = (Total number of rows, columns and diagonals that are still
open for MAX) - (total number of rows, columns and diagonals that are
still open for MIN) = 2
Properties of minimax
• Complete : Yes (if tree is finite)
• Optimal : Yes (against an optimal opponent)
• Time complexity : O(bm)
• Space complexity : O(bm) (depth-first exploration)
• For chess, b ≈ 35, m ≈100 for "reasonable" games
• à exact solution completely infeasible.
Limitations
• Not always feasible to traverse entire tree
• Time limitations
Remarks:
• One representing a lower bound () on the value that a maximizing node
may ultimately be assigned (we call this alpha). >=
• =“at least.”
Pruning
• At Max node: of child >= its parent value
• At Min node: of child <= its parent value
Levels 1st step 2nd step 3rd step Final step
F (1)
Levels Game Tree up to 2nd level using - pruning algorithm Pruning
MAX
MAX D(2) E(7) F(1) G
•There is no need to explore right side of the tree fully as that result
is not going to alter the move decision.
• Given below is a game tree of depth 3 and branching factor 3.
• Find which path should be chosen.
MAX O
MIN O O O
MAX O O O O O O O O O
8 7 3 9 1 6 2 4 1 1 3 5 3 9 2 6 5 2 1 2 3 9 7 2 16 6 4
• Given below is a game tree of depth 3 and branching factor 3.
• Note that only 16 static evaluations are made instead of 27 required without alpha-beta
pruning. Pruning
=5
5 • At Max node: of child >= its parent value
• At Min node: of child <= its parent value
MAX 4 O
MIN =4 O =5 O 3 O
8 5
=4 =5 =3
MAX =8 O 9 O 4 O 3 O 9 O O 2 O O O
8 2 1 3 6 1
8 7 3 9 1 6 2 4 1 1 3 5 3 9 2 6 5 2 1 2 3 9 7 2 16 6 4
Heuristic Alpha–Beta Tree Search
• Limited computation time, cut off the search early and apply a heuristic
evaluation function to states, effectively treating nonterminal nodes as if they
were terminal.
• Replace the UTILITY function with EVAL, which estimates a state’s utility.
• For nonterminal states, the evaluation must be somewhere between a loss and a
win: UTILITY(loss, p) ≤ EVAL(s, p) ≤ UTILITY(win, p)
Cutting off search
• The next step is to modify ALPHA-BETA-SEARCH so that it will call the
heuristic EVAL function when it is appropriate to cut off the search. We
replace the two lines that mention IS-TERMINAL with the following line: