Back to Adversarial Search

Minimax Algorithm Walkthrough

Complete Step-by-Step Implementation

From terminal nodes to optimal decisions
Phase 1: Setting Up the Game Tree

We'll build a simple tic-tac-toe game tree to demonstrate the Minimax algorithm.

1
Welcome to Minimax Algorithm
Let's walk through the complete Minimax algorithm using a real tic-tac-toe example.
Game Tree
MINIMAX-DECISION Function
function MINIMAX-DECISION(state)
  // Find best action for MAX player
  return arg max[a in Actions(state)] Min-Value(Result(state,a))
MAX-VALUE & MIN-VALUE Functions
function MAX-VALUE(state)
  if TERMINAL-TEST(state) then return UTILITY(state)
  v ← -∞
  for a in ACTIONS(state) do
    v ← MAX(v, MIN-VALUE(Result(state,a)))
  return v

function MIN-VALUE(state)
  if TERMINAL-TEST(state) then return UTILITY(state)
  v ← +∞
  for a in ACTIONS(state) do
    v ← MIN(v, MAX-VALUE(Result(state,a)))
  return v