OneCompiler

minimax_ai

84

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

if maximizingPlayer:
    maxEval = -∞
    for each child of node:
        eval = minimax(child, depth - 1, false)
        maxEval = max(maxEval, eval)
    return maxEval
else:
    minEval = +∞
    for each child of node:
        eval = minimax(child, depth - 1, true)
        minEval = min(minEval, eval)
    return minEval