Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the minmax pseudocode

I'm teaching myself the minimax algorithm and I just had a few questions I was hoping someone could answer.

Firstly on line 05 - what does := mean?

Also on line 08/14 I notice that the method max or min is called with two arguments, what would this method return? Would it return the maximum value or the minimum value found so far? Is there a pseudocode example of this or am I misunderstanding?

01 function minimax(node, depth, maximizingPlayer)
02     if depth = 0 or node is a terminal node
03         return the heuristic value of node

04     if maximizingPlayer
05         bestValue := −∞
06         for each child of node
07             v := minimax(child, depth − 1, FALSE)
08             bestValue := max(bestValue, v)
09         return bestValue

10     else    (* minimizing player *)
11         bestValue := +∞
12         for each child of node
13             v := minimax(child, depth − 1, TRUE)
14             bestValue := min(bestValue, v)
15         return bestValue
like image 835
TheRapture87 Avatar asked Mar 22 '26 04:03

TheRapture87


1 Answers

  • bestValue := −∞: Assign negative infinity (the lowest possible number) to bestValue
  • max(bestValue, v) returns bestValue or v, whichever is bigger
  • min(bestValue, v) returns bestValue or v, whichever is smaller

Since this is pseudocode, we can assume that any language you will use to implement it provides the functions max and min. If not, you can easily implement them yourself.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!