0% found this document useful (0 votes)
38 views

Lec11&12-Adversarial Search

The document discusses adversarial search which is a type of search where agents are planning against each other rather than just exploring the problem space independently. It describes how adversarial searches can model games and competitive environments where multiple agents have conflicting goals. The document outlines the minimax algorithm and alpha-beta pruning which are common approaches used in adversarial search to find optimal strategies.

Uploaded by

ÀbdUŁ ßaŠiŤ
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Lec11&12-Adversarial Search

The document discusses adversarial search which is a type of search where agents are planning against each other rather than just exploring the problem space independently. It describes how adversarial searches can model games and competitive environments where multiple agents have conflicting goals. The document outlines the minimax algorithm and alpha-beta pruning which are common approaches used in adversarial search to find optimal strategies.

Uploaded by

ÀbdUŁ ßaŠiŤ
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Adversarial Search

Adversarial Searches

 Adversarial search is a search, where we examine the problem which arises


when we try to plan ahead of the world and other agents are planning against
us.
 Till now we have only studied the searches where only one agent is exploring
the problem space to find a goal
 In many applications there might be more than one agent looking for a goal
 This gives rise to a 'competitive environment in which agents' goals are in
conflict
 Such scenario usually occurs in game playing where two opponents
(adversaries) are searching for the goal
Games

 In a multiagent environment each agent has to consider the actions of other


agents
 Mathematical game theory views any multiagent environment as a game
 The game tree can become very large
 For instance, Chess has an average branching factor of about 35 and the game
usually go to 50 steps by each player
 Games also penalize efficiency severely
Adversarial Search

 In AI usually deterministic, turn-taking, two player, zero-sum games are


played
 Deterministic, fully observable environment
 Two agents whose actions must alternate
 Utility value at the end of game are always equal and opposite
 All games can be formally modeled as search problems
 Searches , where two or more players with contrary goals are exploring the
same solution space for solution, are called Adversarial Searches Active
Windows
Game Definition

A game in AI can be defined by the following components:


 Initial state: Board position and identify the player to move first
 Player (s): defines which player has to move in a state
 Action (s): returns the set of legal actions at a state
 Result (s, a): the transition model-result of a move
 Terminal-Test (s): is True if the game has ended, False otherwise. States,
where the game has ended, are called terminal states
 Utility (s, p): Utility function :Gives numeric (pay-off) values for terminal
states. e.g. win (+1), loose (-1) and draw (0)
 Also called the objective function or payoff function Active Windows
Game Setup

 The initial state and legal moves for each side define the game tree for the game
 Two players named MAX and MIN playing opposite each other
 MAX moves first
 Both take turns until the game is over
 The winner gets the reward while the loser pays a penalty
Game Trees

 Game trees can get very large as we proceed in the game


 A simple game like tic-tac-toe is too complex for us to draw the entire game
tree on a page
 We shall switch to a simple tree, a tree with a depth of 2( one move deep)
 This tree consists of two half moves, each is called ply
 Each of MAX and MIN has only one move
Optimal Strategies

 Given a game tree, the optimal strategy can be determined from minimax
value of each node
 MAX must have a contingent strategy that specifies its move at the start and
then for each move by MIN
 An optimal strategy, in general, leads to outcomes at least as good as any
other strategy when one is playing against an infallible opponent
Partial game tree (tic-tac-toe)
Types of algorithms in Adversarial search

 In a normal search, we follow a sequence of actions to reach the goal or to


finish the game optimally. But in an adversarial search, the result depends on
the players which will decide the result of the game. The Player will try to
win the game with the shortest path and under limited time.
 There are the following types of adversarial search:
 Minmax Algorithm
 Alpha-beta Pruning
Minmax Algorithm

 In AI, minimax is a decision-making strategy under game theory


 minimize the losing chances
 maximize the winning chances
 also known as ‘Minmax,’ ’MM,’ or ‘Saddle point.’
 easily understand this strategy via game tree
 nodes represent the states of the game
 and edges represent the moves made by the players in the game.
Minmax Algorithm

 Players will be two namely:


 MIN: Decrease the chances of MAX winning the game.
 MAX: Increases his chances of winning the game.
Working of Min-Max Algorithm

 This algorithm applies DFS, so in this


game tree, we have to go all the way
through the leaves to reach the terminal
nodes.
 At the terminal node, the terminal values
are given so we will compare those values
and backtrack the tree until the initial
state occurs.
Working of Min-Max Algorithm

 following are the main steps involved in


solving the two-player game tree:
 Step-1: In the first step, the algorithm
generates the entire game tree and apply
the utility function to get the utility values
for the terminal states. In the below tree
diagram, let's take A as the initial state of
the tree. Suppose the maximizer takes the
first turn which has the worst-case initial
value =- infinity, and minimizer will take
next turn which has worst-case initial
value = +infinity.
Working of Min-Max Algorithm

 Step 2: Now, first we find the utility value


for the Maximizer, its initial value is -∞, so
we will compare each value in the terminal
state with the initial value of the Maximizer
and determines the higher nodes values. It
will find the maximum among all.
 For node D max(-1,- -∞) => max(-1,4)= 4
 For Node E max(2, -∞) => max(2, 6)= 6
 For Node F max(-3, -∞) => max(-3,-5) =
-3
 For node G max(0, -∞) = max(0, 7) = 7
Working of Min-Max Algorithm

 Step 3: In the next step, it's a turn for


minimizer, so it will compare all nodes
value with +∞, and will find the 3rd layer
node values.
 For node B= min(4,6) = 4
 For node C= min (-3, 7) = -3
Working of Min-Max Algorithm

 Now it's a turn for Maximizer, and it will


again choose the maximum of all nodes
value and find the maximum value for the
root node. In this game tree, there are only
4 layers, hence we reach immediately to the
root node, but in real games, there will be
more than 4 layers.
 For node A max(4, -3)= 4
Properties of Mini-Max algorithm:

 Complete- Min-Max algorithm is Complete. It will definitely find a solution (if exist),
in the finite search tree.
 Optimal- Min-Max algorithm is optimal if both opponents are playing optimally.
 Time complexity- As it performs DFS for the game-tree, so the time complexity of
Min-Max algorithm is O(bm), where b is branching factor of the game-tree, and m is
the maximum depth of the tree.
 Space Complexity- Space complexity of Mini-max algorithm is also similar to DFS
which is O(bm).
Limitation of the minimax Algorithm:

 slow for complex games such as Chess, go, etc.


 huge branching factor, and the player has lots of choices to decide
 can be improved from alpha-beta pruning
Alpha-Beta Pruning

 Alpha-beta pruning is a modified version of the minimax algorithm. It is an


optimization technique for the minimax algorithm.
 without checking each node of the game tree we can compute the correct minimax
decision, and this technique is called pruning.
 two threshold parameters Alpha and beta
 So it is called alpha-beta pruning. It is also called as Alpha-Beta Algorithm.
Alpha-Beta Pruning

The two-parameter can be defined as:


 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 +∞.
 The main condition which required for alpha-beta pruning is:
α>=β
Key points about 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.
Working of Alpha-Beta Pruning:

 Step 1: At the first step the, Max


player will start first move from node A
where α= -∞ and β= +∞, these value of
alpha and beta passed down to node B
where again α= -∞ and β= +∞, and
Node B passes the same value to its
child D.
Working of Alpha-Beta Pruning:

 Step 2: At Node D, the value of α will


be calculated as its turn for Max. The
value of α is compared with firstly 2
and then 3, and the max (2, 3) = 3 will
be the value of α at node D and node
value will also 3.
 Step 3: Now algorithm backtrack to
node B, where the value of β will
change as this is a turn of Min, Now β=
+∞, will compare with the available
subsequent nodes value, i.e. min (∞, 3)
= 3, hence at node B now α= -∞, and
β= 3.
Working of Alpha-Beta Pruning:

 In the next step, algorithm traverse the


next successor of Node B which is node E,
and the values of α= -∞, and β= 3 will also
be passed.
 Step 4: At node E, Max will take its turn,
and the value of alpha will change. The
current value of alpha will be compared
with 5, so max (-∞, 5) = 5, hence at node
E α= 5 and β= 3, where α>=β, so the right
successor of E will be pruned, and
algorithm will not traverse it, and the
value at node E will be 5.
Working of Alpha-Beta Pruning:

 Step 5: At next step, algorithm again backtrack


the tree, from node B to node A. At node A, the
value of alpha will be changed the maximum
available value is 3 as max (-∞, 3)= 3, and β= +∞,
these two values now passes to right successor of
A which is Node C.
 At node C, α=3 and β= +∞, and the same values
will be passed on to node F.
 Step 6: At node F, again the value of α will be
compared with left child which is 0, and
max(3,0)= 3, and then compared with right child
which is 1, and max(3,1)= 3 still α remains 3, but
the node value of F will become 1.
Working of Alpha-Beta Pruning:

 Step 5: At next step, algorithm again backtrack


the tree, from node B to node A. At node A, the
value of alpha will be changed the maximum
available value is 3 as max (-∞, 3)= 3, and β= +∞,
these two values now passes to right successor of
A which is Node C.
 At node C, α=3 and β= +∞, and the same values
will be passed on to node F.
 Step 6: At node F, again the value of α will be
compared with left child which is 0, and
max(3,0)= 3, and then compared with right child
which is 1, and max(3,1)= 3 still α remains 3, but
the node value of F will become 1.
Working of Alpha-Beta Pruning:

 Step 7: Node F returns the node value


1 to node C, at C α= 3 and β= +∞, here
the value of beta will be changed, it
will compare with 1 so min (∞, 1) = 1.
Now at C, α=3 and β= 1, and again it
satisfies the condition α>=β, so the
next child of C which is G will be
pruned, and the algorithm will not
compute the entire sub-tree G.
Working of Alpha-Beta Pruning:

 Step 8: C now returns the value of 1 to


A here the best value for A is max (3,
1) = 3. Following is the final game tree
which is the showing the nodes which
are computed and nodes which has
never been computed. Hence the
optimal value for the maximizer is 3
for this example.

You might also like