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

Unit2e Adversarial Search

The document discusses multi-agent environments and adversarial search in game theory, focusing on the minimax algorithm and its optimization through alpha-beta pruning. It explains how the minimax algorithm helps determine optimal moves by evaluating game states and highlights the efficiency improvements offered by alpha-beta pruning. The document also outlines the properties, drawbacks, and working steps of both algorithms in the context of game trees.

Uploaded by

Trishna Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Unit2e Adversarial Search

The document discusses multi-agent environments and adversarial search in game theory, focusing on the minimax algorithm and its optimization through alpha-beta pruning. It explains how the minimax algorithm helps determine optimal moves by evaluating game states and highlights the efficiency improvements offered by alpha-beta pruning. The document also outlines the properties, drawbacks, and working steps of both algorithms in the context of game trees.

Uploaded by

Trishna Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Introduction

An environment with more than one agent is called multi-agent


environment.
This leads to game theory wherein each agent is opponent of another
agent.
Each agent needs to consider action of other agents and effect of that
action on their performance.
•Search in which two or more players with conflicting goals try to explore
the same search space for a solution is called adversarial search.
e.g. Tic-tac-toe, chess, checkers.
Introduction
Factors affecting game theory
 Pruning: This technique allows to ignore the unwanted portions of a
search tree which make no difference in the final result
 Evaluation function: This allows to calculate the approximate cost at
each level of the search tree before reaching the goal node
Introduction
Considering games with 2 players called MAX and MIN. MAX makes
the 1st move and then both players take turns until game is over.
At the end of the game, points are awarded to the winning player and
penalties are given to losing player.
A game can be defined as a search problem having following elements
• S0: Initial state
•PLAYER (s): Defines which player has move in the state
•ACTION (s): Returns the set of allowable moves in a state
• RESULT (s, a): Transition model that defines the result of a move
•TERMINAL_TEST (s): True when game is over
•UTILITY (s, p): Final numeric value for a game that ends in terminal
state s for a player p.
Game tree
A tree where nodes of the tree are game states and edges are the moves
by players.
It involves initial state, action’s function and result function
For a gam of Tic-Tac-Toe
There are 2 players MAX and MIN
Players have alternate turns and start with MAX
MAX maximizes result of game tree while MIN minimizes the result
Game tree
Game tree
S0: Initial state: Top node in game tree
•PLAYER (s): 2 players MIN and MAX. MAX begins the game by
picking one best move and places and X in an empty square.
•ACTION (s): Both players make moves in empty boxed chance by
chance
• RESULT (s, a): Moves made by MIN and MAX decide the game
outcome
•TERMINAL_TEST (s): The game terminates when all the empty boxes
are filled
•UTILITY (s, p): At the end we get to know who wind and prize is given
accordingly
Game tree
From initial state, MAX has 09 possible moves.
Play alternates between MAX’s placing an X and MIN’s placing an O
until leaf node corresponding to termination is reached such that any on
player has three in a row or all squares are filled.
The number on each leaf node is the utility value
Game tree
Game tree
Given a game tree, optimal strategy is determined from minimax value
of each node.
Minimax value is the utility of being in the corresponding state

1st minimax node being B has 03 successors with values 3, 12 and 8, so


the minimax value is 3.
For the root node, successor states have values of 3,2,2 so the minimax
value of 3
Min-max Algorithm
• Considered as decision making strategy under game theory, used to
minimize loss chances and (or) maximizing winning chance.

•Minimax is a kind of backtracking algorithm that is used in decision


making and game theory to find the optimal move for a player,
assuming that your opponent also plays optimally.
•Uses recursion to search the game tree.

In Minimax the two players are called maximizer and


minimizer
The maximizer tries to get the highest score possible while the
minimizer tries to do the opposite and get the lowest score possible.
Min-max Algorithm
• Both players fight as the opponent payer gets minimum benefit and they
themselves get the maximum benefit.

MIN: Decreases the chances of MAX to win the game


MAX: Increases his chance s of winning the game

• Performs DFS for exploration of complete game tree.


• The algorithm proceeds all the way down to terminal node and then
backtracks as recursion
Min-max algorithm working
• Consider the given example
•Step 1: 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 is the initial state
of the tree. Suppose maximizer takes
first turn which has worst-case initial
value ‒∞, and minimizer will take
next turn which has worst-case initial
value = +∞.
Min-max algorithm working
•Step 2: Find the utilities value for the Maximizer, its initial value is -∞,
so compare each value in terminal state with initial value of Maximizer
and determines the higher nodes values. It will find the maximum among
the all.
Min-max algorithm working
•Step 3: It's a turn for minimizer, so it will compare all nodes value with
+∞, and will find the 3rd layer node values.
Min-max algorithm working
• Step 4: It's a turn for maximizer, it will again choose the maximum of
all nodes value and find the maximum value for the root node.
Min-max algorithm properties
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).
Min-max algorithm drawbacks
Really slow for complex games such as Chess, go, etc. This type of
games has a huge branching factor, and the player has lots of choices to
decide.
Alpha-Beta Pruning
• Alpha-beta pruning is a modified version of the minimax algorithm. It is
an optimization technique for the minimax algorithm.
• In the minimax search algorithm, the number of game states it has to
examine are exponential in depth of the tree.
• There is a technique by which without checking each node of the game
tree we can compute the correct minimax decision, and this technique is
called pruning.
• Alpha-beta pruning can be applied at any depth of a tree, and sometimes
it not only prune the tree leaves but also entire sub-tree.
• Two main parameters
 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 +∞.
Alpha-Beta Pruning
• The main condition required is that α > =β
• Key points
 The MAX player updates only the value of alpha
 The MIN player updates only 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.
Alpha-Beta pruning working
• Step 1: 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.
Alpha-Beta pruning working
• 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 be 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.
Alpha-Beta pruning working
• 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.
Alpha-Beta pruning working
• Step 5: 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.
Alpha-Beta pruning working
• 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.
Alpha-Beta pruning working
• 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 computed. Hence
the optimal value for the maximizer is 3 for this example.

You might also like