Skip to content

Instantly share code, notes, and snippets.

@mberberoglu
Created March 31, 2014 13:55
Show Gist options
  • Save mberberoglu/9892765 to your computer and use it in GitHub Desktop.
Save mberberoglu/9892765 to your computer and use it in GitHub Desktop.
function minimax(node, depth, maximizingPlayer)
if depth = 0 or node is a terminal node
return the heuristic value of node
if maximizingPlayer
bestValue := -∞
for each child of node
val := minimax(child, depth - 1, FALSE))
bestValue := max(bestValue, val);
return bestValue
else
bestValue := +∞
for each child of node
val := minimax(child, depth - 1, TRUE))
bestValue := min(bestValue, val);
return bestValue
(* Initial call for maximizing player *)
minimax(origin, depth, TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment