min max algorithm

PHOTO EMBED

Tue Jan 16 2024 19:12:32 GMT+0000 (Coordinated Universal Time)

Saved by @nistha_jnn

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.
Mini-Max algorithm uses recursion to search through the game-tree.
Min-Max algorithm is mostly used for game playing in AI. Such as Chess, Checkers, tic-tac-toe, go, and various tow-players game. This Algorithm computes the minimax decision for the current state.
In this algorithm two players play the game, one is called MAX and other is called MIN.
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.

Min-Max algorithm : 
Step 1: Set FINAL_VALUE to be minimum as possible. 
Step 2 : If limit of search has been reached, then FINAL_VALUE = 
GOOD_VALUE of the current position. 
Step 3: Else do. 
Step 3.1 : Generate the successors of the position. 
Step 3.2: Recursively call MIN-MAX again with the present position with 
depth incremented by unity. 
Step 4: Evaluate the GOOD_VALUE. 
Step 5 : If GOOD_VALUE > FINAL_VALUE then FINAL_VALUE = GOOD_VALUE.

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

https://media.geeksforgeeks.org/wp-content/uploads/minmax.png

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