MIniMax Algorithm
MIniMax Algorithm
MIniMax Algorithm
Slide 2
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.
Both the players fight it as the opponent player gets the minimum benefit while they get
the maximum benefit.
Both Players of the game are opponent of each other, where MAX will select the
maximized value and MIN will select the minimized value.
The minimax algorithm performs a depth-first search algorithm for the exploration of the
complete game tree.
The minimax algorithm proceeds all the way down to the terminal node of the tree, then
backtrack the tree as the recursion.
minimax Algorithm
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.
Slide 6
Step 4: 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.
Slide 7
Properties of Mini-Max algorithm:
•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.
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.
Pseudo-code for MinMax Algorithm
1.function minimax(node, depth, maximizingPlayer) is
2.if depth ==0 or node is a terminal node then
3.return static evaluation of node
4.
5.if MaximizingPlayer then // for Maximizer Player
6.maxEva= -infinity
7. for each child of node do
8. eva= minimax(child, depth-1, false)
9.maxEva= max(maxEva,eva) //gives Maximum of the values
10.return maxEva
11.
12.else // for Minimizer player
13. minEva= +infinity
14. for each child of node do
15. eva= minimax(child, depth-1, true)
16. minEva= min(minEva, eva) //gives minimum of the valu
es
17. return minEva