Unit-Ii: Adversarial Search
Unit-Ii: Adversarial Search
world
UNIT-II
ADVERSARIAL SEARCH
Go, change the
world
CONTENTS
• Games
• Optimal decision in games
• Alpha-beta pruning
Go, change the
world
Introduction
• Multiagents should consider the actions of other
agents and how they affect self.
• Games are competitive environments , agents goal
are in conflict, gives rise to adversarial search
problems.
• Games are deterministic, turn-taking, two-player,
zero-sum games of perfect information .
• State of a game is easy to represent and agents are
restricted to a small number of actions whose
outcomes are defined by precise rules.
Go, change the
world
Introduction
• Games are interesting as they are hard to solve.
• Ex: chess has an average branching factor of about
35, assuming game goes to 50 moves per player,
search tree has about nodes.
• Game playing research deals on how to make the
best possible use of time
• Games deals with optimal move and algorithm for
finding it
• Pruning is considered which ignores portions of the
search tree which makes no difference to final
choice.
Go, change the
world
Introduction
• Games are considered with 2 players MAX and MIN
• At the end of the game points are awarded to the
winning player and penalties are given to the lose.
Go, change the
world
Definition of game
Go, change the
world
Definition of game
• initial state, actions function, result function
define the game tree for the game- a tree where
the nodes are game states and the edges are
moves.
Go, change the
world
Min-Max algorithm
Go, change the
world
Example 1:
Go, change the
world
Example-2
Go, change the
world
Example-3
Go, change the
games
Go, change the
world
Alpha-beta pruning
• Problem with min-max search is the number of
game states to be explored is exponential
• Alpha beta pruning reduces the search to half
• Idea is to eliminate large parts of tree from
consideration
• When applied to standard minimax tree, it returns
the same move as minimax , but prunes branches
which would not influence the final decision.
Go, change the
world
Example:
Go, change the
world
Move ordering
• Effectiveness of alpha beta pruning is dependent on
the order of the nodes visited.
• Visiting in proper order ensures the nodes to be
examined by alpha beta pruning will reduce to
• Number of nodes visited by minimax is
• Adding dynamic move-ordering schemes brings
theoretical limits
• Use of iterative deepening provides killer move
heuristic
Go, change the
world
Why CSP?
• CSP yields a natural representation of wide variety
of problems
• Easy to solve a problem using CSP than to design a
custom solution using another search technique
• CSP solvers are faster than a state space searchers
as CSP eliminates large state space
• Ex: if we choose {SA=blue} , without CSP the
assignments would be with CSP the assignment
would be .
Go, change the
world
scheduling
• Consider the problem of scheduling assembly of a
car.
• Whole job is composed of tasks , each task is a
variable, the value of each variable is the time that
the task starts expressed in minutes
• Constraint is one task must start before other
• Constraint also can specify a task takes certain
amount of time to complete
Go, change the
world
Backtracking algorithm
Go, change the
world
Backtracking algorithm
• backtracking search is used for a depth-first search
that chooses values for one variable at a time and
backtracks when a variable has no legal values left
to assign.
• BACKTRACKING-SEARCH keeps only a single
representation of a state and alters that
representation rather than creating new ones
Go, change the
world
Backtracking algorithm
• Which variable should be assigned next (SELECT-
UNASSIGNED-VARIABLE), and in what order should
its values be tried (ORDER-DOMAIN-VALUES)?
• What inferences should be performed at each step
in the search (INFERENCE)?
• When the search arrives at an assignment that
violates a constraint, can the search avoid repeating
this failure?
Go, change the
world
Go, change the
world
backward
• BACKTRACKING-SEARCH algorithm has a very
simple policy for what to do when a branch of the
search fails: back up to the preceding variable and
try a different value for it. This is called
chronological backtracking because the most recent
decision CHRONOLOGICAL BACKTRACKING point is
revisited.
Go, change the
backward
• Applying simple backtracking with a fixed variable
ordering Q, NSW , V , T, SA, WA, NT. Suppose we
have generated the partial assignment {Q = red,
NSW = green, V = blue, T = red}. When we try the
next variable, SA, we see that every value violates a
constraint.backtracking in the above case is of no
use.
• A more intelligent approach to backtracking is to
backtrack to a variable that might fix the problem—
a variable that was responsible for making one of
the possible values of SA impossible called
backjumping
Go, change the
backward
• Consider again the partial assignment {WA = red,
NSW = red} ,Suppose we try T = red next and then
assign NT, Q, V , SA.
• conflict-directed backjumping.
Go, change the
world
Logical Agents
• Knowledge-based agents
• Wumpus world
• Logic
• Propositional logic
• Propositional theorem proving
Go, change the
world
Logical agents
• Reasoning , operating on knowledge
representation, to deduce conclusions exhibiting
intelligence is part of knowledge-based agents.
• Logic is general class of representation to support
knowledge-based agents
• Knowledge base is the central component of
knowledge based agent.
• KB is set of sentences
• Each sentence is represented in knowledge
representation language
Go, change the
world
Logical agents
• Each sentence represents an assertion about the
world.
• Axiom is another term used for sentence
• Way to add new sentence to KB is TELL and way to
query KB is ASK.
• KB initially contains some background knowledge
Go, change the
world
Wumpus world
• The wumpus world is a cave consisting of rooms
connected by passageways.
• Lurking somewhere in the cave is the terrible
wumpus.
• The wumpus can be shot by an agent, but the agent
has only one arrow.
• Some rooms contain bottomless pits that will trap
anyone who wanders into these rooms (except for
the wumpus, which is too big to fall in)
Go, change the
world
Wumpus world
Go, change the
world
Wumpus world
• Performance measure: +1000 for climbing out of the cave
with the gold, –1000 for falling into a pit or being eaten by
the wumpus, –1 for each action taken and –10 for using up
the arrow. The game ends either when the agent dies or
when the agent climbs out of the cave.
• Environment:A 4 × 4 grid of rooms. The agent always starts
in the square labeled [1,1], facing to the right. The locations
of the gold and the wumpus are chosen randomly, with a
uniform distribution, from the squares other than the start
square. In addition, each square other than the start can be
a pit, with probability 0.2.
Go, change the
world
Wumpus world
• Actuators: The agent can move Forward, TurnLeft
by 90◦, or TurnRight by 90◦. The agent dies a
miserable death if it enters a square containing a
pit or a live wumpus. The action Grab can be used
to pick up the gold if it is in the same square as the
agent. The action Shoot can be used to fire an
arrow in a straight line in the direction the agent is
facing. Finally, the action Climb can be used to
climb out of the cave, but only from square [1,1]
Go, change the
world
Wumpus world
• Sensors: The agent has five sensors, each of which gives a
single bit of information: –
• In the square containing the wumpus and in the directly
adjacent squares, the agent will perceive a Stench.
• In the squares directly adjacent to a pit, the agent will
perceive a Breeze.
• In the square where the gold is, the agent will perceive a
Glitter.
• When an agent walks into a wall, it will perceive a Bump.
• When the wumpus is killed, it emits a woeful Scream that
can be perceived anywhere in the cave
Go, change the
world
Wumpus world
• Percept-The percepts will be given to the agent
program in the form of a list of five symbols;
• [Stench, Breeze, None, None, None].
Go, change the
Logic
• Logic must define the semantics
• Semantics must establish truth of each sentence with
respect to each possible world as either true or false
• logical entailment between sentences—the idea that a
sentence follows logically from another sentence. In
mathematical notation,
• we write α |= β
• The formal definition of entailment is this: α |= β if and only
if, in every model in which α is true, β is also true. Using the
notation just introduced, we can write α |= β if and only if
M(α) ⊆ M(β
Go, change the
world
Logic
• An inference algorithm that derives only entailed
sentences is called sound or truth preserving.
• The final issue to consider is grounding
Go, change the
world
Propositional logic:syntax
• The syntax of propositional logic defines the
allowable sentences.
• The atomic sentences consist of a single
proposition symbol.
• symbols that start with an uppercase letter and
may contain other letters or subscripts. Ex: for
example: P, Q, R, W1,3
• Complex sentences are constructed from simpler
sentences, using parentheses and logical
connectives
Go, change the
world
Propositional logic:syntax
• There are five connectives in common use:
¬ (not), ∧ (and), ∨ (or), ⇒ (implies), ⇔ (if and only
if)
Go, change the
grammar of sentences
Go, change the
world
Semantics
• The semantics defines the rules for determining the
truth of a sentence with respect to a particular
model.
• The semantics for propositional logic specify how to
compute the truth value of any sentence, given a
model.
Go, change the
world
Semantics
• For complex sentences, we have five rules
• ¬P is true iff P is false in m.
• P ∧ Q is true iff both P and Q are true in m.
• P ∨ Q is true iff either P or Q is true in m.
• P ⇒ Q is true unless P is true and Q is false in m.
• P ⇔ Q is true iff P and Q are both true or both
false in m.
Go, change the
world
Semantics
Go, change the
world
TT enumeration algorithm
Go, change the
world
Proof by resolution
• if the available inference rules are inadequate,
resolution, that yields a complete inference
algorithm when coupled with any complete search
algorithm.
• Inference procedures based on resolution work by
using the principle of proof by contradiction
• to show that KB |= α, we show that (KB ∧ ¬α) is
unsatisfiable.
Go, change the
A resolution algorithm
Go, change the
world
A resolution algorithm
• The process continues until one of two things
happens:
• there are no new clauses that can be added, in
which case KB does not entail α; or,
• two clauses resolve to yield the empty clause, in
which case KB entails α
Go, change the
world
Forward Chaining
Go, change the
world
Backward Chaining
• The backward-chaining algorithm, as its name
suggests, works backward from the query. If the
query q is known to be true, then no work is
needed.
• Otherwise, the algorithm finds those implications in
the knowledge base whose conclusion is q.
• If all the premises of one of those implications can
be proved true (by backward chaining), then q is
true
Go, change the
world
Symbols
• The basic syntactic elements of first-order logic are
the symbols that stand for objects, relations, and
functions.
• The symbols, therefore, come in three kinds:
• constant symbols-which stand for objects
• predicate symbols-stands for relations
• function symbols-stands for functions
Symbols begin with upper case letters
Go, change the
world
Interpretation
• in addition to its objects, relations, and functions,
each model includes an interpretation that
specifies exactly which objects, relations and
functions are referred to by the constant, predicate,
and function symbols.
• A term is a logical expression that refers to an
object. Constant symbols are therefore terms, but it
is not always convenient to have a distinct symbol
to name every object.
Go, change the
world
Atomic sentences
• An atomic sentence (or atom for short) is formed
from a predicate symbol optionally followed by a
parenthesized list of terms, such as
• Brother (Richard, John).
• Married(Father (Richard), Mother (John))- atomic
sentences having complex terms as arguments.
• logical connectives can be used to construct more
complex sentences,.
Go, change the
world
Complex sentences
• Brother (Richard, John) ∧ Brother (John, Richard)
• King(Richard) ∨ King(John)
• ¬King(Richard) ⇒ King(John)
Go, change the
world
Universal quantification
• “All kings are persons,” is written in first-order logic
as
• ∀ x King(x) ⇒ Person(x) .
• the sentence ∀ x P, where P is any logical
expression, says that P is true for every object x.
Go, change the
world
Nested quantifiers
• “Brothers are siblings”
• ∀ x ∀ y Brother (x, y) ⇒ Sibling(x, y) .
Nested quantifiers
• “There is someone who is loved by everyone,”
∃ y ∀ x Loves(x, y)
De Morgans rules
• The De Morgan rules for quantified and
unquantified sentences are as follows:
•
Go, change the
world
Equality
• equality symbol to signify that two terms refer to
the same object.
• Father (John) = Henry says that the object referred
to by Father (John) and the object referred to by
Henry are the same.
Go, change the
world