100% found this document useful (1 vote)
6 views

Module-2 Lecture 7

The Minimax algorithm is a backtracking algorithm used in two-player games to determine optimal moves while considering that the opponent also plays optimally. It involves creating a game tree with nodes representing possible moves, and uses a utility function to assign values to terminal states. Alpha-Beta pruning is an optimization technique for Minimax that reduces computation time by eliminating branches that do not need to be explored, enhancing efficiency in complex games.

Uploaded by

Balamurali Gunji
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
6 views

Module-2 Lecture 7

The Minimax algorithm is a backtracking algorithm used in two-player games to determine optimal moves while considering that the opponent also plays optimally. It involves creating a game tree with nodes representing possible moves, and uses a utility function to assign values to terminal states. Alpha-Beta pruning is an optimization technique for Minimax that reduces computation time by eliminating branches that do not need to be explored, enhancing efficiency in complex games.

Uploaded by

Balamurali Gunji
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

MODULE-2

LECTURE-7
Minimax
Algorith
m
Introduction
to Minimax Algorithm

•Minimax is a type of backtracking


algorithm. The Minimax algorithm finds an
optimal move to make decisions in game
theory. Minimax algorithm takes into
consideration that the opponent is also
playing optimally, which makes it useful
for two-player games such as checker,
chess, Tic-tac-toe, go and many others.
Terminol
ogyTree: Tree for the game moves, it shows all
Game
the possible moves available to the player at a
particular state. The player makes an optimum
decision and makes a move.
Initial State: The state at which the game starts.

Successor Function: The function is used to


define all the available moves for the player at the
current state.

Terminal State: This is the last state of the game


which decides the winner of the game and the
game gets over. Utility Function: It is the most important function
in this algorithm. It is that a heuristic approach is
used to assign values for each outcome from the
game. The values are assigned based on the rules
of the game. The values assigned come from
terminal leaves if it’s a winning move the high
value will be assigned to that move and if it’s a
MINIMAX ALGORITHM
IMPLEMENTATION
STEP-1
•For node D max(-1,- -∞) => max(-
1,4)= 4
•For Node E max(2, -∞) => max(2,
6)= 6
•For Node F max(-3, -∞) => max(-
3,-5) = -3
What are terminal
•For node G max(0, -∞) = max(0, 7)
nodes
=7
Where the values of the
vertices present in the tree
that are called terminal nodes
STEP-2

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.

•For node B= min(4,6) = 4


•For node C= min (-3, 7) = -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.

•For node A max(4, -


3)= 4

That was the complete workflow of the


minimax two player game.
Properties of Mini-Max algorithm:

•Complete- Min-Max algorithm is Complete. It will definitely find a solution (if exist), in
the finite search tree.
•Optimal- Min-Max algorithm is optimal if both opponents are playing optimally.

•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.

•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 which we have discussed in the next topic.
PRACTISE
EXAMPLES
•L3N1 = -2
•L3N2 = 3
•L3N3 = 1
•L3N4 = 5
•L3N5 = -4
•L3N6 = -6
•L3N7 = 0
•L3N8 = 6
PRACTISE PRACTISE
EXAMPLE-2 EXAMPLE-3
Alpha-Beta Pruning
•Alpha-beta pruning is a modified version of the minimax algorithm. It is an
optimization technique for the minimax algorithm.

Alpha-Beta pruning is not actually a new algorithm, but rather 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.
Working of Alpha-Beta Pruning:

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 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 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.
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(b m/2).
Examples
THANK YOU

You might also like