Spot the error in how minimax backs up values at each node.
Codejavascript
function minimax(node, isMax) {
if (node.isLeaf) return node.value;
if (isMax) {
let best = -Infinity;
for (const child of node.children)
best = Math.max(best, minimax(child, true));
return best;
} else {
let best = Infinity;
for (const child of node.children)
best = Math.min(best, minimax(child, false));
return best;
}
}