Adversial Search
Adversial Search
MODULE -3 CHAPTER-1
ADVERSARIAL SEARCH
A game can be formally defined as a kind of search problem with the following elements:
S0: The initial state, which specifies how the game is set up at the start.
PLAYER(s): Defines which player has the move in a state.
ACTIONS(s): Returns the set of legal moves in a state.
RESULT(s, a): The transition model, which defines the result of a move
TERMINAL-TEST(s): A terminal test, which is true when the game is over and false
otherwise. States where the game has ended are called terminal states
UTILITY(s, p): A utility function (also called an objective function or payoff
function),defines the final numeric value for a game that ends in terminal state s for a
player p. In chess, the outcome is a win, loss, or draw, with values +1, 0, or -1
The initial state, ACTIONS function, and RESULT function define the game tree for
the game—a tree where the nodes are game states and the edges are moves.
Figure shows part of the game tree for tic-tac-toe (noughts and crosses).
OPTIMAL DECISIONS IN GAMES
In a normal search problem, the optimal solution would be a
sequence of actions leading to a goal state -a terminal state that is a
win
In adversarial search, MIN has something to about it, MAX therefore
must find a contingent strategy
Even a simple game like tic-tac-toe is too complex for us to draw the
entire game tree on one page, so we will switch to the trivial game
TWO PLY GAME TREE
Designed to find the optimal strategy for Max and find best move:
1. Generate the whole game tree, down to the leaves.
2. Apply utility (payoff) function to each leaf.
3. Back-up values from leaves through branch nodes:
Max node computes the Max of its child values
Min node computes the Min of its child values
4. At root: choose the move leading to the child of highest value.
The possible moves for MAX at the root node are labelled a1, a2, and a3.
The possible replies to a1 for MIN are b1, b2, b3, and so on.
This particular game ends after one move each by MAX and MIN.
The utilities of PLY the terminal states in this game range from 2 to 14.
EXAMPLE 2:
Given a game tree, the optimal strategy can be determined from the minimax value of each node,
which we write as MINIMAX(n).
The terminal nodes on the bottom level get their utility values from the game’s UTILITY function.
The first MIN node, labelled B, has three successor states with values 3, 12, and 8, so its minimax
value is 3.
Similarly, the other two MIN nodes have minimax value 2.
The root node is a MAX node; its successor states have minimax values 3, 2, and 2; so it has a
minimax value of 3
THE MINIMAX ALGORITHM
The minimax algorithm computes the minimax decision from the current state.
It uses a simple recursive computation of the minimax values of each successor
state, directly implementing the defining equations.
The recursion proceeds all the way down to the leaves of the tree, and then the
minimax values are backed up through the tree as the recursion unwinds
It will be using backtrack Algorithm
Best Move Strategy is used
Max will try to maximize Utility (Best Move)
Min will try to minimize Utility (Worst Move)
OPTIMAL DECISIONS IN MULTIPLAYER GAMES
Many popular games allow more than two players. Let us examine how to extend the minimax
idea to multiplayer games.
This is straightforward from the technical viewpoint, but raises some interesting new
conceptual issues
First, we need to replace the single value for each node with a vector of values.
For example, in a three-player game with players A, B, and C, a vector (vA, vB, Vc) is associated
with each node. For terminal states, this vector gives the utility of the state from each player’s
viewpoint.
The simplest way to implement this is to have the UTILITY function return a vector of utilities
Multiplayer ALLIANCE games usually involve alliances, whether formal or informal,
among the players
ALPHA BETA PRUNNING
The problem with minimax search is that the number of game states it has to
examine is exponential in the depth of the tree.
The trick is that it is possible to compute the correct minimax decision without
looking at every node in the game tree.
we can borrow the idea of pruning to eliminate large parts of the tree from
consideration The particular technique we examine is called ALPHA–BETA beta
pruning.
When applied to a standard PRUNING minimax tree, it returns the same move as
minimax would, but prunes away branches that cannot possibly influence the final
decision.
Pruning allows us to ignore portions of the search tree that make no difference to the final
choice
Α-Β PRUNING: EXAMPLE
Α-Β PRUNING: EXAMPLE
Α-Β PRUNING: EXAMPLE
Α-Β PRUNING: EXAMPLE
Α-Β PRUNING: EXAMPLE
Α-Β PRUNING: EXAMPLE
Α-Β PRUNING: EXAMPLE
Α-Β PRUNING: EXAMPLE
Consider again the two-ply game tree
Let’s go through the calculation of the optimal decision once more, this time paying careful
attention to what we know at each point in the process.
Let the two unevaluated successors of node C in Figure have values x and y. Then the value of the
root node is given by
MINIMAX(root ) = max(min(3, 12, 8), min(2, x, y), min(14, 5, 2))
= max(3, min(2, x, y), 2)
= max(3, z, 2) where z = min(2, x, y) ≤ 2
= 3.
PROPERTIES OF ALPHA-BETA PRUNING
α = the value of the best (i.e., highest-value) choice we have found so far at any choice point along the path for
MAX.
β = the value of the best (i.e., lowest-value) choice we have found so far at any choice point along the path for
MIN.
STOCHASTIC GAMES
In real life, many unpredictable external events can put us into unforeseen situations.
Many games mirror this unpredictability by including a random element, such as the throwing of dice. We
call these stochastic games.
Backgammon is a typical game that combines luck and skill.
Dice are rolled at the beginning of a player’s turn to determine the legal moves
A typical backgammon position.
The goal of the game is to move all one’s pieces off the board.
White moves clockwise toward 25, and Black moves counter clockwise toward 0.
A piece can move to any position unless multiple opponent pieces are there;
if there is one opponent, it is captured and must start over.
https://www.google.com/search?client=ms-android-xiaomi-
rvo2&sxsrf=APwXEdcuKDzagPzM6r4vi6QBp0woVrm37Q:1680193850173&q=Backgammon+rules&sa=X&ved=2ahUKEwjk
mt_siYT-
In the position shown, White has rolled 6–5 and must choose among four legal moves: (5–10,5–11), (5–
11,19–24), (5–10,10–16), and (5–11,11–16), where the notation (5–11,11–16) means move one piece from
position 5 to 11, and then move a piece from 11 to 16.
Although White knows what his or her own legal moves are, White does not know what Black is going to roll
and thus does not know what Black’s legal moves will be.
A Chance nodes game tree in backgammon must include chance nodes in addition to MAX and MIN nodes.
The branches leading from each chance node denote the possible dice rolls; each branch is labelled with the
roll and its probability
There are 36 ways to roll two dice, each equally likely; but because a 6–5 is the same as a 5–6, there are only 21
distinct rolls.
The six doubles (1–1 through 6–6) each have a probability of 1/36, so we say P(1–1) = 1/36.
For chance nodes we compute the expected value, which is the sum of the value over all
outcomes, weighted by the probability of each chance action:
where r represents a possible dice roll (or other chance event) and RESULT(s, r) is the same state
as s, with the additional fact that the result of the dice roll is r.
A)EVALUATION FUNCTIONS FOR GAMES OF CHANCE
One might think that evaluation functions for games such as backgammon should be just like
evaluation functions for chess.
But in fact, the presence of chance nodes means that one has to be more careful about what the
evaluation values mean
with an evaluation function that assigns the values [1, 2, 3, 4] to the leaves, move a1 is best and
with values [1, 20, 30, 400], move a2 is best
The evaluation function must be a positive linear transformation of the probability of winning
from a position
THANK YOU