Explore Library
Code QuizAdvanced

Expectimax Chance Node Averaging

Spot the mistake in how the chance node combines child values.

Codejavascript
function expectimax(node, isMax) {
  if (node.isLeaf) return node.value;
  if (node.isChance) {
    let total = 0;
    for (const child of node.children)
      total += expectimax(child, isMax);
    return total; // expected value
  }
  const scores = node.children.map(c => expectimax(c, !isMax));
  return isMax ? Math.max(...scores) : Math.min(...scores);
}

What is the bug at the chance node?