Visualizations
445 / 500

445 · Games

Alpha-Beta Othello

Othello against alpha-beta search, with its pruned tree unfurling beside the board.

The engine searches the game tree with negamax and alpha-beta pruning: once a reply refutes a move, the remaining replies cannot change the answer and are skipped. Iterative deepening searches depth 1, then 2, and so on, and each pass orders moves for the next using the previous pass's scores, a transposition table of best replies, and a one-step look at how few moves each option leaves the opponent, which is what makes the cutoffs happen early. Positions are scored by square weights that prize corners, mobility, and the disc count near the end. Beside the board, the current iteration's top three plies unfurl as a tree with the principal variation in gold and the snipped branches as grey stubs, while a log-scale chart compares the nodes actually searched with the full minimax tree, typically more than 95 percent pruned. The heatmap shows each candidate move's score, with a less-than sign where alpha-beta only proved an upper bound.

Try it. Click a square (or Play Black or Play White) to take over; on your turn the heatmap is the engine's hint, and H or Space plays it. Choose a depth from 2 to 7 and switch move ordering off to watch the work explode. W watches the AIs again, N starts a new game.

  • Alpha-beta pruning
  • Iterative deepening
  • Move ordering heuristics
  • Zobrist transposition table
  • Generator-based time slicing

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build an Othello game where I play against an alpha-beta search engine, with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Draw a green 8x8 board with the four starting discs. Let me click to place a black disc; a move is legal if it flanks one or more white discs in any of the 8 directions, and those discs flip. If a player has no legal move they pass; when neither can move, the game ends.
- Write an evaluation function: a table of square weights (corners very good, the squares diagonally next to them very bad, edges good), plus a bonus for having more legal moves than the opponent.
- Write negamax with alpha-beta pruning to a fixed depth of 4 and let the computer play white. Make and unmake moves on one board instead of copying it.
- Count the nodes searched and show the number next to the board.

Once that works, make it beautiful:
- Add iterative deepening (depth 1, 2, 3...) and order moves using the previous iteration's scores, best moves first. Compare node counts with ordering on and off.
- Turn the search into a generator function that yields every few hundred nodes, and run a slice of it per animation frame so the page stays smooth at depth 6.
- Shade each legal square by its score while the engine thinks, and draw the top two or three plies of the search tree beside the board, with cut-off branches greyed out.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as a transposition table with Zobrist hashing, flip animations for the discs, or a chart comparing searched nodes with the full minimax tree.
PreviousCosmic Light ConeOur past light cone, horizons and galaxies in the expanding universe, drawn three ways. NextSpacetime TrainA train, a tunnel and a light clock, with a live Minkowski diagram in either frame.

Related visualizations

  • MancalaGames The ancient sowing game on a carved wooden board, played by minimax with alpha-beta.
  • MCTS BloomAlgorithms Four-in-a-row against Monte Carlo Tree Search, its search tree blooming as a flower.
  • Sliding Puzzle SolverGames IDA* with pattern databases solves the 15-puzzle in the fewest possible moves.
  • Rebound RobotsAlgorithms Robots slide until they hit something. A* finds the fewest moves to the target.
  • Bandit CasinoMachine learning Epsilon-greedy, UCB1 and Thompson sampling race to find the best slot machine.
  • Lights Out AlgebraMath The toggle-tile puzzle solved instantly at any size by linear algebra over GF(2).
  • Sokoban ForgeAlgorithms Crate puzzles forged by playing backward from the goals, then solved by A*.
  • Minesweeper OracleAlgorithms Every hidden cell shows its exact mine probability while an AI plays the safest move.
  • Dancing LinksAlgorithms Knuth's Algorithm X tiles boards with wooden pentominoes while its links visibly dance.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs