Adversial Search

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

ADVERSIAL SEARCH

AI Adversarial search
• Adversarial search is a game-playing technique where the agents are
surrounded by a competitive environment. A conflicting goal is given to the
agents (multiagent). These agents compete with one another and try to defeat
one another in order to win the game. Such conflicting goals give rise to
the adversarial search. Here, game-playing means discussing those games
where human intelligence and logic factor is used, excluding other factors
such as luck factor. Tic-tac-toe, chess, checkers, etc., are such type of
games where no luck factor works, only mind works.
• Mathematically, this search is based on the concept of ‘Game Theory.’
According to game theory, a game is played between two players. To
complete the game, one has to win the game and the other looses
automatically.’
• Techniques required to get the best optimal solution
• There is always a need to choose those algorithms which provide the
best optimal solution in a limited time. So, we use the following
techniques which could fulfill our requirements:
• Pruning: A technique which allows ignoring the unwanted portions of
a search tree which make no difference in its final result.
• Heuristic Evaluation Function: It allows to approximate the cost
value at each level of the search tree, before reaching the goal node.
• Elements of Game Playing search
• To play a game, we use a game tree to know all the possible choices and to pick the best one
out. There are following elements of a game-playing:
• S0: It is the initial state from where a game begins.
• PLAYER (s): It defines which player is having the current turn to make a move in the state.
• ACTIONS (s): It defines the set of legal moves to be used in a state.
• RESULT (s, a): It is a transition model which defines the result of a move.
• TERMINAL-TEST (s): It defines that the game has ended and returns true.
• UTILITY (s,p): It defines the final value with which the game has ended. This function is
also known as Objective function or Payoff function. The price which the winner will get
i.e.
• (-1): If the PLAYER loses.
• (+1): If the PLAYER wins.
• (0): If there is a draw between the PLAYERS.
Let’s understand the working of the elements with the help of a game tree designed for tic-tac-toe. Here, the node represents the game state and edges represent the moves ta
A game-tree for tic-tac-toe

• INITIAL STATE (S0): The top node in the game-tree represents the initial state in
the tree and shows all the possible choice to pick out one.
• PLAYER (s): There are two players, MAX and MIN. MAX begins the game by
picking one best move and place X in the empty square box.
• ACTIONS (s): Both the players can make moves in the empty boxes chance by
chance.
• RESULT (s, a): The moves made by MIN and MAX will decide the outcome of the
game.
• TERMINAL-TEST(s): When all the empty boxes will be filled, it will be the
terminating state of the game.
• UTILITY: At the end, we will get to know who wins: MAX or MIN, and
accordingly, the price will be given to them.
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.
It is also obvious that the solution for the goal state will be an optimal
solution because the player will try to win the game with the shortest
path and under limited time.
• There are following types of adversarial search:
• Minmax Algorithm
• Alpha-beta Pruning.
• In artificial intelligence, minimax is a decision-making strategy
under game theory, which is used to minimize the losing chances in a
game and to maximize the winning chances. This strategy is also
known as ‘Minmax,’ ’MM,’ or ‘Saddle point.’ Basically, it is a two-
player game strategy where if one wins, the other loose the game. This
strategy simulates those games that we play in our day-to-day life.
Like, if two persons are playing chess, the result will be in favor of
one player and will unfavor the other one. The person who will make
his best try,efforts as well as cleverness, will surely win.
• We can easily understand this strategy via game tree- where the nodes
represent the states of the game and edges represent the moves made
by the players in the game. Players will be two namely:
• MIN: Decrease the chances of MAX to win the game.
• MAX: Increases his chances of winning the game.
• They both play the game alternatively, i.e., turn by turn and following
the above strategy, i.e., if one wins, the other will definitely lose it.
Both players look at one another as competitors and will try to defeat
one-another, giving their best.
• In minimax strategy, the result of the game or the utility value is
generated by a heuristic function by propagating from the initial node
to the root node. It follows the backtracking technique and
backtracks to find the best choice. MAX will choose that path which
will increase its utility value and MIN will choose the opposite path
which could help it to minimize MAX’s utility value.
MINIMAX Algorithm

• MINIMAX algorithm is a backtracking algorithm where it backtracks


to pick the best move out of several choices. MINIMAX strategy
follows the DFS (Depth-first search) concept. Here, we have two
players MIN and MAX, and the game is played alternatively between
them, i.e., when MAX made a move, then the next turn is of MIN. It
means the move made by MAX is fixed and, he cannot change it. The
same concept is followed in DFS strategy, i.e., we follow the same
path and cannot change in the middle.
• MINIMAX algorithm, instead of BFS, we follow DFS.
• Keep on generating the game tree/ search tree till a limit d.
• Compute the move using a heuristic function.
• Propagate the values from the leaf node till the current position
following the minimax strategy.
• Make the best move from the choices.
• For example, in the above figure, the two players MAX and MIN are
there. MAX starts the game by choosing one path and propagating all the
nodes of that path. Now, MAX will backtrack to the initial node and choose
the best path where his utility value will be the maximum. After this,
its MIN chance. MIN will also propagate through a path and again will
backtrack, but MIN will choose the path which could
minimize MAX winning chances or the utility value.
• So, if the level is minimizing, the node will accept the minimum value from
the successor nodes. If the level is maximizing, the node will accept the
maximum value from the successor.
• Note: The time complexity of MINIMAX algorithm is O(bd) where b is the
branching factor and d is the depth of the search tree.
Alpha-beta pruning
• Alpha-beta pruning is an advance version of MINIMAX algorithm.
The drawback of minimax strategy is that it explores each node in the
tree deeply to provide the best path among all the paths. This increases
its time complexity. But as we know, the performance measure is the
first consideration for any optimal algorithm. Therefore, alpha-beta
pruning reduces this drawback of minimax strategy by less exploring
the nodes of the search tree.
• The method used in alpha-beta pruning is that it cutoff the search by
exploring less number of nodes. It makes the same moves as a
minimax algorithm does, but it prunes the unwanted branches using
the pruning technique (discussed in adversarial search).
• Alpha-beta pruning works on two threshold values, i.e., ?
(alpha) and ? (beta).
• ?: It is the best highest value, a MAX player can have. It is the lower
bound, which represents negative infinity value.
• ?: It is the best lowest value, a MIN player can have. It is the upper
bound which represents positive infinity.
• So, each MAX node has ?-value, which never decreases, and each
MIN node has ?-value, which never increases.
• Note: Alpha-beta pruning technique can be applied to trees of any
depth, and it is possible to prune the entire subtrees easily.
Working of Alpha-beta Pruning
• Consider the below example of a game tree where P and Q are two
players. The game will be played alternatively, i.e., chance by chance.
Let, P be the player who will try to win the game by maximizing its
winning chances. Q is the player who will try to minimize P’s
winning chances. Here, ? will represent the maximum value of the
nodes, which will be the value for P as well. ? will represent the
minimum value of the nodes, which will be the value of Q.
• ny one player will start the game. Following the DFS order, the player will choose one path
and will reach to its depth, i.e., where he will find the TERMINAL value.
• If the game is started by player P, he will choose the maximum value in order to increase its
winning chances with maximum utility value.
• If the game is started by player Q, he will choose the minimum value in order to decrease
the winning chances of A with the best possible minimum utility value.
• Both will play the game alternatively.
• The game will be started from the last level of the game tree, and the value will be chosen
accordingly.
• Like in the below figure, the game is started by player Q. He will pick the leftmost value of
the TERMINAL and fix it for beta (?). Now, the next TERMINAL value will be compared
with the ?-value. If the value will be smaller than or equal to the ?-value, replace it with the
current ?-value otherwise no need to replace the value.
• After completing one part, move the achieved ?-value to its upper
node and fix it for the other threshold value, i.e., ?.
• Now, its P turn, he will pick the best maximum value. P will move to
explore the next part only after comparing the values with the
current ?-value. If the value is equal or greater than the current ?-
value, then only it will be replaced otherwise we will prune the values.
• The steps will be repeated unless the result is not obtained.
• So, number of pruned nodes in the above example are four and MAX
wins the game with the maximum UTILITY value, i.e.,3
End……..

You might also like