0% found this document useful (0 votes)
50 views39 pages

Adversial Search

Adversarial search involves searching when there is an opponent who can change the state of the problem in an unpredictable way. It is common in games where agents have conflicting goals and compete against each other. Minimax search is commonly used to find the optimal strategy in two-player zero-sum games by recursively evaluating the game tree. Alpha-beta pruning improves on minimax by pruning branches that cannot influence the final decision. Stochastic games introduce randomness, like dice rolls, requiring chance nodes in the game tree in addition to max and min nodes.

Uploaded by

IM AM INEVITABLE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views39 pages

Adversial Search

Adversarial search involves searching when there is an opponent who can change the state of the problem in an unpredictable way. It is common in games where agents have conflicting goals and compete against each other. Minimax search is commonly used to find the optimal strategy in two-player zero-sum games by recursively evaluating the game tree. Alpha-beta pruning improves on minimax by pruning branches that cannot influence the final decision. Stochastic games introduce randomness, like dice rolls, requiring chance nodes in the game tree in addition to max and min nodes.

Uploaded by

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

ADVERSARIAL SEARCH

MODULE -3 CHAPTER-1
ADVERSARIAL SEARCH

 Adversarial search is search when there is an "enemy" or


"opponent" changing the state of the problem every step in a
direction you do not want.
 Examples: Chess, business, trading. You change state, but then
you don't control the next state. Opponent will change the next
state in a way: unpredictable.
 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.
INTRODUCTION TO GAME PLAYING
 When agents’ goals are in conflict, giving rise GAME to
adversarial search problems, often known as games
 Mathematical game theory, a branch of economics, views any
multiagent environment as a game.
 In AI, the most common games are of a rather specialized kind—
what game theorists call deterministic, turn-taking, two-player,
zero-sum games of perfect information.
 This means deterministic, fully observable environments in
which two agents act alternately and in which the utility values at
the end of the game are always equal and opposite.
 The state of a game is easy to represent, and agents are usually
restricted to a small number of actions whose outcomes are
defined by precise rules.
INTRODUCTION TO GAME PLAYING
 Games, unlike most of the toy problems studied are
interesting because they are too hard to solve.
 For example, chess has an average branching factor of
about 35,and games often go to 50 moves by each
player, so the search tree has about 35 power 100
 We first consider games with two players, whom we
call MAX and MIN.
 MAX moves first, and then they take turns moving
until the game is over.
 At the end of the game, points are awarded to the
winning player and penalties are given to the loser.
DEFINING A GAME

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

 Pruning does not affect final result

 Good move ordering improves effectiveness of pruning

 With "perfect ordering," time complexity = O(bm/2)


 Without pruning, need to examine O(bm) nodes
 With pruning, depends on which nodes we consider first
 If we manage to choose the best successor first, need to examine O(bm/2) nodes
Alpha Beta
Pruning :
Cut off search by
exploring less
no .of nodes
The general principle is this: consider a node n somewhere in the tree (see Figure), such that Player has a
choice of moving to that node.
If Player has a better choice m either at the parent node of n or at any choice point further up,then n will
never be reached in actual play.

α = 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.

 The other 15 distinct rolls each have a 1/18 probability


we can only calculate the expected value of a position, the average over all possible outcomes
of the chance nodes.

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

You might also like