0% found this document useful (0 votes)
7 views12 pages

7 Lecture7 AI

The document discusses informed search techniques in artificial intelligence, focusing on the A* algorithm and adversarial search methods like the MiniMax algorithm. A* is a pathfinding algorithm that combines heuristic and cost functions to find the shortest path efficiently, while adversarial search involves multiple agents competing in a search space, exemplified by games. The MiniMax algorithm is highlighted as a decision-making tool for two-player games, optimizing moves for both players under the assumption of optimal play.

Uploaded by

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

7 Lecture7 AI

The document discusses informed search techniques in artificial intelligence, focusing on the A* algorithm and adversarial search methods like the MiniMax algorithm. A* is a pathfinding algorithm that combines heuristic and cost functions to find the shortest path efficiently, while adversarial search involves multiple agents competing in a search space, exemplified by games. The MiniMax algorithm is highlighted as a decision-making tool for two-player games, optimizing moves for both players under the assumption of optimal play.

Uploaded by

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

ARTIFICIAL INTELLIGENCE

LECTURE 7

INFORMED SEARCH TECHNIQUES

(A* Algorithm, Adversarial Search, MiniMax Algorithm)

A*Algorithm

A* Algorithm is one of the best and popular techniques used for path finding and graph
traversals. A lot of games and web-based maps use this algorithm for finding the shortest path
efficiently. It is essentially a best first search algorithm.

A* uses heuristic function h(n), and cost to reach the node n from the start state g(n). A* search
algorithm finds the shortest path through the search space using the heuristic function. This
search algorithm expands less search tree and provides optimal result faster.

In A* search algorithm, we use search heuristic as well as the cost to reach the node. Hence we
can combine both costs as following,

At each point in the search space, only those node is expanded which have the lowest value of
f(n), and the algorithm terminates when the goal node is found.
Algorithm of A* Search:

- The implementation of A* Algorithm involves maintaining two lists- OPEN and


CLOSED.
- OPEN contains those nodes that have been evaluated by the heuristic function but have
not been expanded into successors yet.
- CLOSED contains those nodes that have already been visited.
The algorithm is as follows-

Step-01:

- Define a list OPEN.


- Initially, OPEN consists solely of a single node, the start node S.

Step-02:

If the list is empty, return failure and exit.

Step-03:

- Remove node n with the smallest value of f(n) from OPEN and move it to list CLOSED.
- If node n is a goal state, return success and exit.

Step-04:

Expand node n.

Step-05:

- If any successor to n is the goal node, return success and the solution by tracing the path
from goal node to S.
- Otherwise, go to Step-06.

Step-06:

- For each successor node,


 Apply the evaluation function f to the node.
 If the node has not been in either list, add it to OPEN.

Step-07:

Go back to Step-02.
Example 1:

- The numbers written on edges represent the distance between the nodes.
- The numbers written on nodes represent the heuristic value.
- Find the most cost-effective path to reach from start state A to final state J using A*
Algorithm.

Step-01:
 We start with node A.
 Node B and Node F can be reached from node A.
A* Algorithm calculates f(B) and f(F).
 f(B) = 6 + 8 = 14
 f(F) = 3 + 6 = 9
Since f(F) < f(B), so it decides to go to node F.
Path- A → F
Step-02:
Node G and Node H can be reached from node F.
A* Algorithm calculates f(G) and f(H).
 f(G) = (3+1) + 5 = 9
 f(H) = (3+7) + 3 = 13
Since f(G) < f(H), so it decides to go to node G.
Path- A → F → G
Step-03:
Node I can be reached from node G.
A* Algorithm calculates f(I).
f(I) = (3+1+3) + 1 = 8
It decides to go to node I.
Path- A → F → G → I
Step-04:
Node E, Node H and Node J can be reached from node I.
A* Algorithm calculates f(E), f(H) and f(J).
 f(E) = (3+1+3+5) + 3 = 15
 f(H) = (3+1+3+2) + 3 = 12
 f(J) = (3+1+3+3) + 0 = 10
Since f(J) is least, so it decides to go to node J.
Path- A → F → G → I → J

Example 2:
Given an initial state of an 8-puzzle problem and final state to be reached-

- Find the most cost-effective path to reach the final state from initial state using A*
Algorithm.
- Consider g(n) = Depth of node and h(n) = Number of misplaced tiles.
Important Note:
It is important to note that-
 A* Algorithm is one of the best path finding algorithms.
 But it does not produce the shortest path always.
 This is because it heavily depends on heuristics (A* Admissible, overestimation &
underestimation)
ADVERSARIAL SEARCH
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 modeled as a Search problem and heuristic evaluation function, and these are
the two main factors which help to model and solve games in AI.
Types of Games in AI:

Deterministic Non-Deterministic

Perfect information Chess, Checkers, Backgammon, monopoly

Imperfect information Nim, tic-tac-toe Bridge, poker, nuclear war

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, Nim 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: Monopoly, Poker etc.
Note: In AI, “games” have special format: deterministic, turn-taking, 2- player, zero-sum games
of perfect information.
Zero-Sum Games
o Zero-sum games are adversarial search which involves pure competition.
o In Zero-sum game, each agent's gain or loss of utility is exactly balanced by the losses or
gains of utility of another agent. In it, one person’s gain is equivalent to another’s loss, so
the net change in wealth or benefit is zero.
o Chess and tic-tac-toe are examples of a Zero-sum game.
Formalization of the problem:
A game can be defined as a type of search in AI which can be formalized of the following
elements:
o Initial state: It specifies how the game is set up at the start.
o Player(s): It specifies which player has moved in the state space.
o Action(s): It returns the set of legal moves in state space.
o Result(s, a): It is the transition model, which specifies the result of moves in the state
space.
o Terminal-Test(s): Terminal test is true if the game is over, else it is false at any case.
The state where the game ends is called terminal states.
o Utility(s, p): A utility function gives the final numeric value for a game that ends in
terminal states s for player p. It is also called payoff function. For tic-tac-toe, utility
values are +1, -1, and 0.
Types of Algorithms in Adversarial Search
In a normal search, we follow a sequence of actions to reach the goal or to finish the game
optimally. But in an adversarial search, the result depends on the players which will decide the
result of the game.
There are following types of adversarial search:
 Minmax Algorithm
 Alpha-beta Pruning
MiniMax Algorithm
o Mini-max algorithm is a recursive or backtracking algorithm which is used in decision-
making and game theory. It provides an optimal move for the player assuming that
opponent is also playing optimally.
o Min-Max algorithm is mostly used for game playing in AI. Such as Chess, Checkers, tic-
tac-toe, go, and various tow-players game.
o In this algorithm two players play the game, one is called MAX and other is called MIN.
MIN: Decrease the chances of MAX to win the game.
MAX: Increases his chances of winning the game.
o Both the players fight it as the opponent player gets the minimum benefit while they get
the maximum benefit.
o Both Players of the game are opponent of each other, where MAX will select the
maximized value and MIN will select the minimized value.
o The minimax algorithm performs a depth-first search algorithm for the exploration of the
complete game tree.
o The minimax algorithm proceeds all the way down to the terminal node of the tree, then
backtrack the tree as the recursion.
Working of Min-Max Algorithm:
o In the example, there are two players one is called Maximizer and other is called
Minimizer.
o Maximizer will try to get the Maximum possible score, and Minimizer will try to get the
minimum possible score.
o This algorithm applies DFS, so in this game-tree, we have to go all the way through the
leaves to reach the terminal nodes.
o At the terminal node, the terminal values are given so we will compare those value and
backtrack the tree until the initial state occurs. Following are the main steps involved in
solving the two-player game tree:
Step-1: In the first step, the algorithm generates the entire game-tree and apply the utility
function to get the utility values for the terminal states. In the below tree diagram, let's take A
is the initial state of the tree. Suppose maximizer takes first turn which has worst-case initial
value =- infinity, and minimizer will take next turn which has worst-case initial value =
+infinity.
Step 2: Now, first we find the utilities value for the Maximizer, its initial value is -∞, so we will
compare each value in terminal state with initial value of Maximizer and determines the higher
nodes values. It will find the maximum among the all.
o For node D max(-1,- -∞) => max(-1,4)= 4
o For Node E max(2, -∞) => max(2, 6)= 6
o For Node F max(-3, -∞) => max(-3,-5) = -3
o For node G max(0, -∞) = max(0, 7) = 7

Step 3: In the next step, it's a turn for minimizer, so it will compare all nodes value with +∞, and
will find the 3rd layer node values.
o For node B= min(4,6) = 4
o For node C= min (-3, 7) = -3

Step 3: Now it's a turn for Maximizer, and it will again choose the maximum of all nodes value
and find the maximum value for the root node. In this game tree, there are only 4 layers, hence
we reach immediately to the root node, but in real games, there will be more than 4 layers.
o For node A max(4, -3)= 4

That was the complete workflow of the minimax two player game.
Minimax in tic-tac-toe

Pseudo-code for MinMax Algorithm:


function minimax(node, depth, maximizingPlayer) is
if depth ==0 or node is a terminal node then
return static evaluation of node

if MaximizingPlayer then // for Maximizer Player


maxEva= -infinity
for each child of node do
eva= minimax(child, depth-1, false)
maxEva= max(maxEva,eva) //gives Maximum of the values
return maxEva

else // for Minimizer player


minEva= +infinity
for each child of node do
eva= minimax(child, depth-1, true)
minEva= min(minEva, eva) //gives minimum of the values
return minEva

Properties of Mini-Max algorithm:


o Complete- Min-Max algorithm is Complete. It will definitely find a solution (if exist), in
the finite search tree.
o Optimal- Min-Max algorithm is optimal if both opponents are playing optimally.
o Time complexity- As it performs DFS for the game-tree, so the time complexity of Min-
Max algorithm is O(bm), where b is branching factor of the game-tree, and m is the
maximum depth of the tree.
o Space Complexity- Space complexity of Mini-max algorithm is also similar to DFS
which is O(bm).
Limitation of the minimax Algorithm:
The main drawback of the minimax algorithm is that it gets really slow for complex games such
as Chess, go, etc. This type of games has a huge branching factor, and the player has lots of
choices to decide. This limitation of the minimax algorithm can be improved from alpha-beta
pruning.

You might also like