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

Unit 5

Game playing:
Overview, The min-max search procedure, Min-Max algorithm, alpha
beta cut-offs, planning and its components, Goal stack planning.
Expert Systems.
Game playing
• Rich tradition of creating game-playing programs in AI
• Many similarities to search
• Most of the games studied
• have two players,
• are zero-sum: what one player wins, the other loses
• have perfect information: the entire state of the game is known to both
players at all times
• E.g., tic-tac-toe, checkers, chess, Go, backgammon, …
• Will focus on these for now
• Recently more interest in other games
• Esp. games without perfect information; e.g., poker
• Need probability theory, game theory for such games
Types of games
Overview
• Charles Babbage, the nineteenth-century computer architect thought about
programming his analytical engine to play chess and later of building a machine to play
tic-tac-toe.
• There are two reasons that games appeared to be a good domain.
1. They provide a structured task in which it is very easy to measure success or failure.
2. They are easily solvable by straightforward search from the starting state to a winning
position.
The first is true is for all games bust the second is not true for all, except simplest games.

For example, consider chess.


The average branching factor is around 35. In an average game, each player might make 50.
So in order to examine the complete game tree, we would have to examine 35^100
Game tree
Overview(conti..)
• The effectiveness of a search based problem-solving program two things can do.
1. Improve the generate procedure so that only good moves generated.
2. Improve the test procedure so that the best move will recognize and explored first.

• The performance of the overall system can improve by adding heuristic knowledge into
both the generator and the tester.
• Instead of the legal-move generator, we can use plausible-move generator in which only
some small numbers of promising moves generated.
• This is done using static evaluation function, which uses whatever information it has to
evaluate individual board position by estimating how likely they are to lead eventually to a
win.
MINIMAX Search Procedure
• The minimax search is a depth-first and depth limited procedure.
• The idea is to start at the current position and use the plausible-move generator to generate the set
of possible successor positions.
• Now we can apply the static evaluation function (utility)to those positions and simply choose the best
one.
• After doing so, we can back that value up to the starting position to represent our evolution of it.
• Here we assume that static evaluation function returns larger values to indicate good situations .
• So our goal is to maximize the value of the static evaluation function of the next board position.
• The opponents’ goal is to minimize the value of the static evaluation function.
• The alternation of maximizing and minimizing at alternate ply when evaluations are to be pushed
back up corresponds to the opposing strategies of the two players is called MINIMAX.
MINIMAX ALGORITHM
• It is the recursive procedure that depends on two procedures -
MOVEGEN(position, player)— The plausible-move generator, which returns a list of nodes representing the
moves that can make by Player in Position.
STATIC(position, player)– static evaluation function, which returns a number representing the goodness of
Position from the standpoint of Player.
• With any recursive program, we need to decide when recursive procedure should stop.
• There are the variety of factors that may influence the decision they are,
Has one side won? How many plies have we already explored? How much time is left? How stable is the
configuration?
• The DEEP-ENOUGH which assumed to evaluate all of these factors and to return TRUE if the search should be
stopped at the current level and FALSE otherwise. It takes two parameters, position, and depth, it will ignore
its position parameter and simply return TRUE if its depth parameter exceeds a constant cut off value.
We assume that MINIMAX returns a structure containing both results and we have two functions, VALUE and
PATH that extract the separate components.
Initially, It takes three parameters, a board position, the current depth of the search, and the player to move,
MINIMAX(current,0,player-one) If player –one is to move
MINIMAX(current,0,player-two) If player –two is to move
Do we need to see all the leaves?
• Do we need to see the values of the question marks here?

Player 1
0 1

Player 2 Player 2

0 1 1
0

Player 1 Player 1 Player 1 Player 1

0 1 0 1 0 1 0 1

-1 -2 ? ? -5 6 7 -8
Alpha-beta pruning
• Pruning = cutting off parts of the search tree (because you
realize you don’t need to look at them)
• When we considered A* we also pruned large parts of the search
tree
• Maintain alpha = value of the best option for player 1 along
the path so far
• Beta = value of the best option for player 2 along the path so
far
Alpha-beta pruning
• Alpha-beta pruning is a modified version of the minimax algorithm. It is
an optimization technique for the minimax algorithm.
• As we have seen in the minimax search algorithm that the number of
game states it has to examine are exponential in depth of the tree.
Since we cannot eliminate the exponent, but we can cut it to half.
Hence 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.
• This involves two threshold parameter Alpha and beta for future
expansion, so it is called alpha-beta pruning. It is also called as Alpha-
Beta Algorithm.
• 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.
• The two-parameter can be defined as:
• 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 +∞.
• The Alpha-beta pruning to a standard minimax algorithm returns the same
move as the standard algorithm does, but it removes all the nodes which
are not really affecting the final decision but making algorithm slow. Hence
by pruning these nodes, it makes the algorithm fast.
Key points about alpha-beta pruning

• The Max player will only update the value of alpha.


• The Min player will only update 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.
Example • Step 1: At the first step the,
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.
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 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. In
the next step, algorithm traverse
the next successor of Node B
which is node E, and the values of
α= -∞, and β= 3 will also be
passed.
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.
• Step 5: At next step, 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
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.
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.
Adding alpha-beta cutoffs
• It requires maintaining of two threshold values, one representing a lower
bound on that a maximizing node may ultimately assign (we call this alpha).
• And another representing an upper bound on the value that a minimizing
node may assign (this we call beta).
• Each level must receive both the values, one to use and one to pass down
to the next level to use.
• The MINIMAX procedure as it stands does not need to treat maximizing
and minimizing levels differently. Since it simply negates evaluation each
time it changes levels.
• Instead of referring to alpha and beta, MINIMAX uses two values,
USE-THRESH and PASSTHRESH.
• USE-THRESH used to compute cutoffs. PASS-THRESH passed to next
level as its USETHRESH.
• USE-THRESH must also pass to the next level, but it will pass as PASS-
THRESH so that it can be passed to the third level down as USE-
THRESH again, and so forth.
• Just as values had to negate each time they passed across levels.
• Still, there is no difference between the code required at maximizing
levels and that required at minimizing levels.
• PASS-THRESH should always the maximum of the value it inherits
from above and the best move found at its level.
• If PASS-THRESH updated the new value should propagate both down
to lower levels. And back up to higher ones so that it always reflects
the best move found anywhere in the tree.
• The MINIMAX-A-B requires five arguments, position, depth, player,
Use-thresh, and passThresh.
• MINIMAX-A-B(current,0,player-one,maximum value static can
compute, minimum value static can compute).
Alpha-beta pruning Algorithm
Benefits of alpha-beta pruning
• Without pruning, need to examine O(bm) nodes
• With pruning, depends on which nodes we consider
first
• If we choose a random successor, need to examine
O(b3m/4) nodes
• If we manage to choose the best successor first, need
to examine O(bm/2) nodes
• Practical heuristics for choosing next successor to consider
get quite close to this
• Can effectively look twice as deep!
• Difference between reasonable and expert play
Repeated states
• As in search, multiple sequences of moves may
lead to the same state
• Again, can keep track of previously seen states
(usually called a transposition table in this
context)
• May not want to keep track of all previously seen
states…
Using evaluation functions
• Most games are too big to solve even with alpha-beta
pruning
• Solution: Only look ahead to limited depth
(nonterminal nodes)
• Evaluate nodes at depth cutoff by a heuristic (aka.
evaluation function)
• E.g., chess:
• Material value: queen worth 9 points, rook 5, bishop 3, knight
3, pawn 1
• Heuristic: difference between players’ material values
Move Ordering in Alpha-Beta pruning:
The effectiveness of alpha-beta pruning is highly dependent on the order in which
each node is examined. Move order is an important aspect of alpha-beta pruning.
It can be of two types:
• Worst ordering: In some cases, alpha-beta pruning algorithm does not prune any
of the leaves of the tree, and works exactly as minimax algorithm. In this case, it
also consumes more time because of alpha-beta factors, such a move of pruning
is called worst ordering. In this case, the best move occurs on the right side of the
tree. The time complexity for such an order is O(bm).
• Ideal ordering: The ideal ordering for alpha-beta pruning occurs when lots of
pruning happens in the tree, and best moves occur at the left side of the tree. We
apply DFS hence it first search left of the tree and go deep twice as minimax
algorithm in the same amount of time. Complexity in ideal ordering is O(bm/2).
Planning
• The planning in Artificial Intelligence is about the
decision making tasks performed by the robots or
computer programs to achieve a specific goal.
• The execution of planning is about choosing a sequence
of actions with a high likelihood to complete the specific
task.
• Actions are given as logical descriptions of actions are
given as logical descriptions of preconditions and
effects.
Planning vs Problem Solving
• Planning agent is very similar to problem solving agent
---Constructs plans to achieve goals, then executes them.

Planning agent is different from problem solving agent in :


Representation of goals , states , actions.
Use of explicit ,logical representations
Way it searches for solutions.

Examples of planning are STRIPS,ADL.


Blocks-World planning problem
In order to compare the variety of methods of planning, we should find it
useful to look at all of them in a single domain that is complex enough that
the need for each of the mechanisms is apparent yet simple enough that
easy-to-follow examples can be found.
There is a flat surface on which blocks can be placed.
There are a number of square blocks, all the same size.
They can be stacked one upon the other.
There is robot arm that can manipulate the blocks.
Actions of the robot arm
1. UNSTACK(A, B): Pick up block A from its current position on block B.
2. STACK(A, B): Place block A on block B.
3. PICKUP(A): Pick up block A from the table and hold it.
4. PUTDOWN(A): Put block A down on the table.
Notice that the robot arm can hold only one block at a time.
Predicates
In order to specify both the conditions under which an operation may
be performed and the results of performing it, we need the following
predicates:
1. ON(A, B): Block A is on Block B.
2. ONTABLES(A): Block A is on the table.
3. CLEAR(A): There is nothing on the top of Block A.
4. HOLDING(A): The arm is holding Block A.
5. ARMEMPTY: The arm is holding nothing.
Goal Stack Planning
• This is one of the most important planning algorithms,
which is specifically used by STRIPS. The stack is used in
an algorithm to hold the action and satisfy the goal. A
knowledge base is used to hold the current state,
actions.
• Goal stack is similar to a node in a search tree, where
the branches are created if there is a choice of an
action.
• The important steps of the algorithm are as stated below:

i. Start by pushing the original goal on the stack. Repeat this until
the stack becomes empty. If stack top is a compound goal, then
push its unsatisfied subgoals on the stack.

ii. If stack top is a single unsatisfied goal then, replace it by an


action and push the action’s precondition on the stack to satisfy the
condition.

iii. If stack top is an action, pop it from the stack, execute it and
change the knowledge base by the effects of the action.

iv. If stack top is a satisfied goal, pop it from the stack.


Components of a Planning System
A Simple problem solving tasks basically involve the following tasks:

1.Choose the best rule based upon heuristics.


2.Apply this rule to create a new state.
3.Detect when a solution is found.
4.Detect dead ends so that they can be avoided.
5.Detect when a nearly solved state occurs and use special methods to
make it a solved state(Repairing an Almost Correct Solution).
1) Choose the best rule to apply next, based on the best
available heuristic information.
2) Apply the chosen rule to compute the new problem state that
arises from its application.
3) Detect when a solution has found
• A planning system has succeeded in finding a solution to a problem when
it has found a sequence of operators that transform the initial problem
state into the goal state.
• How will it know when this has done?
• In simple problem-solving systems, this question is easily answered by a
straightforward match of the state descriptions.
• One of the representative systems for planning systems is predicate logic.
Due to its deductive mechanism the researchers often find it more
appealing.
4) Detect dead ends so that they can abandon and the
system’s effort directed in more fruitful directions.
• As a planning system is searching for a sequence of operators to solve a
particular problem, it must be able to detect when it is exploring a path that
can never lead to a solution.
• The same reasoning mechanisms that can use to detect a solution can often
use for detecting a dead end.
• If the search process is reasoning forward from the initial state. It can prune
any path that leads to a state from which the goal state cannot reach.
• If search process reasoning backward from the goal state, it can also
terminate a path either because it is sure that the initial state cannot reach
or because little progress made.
5) Detect when an almost correct solution has found and
employ special techniques to make it totally correct.
• The kinds of techniques discussed are often useful in solving nearly
decomposable problems.
• A slightly better approach is to compared the desired solution and derived
solution and if there is a difference then the problem solving system can be
called again and asked to find a way of eliminating this new difference.
• An even better way to patch up an almost correct solution is to appeal to
specific knowledge about what went wrong and then apply a direct patch.
• A better way is to leave them incompletely specified until the last possible
moment. Then when as much information as possible is available,
complete the specification in such a way that no conflict arise. This
approach is called as Least Commitment Strategy.
Expert Systems
• Expert system = knowledge + problem-solving methods. ...
• A knowledge base that captures the domain-specific knowledge and an
inference engine that consists of algorithms for manipulating the
knowledge represented in the knowledge base to solve a problem
presented to the system.
• Expert systems (ES) are one of the prominent research domains of AI. It is
introduced by the researchers at Stanford University, Computer Science
Department.
What are Expert Systems?
• The expert systems are the computer applications developed to solve
complex problems in a particular domain, at the level of extra-ordinary
human intelligence and expertise.
• Simulates reasoning by applying knowledge and interfaces.
• Uses expert’s knowledge as rules and data within the system
• Models the problem solving ability of a human expert.
Characteristics of Expert Systems
Capabilities of Expert Systems
They are incapable of
• The expert systems are capable of −
• Advising • Substituting human decision
• Instructing and assisting human in decision makers
making
• Possessing human capabilities
• Demonstrating
• Deriving a solution • Producing accurate output for
• Diagnosing inadequate knowledge base
• Explaining • Refining their own knowledge
• Interpreting input
• Predicting results
• Justifying the conclusion
• Suggesting alternative options to a problem
Components of Expert Systems
The components of ES include −
• Knowledge Base
• Inference Engine
• User Interface
Knowledge Base
• It is declarative representation of the expertise, often in IF THEN rules
including such things as simple facts about the domain, rules or constraints
that describe relation or phenomena in the domain, and possibly also
methods, heuristics and ideas for solving problems in the domain.
• It contains domain-specific and high-quality knowledge.
• The success of any ES majorly depends upon the collection of highly accurate
and precise knowledge.
• Stores the data as a set of rules that the system must follow to make
decisions.
Knowledge representation
• It is the method used to organize and formalize the knowledge in the
knowledge base. It is in the form of IF-THEN-ELSE rules.
Knowledge Acquisition

The knowledge engineer also monitors the development of the ES.


Inference Engine
• It carries out the reasoning by interplaying the information or facts
obtained from the user with the knowledge stored in the knowledge base
whereby the expert system reaches a solution.
• It explains about how a particular conclusion is reached and why a specific
fact is needed and also explains its reasoning and justifies its advice,
analysis or conclusion.
In case of rule based ES, it
▪ Applies rules repeatedly to the facts, which are obtained from earlier rule
application.
▪ Adds new knowledge into the knowledge base if required.
▪ Resolves rules conflict when multiple rules are applicable to a particular
case.
To recommend a solution, the Inference Engine uses the following strategies
Forward Chaining

Backward Chaining
User Interface
User interface provides interaction between user and expert system.
It is generally Natural Language Processing so as to be used by the user who
is well-versed in the task domain.
The user of the ES need not be necessarily an expert in Artificial Intelligence.
Requirements of Efficient ES User Interface
• It should help users to accomplish their goals in shortest possible way.
• It should be designed to work for user’s existing or desired work practices.
• It should make efficient use of user input.
• Sends the user questions or answers and receives their responses.
Steps for Development of Expert Systems:
• The process of ES development is iterative. Steps in developing the ES include −
1) Identify Problem Domain –
The problem must be suitable for an expert system to solve it.
Find the experts in task domain for the ES project.
Establish cost-effectiveness of the system.
2) Design the System-
Identify the ES Technology
Know and establish the degree of integration with the other systems and databases.
Realize how the concepts can represent the domain knowledge best.
3) Develop the Prototype From Knowledge Base: The knowledge engineer works to −
Acquire domain knowledge from the expert.
Represent it in the form of If-THEN-ELSE rules.
Steps for Development of Expert Systems:
4) Test and Refine the Prototype
The knowledge engineer uses sample cases to test the prototype for any deficiencies in
performance.
End users test the prototypes of the ES.
5) Develop and Complete the ES
Test and ensure the interaction of the ES with all elements of its environment, including end
users, databases, and other information systems.
Document the ES project well.
Train the user to use ES.
6) Maintain the ES
Keep the knowledge base up-to-date by regular review and update.
Cater for new interfaces with other information systems, as those systems evolve.
Applications of Expert System
Examples of Expert System
1) DENDRIL
It is used in Organic chemistry.It detects unknown organic molecule.
2) MYCIN
It diagnose the blood clot disease.It recommends the antibiotics.
Expert Systems Limitations
• Difficult knowledge acquisition
• ES are difficult to maintain
• High development costs
End of Syllabus : 20CS540

Thank you and all the best

You might also like