0% found this document useful (0 votes)
19 views34 pages

Ai-Unit 1

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

Ai-Unit 1

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

UNIT 1

Introduction to Al: What is AI? Intelligent Agents: Agents and environment, the concept
ofRationality, the nature of the environment, the structure of agents; Problem-solving:
Problem-solving agents; Uninformed search strategies: DFS, BFS; Informed Search:
Best First Search,A* search, AO* search, Means End Analysis. Adversarial Search ;
Games: Two-player zero-sum games, Minimax Search, Alpha-Beta pruning.

Artificial intelligence (AI) is the simulation of human intelligence in machines that are
programmed to think and act like humans. .

Artificial Intelligence is a method of making a computer, a computer-controlled robot,


or a software think intelligently like the human mind. AI is accomplished by studying
the patterns of the human brain and by analysing the cognitive process. The outcome
of these studies develops intelligent software and systems.

Goals of Artificial Intelligence


Here are the main Goals of AI:

● It helps you reduce the amount of time needed to perform specific tasks.
● Making it easier for humans to interact with machines.
● Facilitating human-computer interaction in a way that is more natural and
efficient.
● Improving the accuracy and speed of medical diagnoses.
● Helping people learn new information more quickly.
● Enhancing communication between humans and machines.

Subfields of Artificial Intelligence


Here, are some important subfields of Artificial Intelligence:

Machine Learning: Machine learning is the art of studying algorithms that


learn from examples and experiences. Machine learning is based on the
idea that some patterns in the data were identified and used for future
predictions.
Deep Learning: Deep learning is a sub-field of machine learning. Deep
learning does not mean the machine learns more in-depth knowledge; it
uses different layers to learn from the data. The depth of the model is
represented by the number of layers in the model. For instance, the
Google LeNet model for image recognition counts 22 layers.

Natural Language Processing: A neural network is a group of connected


I/O units where each connection has a weight associated with its
computer programs. It helps you to build predictive models from large
databases. This model builds upon the human nervous system. You can
use this model to conduct image understanding, human learning,
computer speech, etc.

Expert Systems: An expert system is an interactive and reliable computer-


based decision-making system that uses facts and heuristics to solve
complex decision-making problems. It is also considered at the highest
level of human intelligence. The main goal of an expert system is to solve
the most complex issues in a specific domain.

Fuzzy Logic: Fuzzy Logic is defined as a many-valued logic form that may
have truth values of variables in any real number between 0 and 1. It is the
handle concept of partial truth. In real life, we may encounter a situation
where we can’t decide whether the statement is true or false.
Agents
In the context of the AI field, an “agent” is an independent program or
entity that interacts with its environment by perceiving its surroundings
via sensors, then acting through actuators or effectors.
Agents use their actuators to run through a cycle of perception, thought,
and action.

Examples of agents in general terms include:

Software: This Agent has file contents, keystrokes, and received network
packages that function as sensory input, then act on those inputs,
displaying the output on a screen.
Human: Yes, we’re all agents. Humans have eyes, ears, and other organs
that act as sensors, and hands, legs, mouths, and other body parts act as
actuators.
Robotic: Robotic agents have cameras and infrared range finders that act
as sensors, and various servos and motors perform as actuators.

These are the main four rules all AI agents must adhere to:

Rule 1: An AI agent must be able to perceive the environment.


Rule 2: The environmental observations must be used to make decisions.
Rule 3: The decisions should result in action.
Rule 4: The action taken by the AI agent must be a rational. Rational
actions are actions that maximize performance and yield the best positive
outcome.

Intelligent agents
Intelligent agents in AI are autonomous entities that act upon an environment using
sensors and actuators to achieve their goals. In addition, intelligent agents may learn
from the environment to achieve those goals.
Driverless cars and the Siri virtual assistant are examples of intelligent agents in AI.

Types of intelligent agents


Types of intelligent agents are defined by their range of agent functions and
capabilities and their degree of intelligence:

Simple reflex agents. These agents function in a current state, ignoring past history.
Responses are based on the event-condition-action rule, or ECA rule, where a user
initiates an event and then the agent refers to a list of preset rules and
preprogrammed outcomes.
Model-based reflex agents. These agents take action in the same way as a reflex
agent, but they have a more comprehensive view of their environments. A model of
the world is programmed into the internal system that incorporates the agent's
history.
Goal-based agents. These agents, also referred to as rational agents, expand on the
information that model-based agents store by also including goal information or
information about desirable situations.
Utility-based agents. These agents are similar to goal-based agents, but they provide
an extra utility measurement that rates each possible scenario on its desired result,
and then choose the action that maximizes the outcome. Rating criteria examples
include the probability of success or the resources required.
Learning agents. These agents have the ability to gradually improve and become
more knowledgeable about an environment over time through an additional learning
algorithm or element. The learning element uses feedback on performance measures
to determine how performance elements should be changed to improve gradually.
This concept describes how an AI system should operate.

Examples of intelligent agents


AI assistants such as Alexa and Siri are examples of intelligent AI agents that use
sensors to perceive a user request and automatically collect data from the internet
without the user's help. They can gather information about their observable
environments, such as weather and time.
Google Assistant is another example of an intelligent AI agent. It uses machine
learning and natural language processing technology to answer users' questions and
perform tasks, such as calling contacts stated in voice commands.
Autonomous vehicles can also be considered intelligent robotic agents. They use
sensors, Global Positioning System navigation and cameras for reactive decision-
making in the real world to maneuver through traffic
Environment
The environment is the space or surroundings in which agents operate, and it’s
where they perceive information and execute actions.

Environment is characterised on the basis of PEAS.


1. Performance – What is the performance characteristic which would either make the
agent successful or not. For example, as per the previous example clean floor,
optimal energy consumption might be performance measures.
2. Environment – Physical characteristics and constraints expected. For example, wood
floors, furniture in the way etc
3. Actuators – The physical or logical constructs which would take action. For example
for the vacuum cleaner, these are the suction pumps
4. Sensors – Again physical or logical constructs which would sense the environment.
From our previous example, these are cameras and dirt sensors.
Rationality
Rationality is nothing but status of being reasonable, sensible, and having good sense of judgment.

Rationality is concerned with expected actions and results depending upon what the agent has perceived.
Performing actions with the aim of obtaining useful information is an important part of rationality.

The Nature of Environments


Environments are further divided into several categories. This would aid in
determining the intelligence that the spy would require.

Full or Partial Observability? The agent's sensors do not need to pre-store any
information if they have complete access. Partial access may be sensor inaccuracy or
insufficient environmental data, such as limited access to hostile territory.
Number of Agents — A single agent environment is used for the vacuum cleaner, but
for driverless taxis, each driverless cab is a different agent, resulting in a multi-agent
environment.
Deterministic — The number of unknowns in the environment impacts the
ecosystem's predictability. For example, cleaning floor space is generally predictable,
and furniture stays there most of the time, while taxi driving on the road is not.
Deterministic — The number of unknowns in the environment impacts the
ecosystem's predictability. For example, cleaning floor space is generally predictable,
and furniture stays there most of the time, while taxi driving on the road is not.
Static — How frequently does the surrounding environment change? Is it possible for
the agent t
Problem-Solving Agents In Artificial Intelligence
In artificial intelligence, a problem-solving agent refers to a type of intelligent
agent designed to address and solve complex problems or tasks in its
environment. These agents are a fundamental concept in AI and are used in
various applications, from game-playing algorithms to robotics and decision-
making systems. Here are some key characteristics and components of a
problem-solving agent:

1. Perception : Problem-solving agents typically have the ability to perceive


or sense their environment. They can gather information about the
current state of the world, often through sensors, cameras, or other data
sources.
2. Knowledge Base : These agents often possess some form of knowledge
or representation of the problem domain. This knowledge can be
encoded in various ways, such as rules, facts, or models, depending on
the specific problem.
3. Reasoning : Problem-solving agents employ reasoning mechanisms to
make decisions and select actions based on their perception and
knowledge. This involves processing information, making inferences,
and selecting the best course of action.
4. Planning : For many complex problems, problem-solving agents engage
in planning. They consider different sequences of actions to achieve their
goals and decide on the most suitable action plan.
5. Actuation : After determining the best course of action, problem-solving
agents take actions to interact with their environment. This can involve
physical actions in the case of robotics or making decisions in more
abstract problem-solving domains.
6. Feedback : Problem-solving agents often receive feedback from their
environment, which they use to adjust their actions and refine their
problem-solving strategies. This feedback loop helps them adapt to
changing conditions and improve their performance.
7. Learning : Some problem-solving agents incorporate machine learning
techniques to improve their performance over time. They can learn from
experience, adapt their strategies, and become more efficient at solving
similar problems in the future.
Problem-solving agents can vary greatly in complexity, from simple algorithms
that solve straightforward puzzles to highly sophisticated AI systems that
tackle complex, real-world problems. The design and implementation of
problem-solving agents depend on the specific problem domain and the goals
of the AI application.
AI search algorithms
Artificial Intelligence is the study of building agents that act rationally. Most of the
time, these agents perform some kind of search algorithm in the background in order
to achieve their tasks.
● A search problem consists of:
● A State Space. Set of all possible states where you can be.
● A Start State. The state from where the search begins.
● A Goal State. A function that looks at the current state returns whether
or not it is the goal state.
● The Solution to a search problem is a sequence of actions, called the plan that
transforms the start state to the goal state.
● This plan is achieved through search algorithms.

Types of search algorithms:

There are far too many powerful search algorithms out there to fit in a single article.
Instead, this article will discuss six of the fundamental search algorithms, divided
into two categories, as shown below.

Note that there is much more to search algorithms than the chart I have provided
above. However, this article will mostly stick to the above chart, exploring the
algorithms given there.
Uninformed Search Algorithms:

The search algorithms in this section have no additional information on the goal node
other than the one provided in the problem definition. The plans to reach the goal state
from the start state differ only by the order and/or length of actions. Uninformed
search is also called Blind search. These algorithms can only generate the successors
and differentiate between the goal state and non goal state.
The following uninformed search algorithms are discussed in this section.
1. Depth First Search
2. Breadth First Search
3. Uniform Cost Search

Each of these algorithms will have:


● A problem graph, containing the start node S and the goal node G.
● A strategy, describing the manner in which the graph will be traversed to get to G.
● A fringe, which is a data structure used to store all the possible states (nodes) that
you can go from the current states.
● A tree, that results while traversing to the goal node.
● A solution plan, which the sequence of nodes from S to G.

Depth First Search:

o Depth-first search isa recursive algorithm for traversing a tree or graph data
structure.
o It is called the depth-first search because it starts from the root node and follows
each path to its greatest depth node before moving to the next path.
o DFS uses a stack data structure for its implementation.
o The process of the DFS algorithm is similar to the BFS algorithm.

Advantage:

o DFS requires very less memory as it only needs to store a stack of the nodes on
the path from root node to the current node.
o It takes less time to reach to the goal node than BFS algorithm (if it traverses in
the right path).

Disadvantage:
o There is the possibility that many states keep re-occurring, and there is no guarantee
of finding the solution.
o DFS algorithm goes for deep down searching and sometime it may go to the infinite
loop.

it will follow the order as:

Root node--->Left node ----> right node.

Example:
Question. Which solution would DFS find to move from node S to node G if run on
the graph below?

Solution. The equivalent search tree for the above graph is as follows. As DFS
traverses the tree “deepest node first”, it would always pick the deeper branch until
it reaches the solution (or it runs out of nodes, and goes to the next branch). The
traversal is shown in blue arrows.
This ad will end in 11

Path: S -> A -> B -> C -> G


Breadth First Search:

o Breadth-first search is the most common search strategy for traversing a


tree or graph. This algorithm searches breadthwise in a tree or graph, so
it is called breadth-first search.
o BFS algorithm starts searching from the root node of the tree and expands
all successor node at the current level before moving to nodes of next
level.
o The breadth-first search algorithm is an example of a general-graph
search algorithm.
o Breadth-first search implemented using FIFO queue data structure.

Advantages:

o BFS will provide a solution if any solution exists.


o If there are more than one solutions for a given problem, then BFS will provide
the minimal solution which requires the least number of steps.

Disadvantages

o It requires lots of memory since each level of the tree must be saved into
memory to expand the next level.
o BFS needs lots of time if the solution is far away from the root node.

Example:
Question. Which solution would BFS find to move from node S to node G if run on
the graph below?
Solution. The equivalent search tree for the above graph is as follows. As BFS
traverses the tree “shallowest node first”, it would always pick the shallower branch
until it reaches the solution (or it runs out of nodes, and goes to the next branch).
The traversal is shown in blue arrows.

Path: S -> D -> G


Uniform Cost Search:

UCS is different from BFS and DFS because here the costs come into play. In other
words, traversing via different edges might not have the same cost. The goal is to
find a path where the cumulative sum of costs is the least.
Cost of a node is defined as:
cost(node) = cumulative cost of all nodes from root
cost(root) = 0
Example:
Question. Which solution would UCS find to move from node S to node G if run on
the graph below?

Solution. The equivalent search tree for the above graph is as follows. The cost of
each node is the cumulative cost of reaching that node from the root. Based on the
UCS strategy, the path with the least cumulative cost is chosen. Note that due to the
many options in the fringe, the algorithm explores most of them so long as their cost
is low, and discards them when a lower-cost path is found; these discarded
traversals are not shown below. The actual traversal is shown in blue.
Path: S -> A -> B -> G

Advantages:
● UCS is complete only if states are finite and there should be no loop with zero
weight.
● UCS is optimal only if there is no negative cost.
Disadvantages:
● Explores options in every “direction”.
● No information on goal location.

Informed Search Algorithms:


Here, the algorithms have information on the goal state, which helps in more efficient
searching. This information is obtained by something called a heuristic.
In this section, we will discuss the following search algorithms.
1. Greedy Search
2. A* Tree Search
3. A* Graph Search
Search Heuristics: In an informed search, a heuristic is a function that estimates
how close a state is to the goal state. For example – Manhattan distance, Euclidean
distance, etc. (Lesser the distance, closer the goal.) Different heuristics are used in
different informed algorithms discussed below.
Greedy Search OR Best Fit Search

In greedy search, we expand the node closest to the goal node. The “closeness” is
estimated by a heuristic h(x).
Heuristic: A heuristic h is defined as-
h(x) = Estimate of distance of node x from the goal node.
Lower the value of h(x), closer is the node from the goal.
Strategy: Expand the node closest to the goal state, i.e. expand the node with a
lower h value.
Example:
Question. Find the path from S to G using greedy search. The heuristic values h of
each node below the name of the node.

Solution. Starting from S, we can traverse to A(h=9) or D(h=5). We choose D, as it


has the lower heuristic cost. Now from D, we can move to B(h=4) or E(h=3). We
choose E with a lower heuristic cost. Finally, from E, we go to G(h=0). This entire
traversal is shown in the search tree below, in blue.
Path: S -> D -> E -> G
Advantage: Works well with informed search problems, with fewer steps to reach a
goal.
Disadvantage: Can turn into unguided DFS in the worst case.
A* Tree Search:
A* Tree Search, or simply known as A* Search, combines the strengths of uniform-
cost search and greedy search. In this search, the heuristic is the summation of the
cost in UCS, denoted by g(x), and the cost in the greedy search, denoted by h(x).
The summed cost is denoted by f(x).
Heuristic: The following points should be noted wrt heuristics in A* search.

● Here, h(x) is called the forward cost and is an estimate of the distance of the
current node from the goal node.
● And, g(x) is called the backward cost and is the cumulative cost of a node from
the root node.
● A* search is optimal only when for all nodes, the forward cost for a node h(x)
underestimates the actual cost h*(x) to reach the goal. This property
of A* heuristic is called admissibility.
Admissibility:
Strategy: Choose the node with the lowest f(x) value.
Example:
Question. Find the path to reach from S to G using A* search.

Solution. Starting from S, the algorithm computes g(x) + h(x) for all nodes in the
fringe at each step, choosing the node with the lowest sum. The entire work is
shown in the table below.
Note that in the fourth set of iterations, we get two paths with equal summed cost
f(x), so we expand them both in the next set. The path with a lower cost on further
expansion is the chosen path.

Path h(x) g(x) f(x)


S 7 0 7

S -> A 9 3 12

S -> D 5 2 7

S -> D -> B 4 2+1=3 7


S -> D -> E 3 2+4=6 9

S -> D -> B -> C 2 3+2=5 7

S -> D -> B -> E 3 3+1=4 7

S -> D -> B -> C -> G 0 5+4=9 9

S -> D -> B -> E -> G 0 4+3=7 7


Path: S -> D -> B -> E -> G
Cost: 7
A* Graph Search:
● A* tree search works well, except that it takes time re-exploring the branches it
has already explored. In other words, if the same node has expanded twice in
different branches of the search tree, A* search might explore both of those
branches, thus wasting time
● A* Graph Search, or simply Graph Search, removes this limitation by adding this
rule: do not expand the same node more than once.
● Heuristic. Graph search is optimal only when the forward cost between two
successive nodes A and B, given by h(A) – h (B), is less than or equal to the
backward cost between those two nodes g(A -> B). This property of the graph
search heuristic is called consistency.
Consistency:
Example:
Question. Use graph searches to find paths from S to G in the following graph.

the Solution. We solve this question pretty much the same way we solved last
question, but in this case, we keep a track of nodes explored so that we don’t re-
explore them.
Path: S -> D -> B -> E -> G
Cost: 7

Mean End Analysis


Problem-solving in artificial intelligence is the application of heuristics,
root cause analysis, and algorithms to provide solutions to AI problems.

It is an effective way of reaching a target goal from a problematic state.


This process begins with the collection of data relating to the problem.
This data is then analysed to establish a suitable solution.

Means end analysis is a technique used to solve problems in AI


programs. This technique combines forward and backward strategies to
solve complex problems. With these mixed strategies, complex problems
can be tackled first, followed by smaller ones.

In this technique, the system evaluates the differences between the


current state or position and the target or goal state. It then decides the
best action to be undertaken to reach the end goal.
How MEA works
Means end analysis uses the following processes to achieve its
objectives:

1. First, the system evaluates the current state to establish whether


there is a problem. If a problem is identified, then it means that an
action should be taken to correct it.
2. The second step involves defining the target or desired goal that
needs to be achieved.
3. The target goal is split into sub-goals, that are further split into other
smaller goals.
4. This step involves establishing the actions or operations that will be
carried out to achieve the end state.
5. In this step, all the sub-goals are linked with corresponding
executable actions (operations).
6. After that is done, intermediate steps are undertaken to solve the
problems in the current state. The chosen operators will be applied
to reduce the differences between the current state and the end
state.
7. This step involves tracking all the changes made to the actual state.
Changes are made until the target state is achieved.

The following image shows how the target goal is divided into sub-goals,
that are then linked with executable actions.
Algorithm steps for Means End Analysis
The following are the algorithmic steps for means end analysis:

1. Conduct a study to assess the status of the current state. This can
be done at a macro or micro level.
2. Capture the problems in the current state and define the target
state. This can also be done at a macro or micro level.
3. Make a comparison between the current state and the end state that
you defined. If these states are the same, then perform no further
action. This is an indication that the problem has been tackled. If the
two states are not the same, then move to step 4.
4. Record the differences between the two states at the two
aforementioned levels (macro and micro).
5. Transform these differences into adjustments to the current state.
6. Determine the right action for implementing the adjustments in step
5.
7. Execute the changes and compare the results with the target goal.
8. If there are still some differences between the current state and the
target state, perform course correction until the end goal is
achieved.

Example of problem-solving in Means


End Analysis
Let’s assume that we have the following initial state.

We want to apply the concept of means end analysis to establish whether


there are any adjustments needed. The first step is to evaluate the initial
state, and compare it with the end goal to establish whether there are any
differences between the two states.
The following image shows a comparison between the initial state and
the target state.

The image above shows that there is a difference between the current
state and the target state. This indicates that there is a need to make
adjustments to the current state to reach the end goal.

The goal can be divided into sub-goals that are linked with executable
actions or operations.

The following are the three operators that can be used to solve the
problem.

1. Delete operator: The dot symbol at the top right corner in the initial
state does not exist in the goal state. The dot symbol can be removed by
applying the delete operator.

2. Move operator: We will then compare the new state with the end state.
The green diamond in the new state is inside the circle while the green
diamond in the end state is at the top right corner. We will move this
diamond symbol to the right position by applying the move operator.
3. Expand operator: After evaluating the new state generated in step 2,
we find that the diamond symbol is smaller than the one in the end state.
We can increase the size of this symbol by applying the expand operator.

After applying the three operators above, we will find that the state in step
3 is the same as the end state. There are no differences between these
two states, which means that the problem has been solved.

Applications of Means End Analysis


Means end analysis can be applied in the following fields:

Organizational planning
Means end analysis is used in organizations to facilitate general
management. It helps organizational managers to conduct planning to
achieve the objectives of the organization. The management reaches the
desired goal by dividing the main goals into sub-goals that are linked with
actionable tasks.

Business transformation
This technique is used to implement transformation projects. If there are
any desired changes in the current state of a business project, means
end analysis is applied to establish the new processes to be
implemented. The processes are split into sub-processes to enhance
effective implementation.

Gap analysis
Gap analysis is the comparison between the current performance and the
required performance. Means end analysis is applied in this field to
compare the existing technology and the desired technology in
organizations. Various operations are applied to fill the existing gap in
technology.
Adversarial Search
Adversarial search is a search, where we examine the problem which arises when we try
to plan ahead of the world and other agents are planning against us.

o In previous topics, we have studied the search strategies which are only associated
with a single agent that aims to find the solution which often expressed in the form of
a sequence of actions.
o But, there might be some situations where more than one agent is searching for the
solution in the same search space, and this situation usually occurs in game playing.
o The environment with more than one agent is termed as multi-agent environment , in
which each agent is an opponent of other agent and playing against each other. Each
agent needs to consider the action of other agent and effect of that action on their
performance.
o So, Searches in which two or more players with conflicting goals are trying to
explore the same search space for the solution, are called adversarial searches,
often known as Games .
o Games are modelled as a Search problem and heuristic evaluation function, and these
are the two main factors which help to model and solve games in AI.

Adversarial search in artificial intelligence is used to resolve two-person games in


which one player seeks to maximize their score while the other tries to minimize it.
Chess, checkers, and tic-tac-toe are the three most popular games that can be
solved via adversarial search. In many real-world applications, such as financial
decision-making and military operations, adversarial search is used. To give players
clever opponents in video games, it is also deployed.

Types of Games in AI:

Deterministic Chance Moves

Perfect information Chess, Checkers, go, Othello Backgammon, monopoly

Imperfect information Battleships, blind, tic-tac-toe Bridge, poker, scrabble, n

o Perfect information: A game with the perfect information is that in which agents can
look into the complete board. Agents have all the information about the game, and
they can see each other moves also. Examples are Chess, Checkers, Go, etc.
o Imperfect information: If in a game agents do not have all information about the game
and not aware with what's going on, such type of games are called the game with
imperfect information, such as tic-tac-toe, Battleship, blind, Bridge, etc.
o Deterministic games: Deterministic games are those games which follow a strict
pattern and set of rules for the games, and there is no randomness associated with
them. Examples are chess, Checkers, Go, tic-tac-toe, etc.
o Non-deterministic games: Non-deterministic are those games which have various
unpredictable events and has a factor of chance or luck. This factor of chance or luck
is introduced by either dice or cards. These are random, and each action response is
not fixed. Such games are also called as stochastic games.
Example: Backgammon, Monopoly, Poker, etc.

TWO PLAYERS ZERO SUM GAME

The 2-players 0-sum game is a basic model in game theory. There are two players, each
with an associated set of strategies. While one player aims to maximize her payoff, the other
player attempts to take an action to minimize this payoff. In fact, the gain of a player is the
loss of another.

Each 2-players game consists of 2 players;

o Strategies available to each player;


o Payoffs for each player;
▪ the payoff is the amount of benefit or loss that a player derives if a
particular outcome happens.
▪ the payoff of each player depends on her choice, and also depends on
the choice of the other player.
MINIMAX ALGORITHM

Minimax is a kind of backtracking algorithm that is used in decision making and game
theory to find the optimal move for a player, assuming that your opponent also plays
optimally. It is widely used in two player turn-based games such as Tic-Tac-Toe,
Backgammon, Mancala, Chess, etc.

In Minimax the two players are called maximizer and minimizer. The maximizer tries
to get the highest score possible while the minimizer tries to do the opposite and get
the lowest score possible.
Every board state has a value associated with it. In a given state if the maximizer has
upper hand then, the score of the board will tend to be some positive value. If the
minimizer has the upper hand in that board state then it will tend to be some negative
value. The values of the board are calculated by some heuristics which are unique for
every type of game.

Example:
Consider a game which has 4 final states and paths to reach final state are from root
to 4 leaves of a perfect binary tree as shown below. Assume you are the maximizing
player and you get the first chance to move, i.e., you are at the root and your opponent
at next level. Which move you would make as a maximizing player considering that
your opponent also plays optimally?

Since this is a backtracking based algorithm, it tries all possible moves, then backtracks
and makes a decision.
● Maximizer goes LEFT: It is now the minimizers turn. The minimizer now has a
choice between 3 and 5. Being the minimizer it will definitely choose the least
among both, that is 3
● Maximizer goes RIGHT: It is now the minimizers turn. The minimizer now has a
choice between 2 and 9. He will choose 2 as it is the least among the two values.

Being the maximizer you would choose the larger value that is 3. Hence the optimal
move for the maximizer is to go LEFT and the optimal value is 3.

Now the game tree looks like below :

The above tree shows two possible scores when maximizer makes left and right moves.

Note: Even though there is a value of 9 on the right subtree, the minimizer will never
pick that. We must always assume that our opponent plays optimally.
ALPHA-BETA PRUNING

Alpha-Beta pruning is an optimization technique for the minimax algorithm. It reduces


the computation time by a huge factor. This allows us to search much faster and even
go into deeper levels in the game tree. It cuts off branches in the game tree which need
not be searched because there already exists a better move available. It is called
Alpha-Beta pruning because it passes 2 extra parameters in the minimax function,
namely alpha and beta.

Let’s define the parameters alpha and beta.

Alpha is the best value that the maximizer currently can guarantee at that level or
above.
Beta is the best value that the minimizer currently can guarantee at that level or
below.

Let’s make the above algorithm clear with an example.

● The initial call starts from A. The value of alpha here is -INFINITY and the value
of beta is +INFINITY. These values are passed down to subsequent nodes in the
tree. At A the maximizer must choose max of B and C, so A calls B first
● At B it the minimizer must choose min of D and E and hence calls D first.
● At D, it looks at its left child which is a leaf node. This node returns a value of 3.
Now the value of alpha at D is max( -INF, 3) which is 3.
● To decide whether its worth looking at its right node or not, it checks the
condition beta<=alpha. This is false since beta = +INF and alpha = 3. So it
continues the search.
● D now looks at its right child which returns a value of 5.At D, alpha = max(3, 5)
which is 5. Now the value of node D is 5
● D returns a value of 5 to B. At B, beta = min( +INF, 5) which is 5. The minimizer
is now guaranteed a value of 5 or lesser. B now calls E to see if he can get a lower
value than 5.
● At E the values of alpha and beta is not -INF and +INF but instead -INF and 5
respectively, because the value of beta was changed at B and that is
what B passed down to E
● Now E looks at its left child which is 6. At E, alpha = max(-INF, 6) which is 6. Here
the condition becomes true. beta is 5 and alpha is 6. So beta<=alpha is true.
Hence it breaks and E returns 6 to B
● Note how it did not matter what the value of E‘s right child is. It could have been
+INF or -INF, it still wouldn’t matter, We never even had to look at it because
the minimizer was guaranteed a value of 5 or lesser. So as soon as the maximizer
saw the 6 he knew the minimizer would never come this way because he can
get a 5 on the left side of B. This way we didn’t have to look at that 9 and hence
saved computation time.
● E returns a value of 6 to B. At B, beta = min( 5, 6) which is 5.The value of node B is
also 5

So far this is how our game tree looks. The 9 is crossed out because it was never
computed.
● B returns 5 to A. At A, alpha = max( -INF, 5) which is 5. Now the maximizer is
guaranteed a value of 5 or greater. A now calls C to see if it can get a higher value
than 5.
● At C, alpha = 5 and beta = +INF. C calls F
● At F, alpha = 5 and beta = +INF. F looks at its left child which is a 1. alpha = max(
5, 1) which is still 5.
● F looks at its right child which is a 2. Hence the best value of this node is 2. Alpha
still remains 5
● F returns a value of 2 to C. At C, beta = min( +INF, 2). The condition beta <= alpha
becomes true as beta = 2 and alpha = 5. So it breaks and it does not even have
to compute the entire sub-tree of G.
● The intuition behind this break-off is that, at C the minimizer was guaranteed a
value of 2 or lesser. But the maximizer was already guaranteed a value of 5 if he
choose B. So why would the maximizer ever choose C and get a value less than
2 ? Again you can see that it did not matter what those last 2 values were. We
also saved a lot of computation by skipping a whole sub-tree.
● C now returns a value of 2 to A. Therefore the best value at A is max( 5, 2) which
is a 5.
● Hence the optimal value that the maximizer can get is 5

This is how our final game tree looks like. As you can see G has been crossed out as it
was never computed.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy