Under the Hood

How the Chess AI Works: Negamax, Alpha-Beta and Quiescence

How the Chess AI works: a negamax search with alpha-beta pruning, null-move pruning and a quiescence search, layered under a hand-written positional evaluation — LK Forge's own engine, not Stockfish and not a neural network.

Published September 12, 2026 · LK Forge · search numbers from a re-runnable, seeded benchmark

+321
Elo from the first extra ply of search
4
levels, up to club-strength Expert
~2s
Expert's search budget per move
0
servers — it runs in your browser

The opponent on LK Forge Chess is a real chess engine — the same family of algorithm behind classic chess programs — but it is our own code, not Stockfish and not a neural network, and it runs entirely in your browser with nothing sent to a server. Here is how it turns a position into a move.

Negamax with alpha-beta pruning

On each move the engine generates the fully legal moves — respecting pins, checks and castling rights — and searches them with negamax, the compact single-function form of minimax that works because chess is zero-sum: one side's gain is exactly the other's loss, so a position's score for me is just the negation of its score for you. It plays sequences of moves out for both sides, scores the resulting positions, and picks the move with the best guaranteed outcome.

Alpha-beta pruning keeps that tree manageable: the engine tracks the best score each side can already force and abandons any line that provably cannot beat it. Chess has a much larger branching factor than a game like Connect 4, so pruning — plus move ordering that tries the most promising moves first — is what makes a useful search depth reachable in about a second.

// negamax + alpha-beta; at depth 0 it hands off to quiescence
function negamax(pos, depth, alpha, beta) {
  if (depth === 0) return quiesce(pos, alpha, beta);   // resolve captures first
  let best = -Infinity;
  for (const mv of orderedMoves(pos)) {
    const score = -negamax(make(pos, mv), depth - 1, -beta, -alpha);
    if (score > best) best = score;
    if (best > alpha) alpha = best;
    if (alpha >= beta) break;                    // prune
  }
  return best;
}

Quiescence search: don't stop mid-trade

A fixed-depth search has a dangerous habit: it can stop counting the instant after it grabs a piece and never notice the piece is recaptured next move — the horizon effect. So at the leaves of the main search the engine runs a quiescence search: a short extra search that follows only captures until the position is quiet, so the score reflects the end of the exchange rather than the middle of it. On top of that, null-move pruning lets the engine cheaply prove that many positions are already so good that a full search is unnecessary — it imagines passing the turn, and if the opponent still can't catch up, the branch is cut.

What it actually rewards

The evaluation is classical and hand-written. Beyond raw material it scores king safety, pawn structure, passed pawns, the bishop pair and rooks on open files — the positional signals a club player weighs. But as with every search engine, most of the strength comes from how deep it can look before it has to trust that evaluation.

How much is one more move of lookahead worth?

We measured it across four LK Forge engines by pinning each to a fixed depth and self-playing 120 colour-balanced games between adjacent depths. Chess is the odd one out. In most games the first extra ply dwarfs the rest, but in chess the first two plies are almost equal — +321 then +315 Elo — because the branching factor is so large that even a two-move search still misses a great deal, leaving plenty for the next ply to find.

0 100 200 300 400 +321 +315 +225 depth 1→2 depth 2→3 depth 3→4 Elo gained per extra ply of search depth → lkforge.com

Elo gained by each extra ply of fixed-depth chess search, 120 colour-balanced games per step (Elo = 400·log₁₀(p/(1−p)), draws count half). Full method and the other three engines are in What One Ply of Search Is Worth.

Four levels, one engine. Beginner mixes in deliberate weak moves; Medium searches a few plies; Hard runs the full engine at about a second per move; Expert uses the same engine but thinks about two seconds and is a strong club-level opponent. We do not claim grandmaster strength or perfect play.

That is the whole engine: legal moves, negamax with alpha-beta, quiescence and null-move pruning to search deeper for less, and a positional evaluation to judge the leaves. Want to see the search decide move by move? Read minimax and alpha-beta, step by step, or compare the depth trade-off across four engines in What One Ply of Search Is Worth.

FAQ

Does the chess AI use a neural network or Stockfish?

Neither — this chess AI is LK Forge's own classical engine: negamax search with alpha-beta pruning, null-move pruning, a quiescence search and a hand-written positional evaluation. There is no neural network, no Stockfish and no server: the engine runs entirely in your browser. It was built from scratch for LK Forge.

How strong is the chess AI?

The chess AI has four levels. Beginner plays deliberate weak moves, Medium plays a solid game a few moves deep, Hard runs the full engine at about a second per move, and Expert searches deeper at about two seconds per move and is a strong club-level opponent. We do not claim it plays perfectly or at grandmaster strength.

What is a quiescence search?

A quiescence search is a short extra search, run at the leaves of the main search, that only follows captures until the position is quiet. Without it an engine can stop counting right after grabbing a piece and miss that the piece is immediately recaptured — the 'horizon effect'. Quiescence search prevents that by resolving the exchanges before it trusts the score.

Why does one more move of lookahead matter?

In a seeded self-play benchmark of four LK Forge engines, the first extra ply of chess search was worth +321 Elo. Unusually, the second ply was almost as valuable at +315, because chess has such a large branching factor that even a two-move search still misses a great deal, leaving plenty for the next ply to find. That is why even Medium, which searches only a few plies, already plays noticeably better than Beginner.

Take on the engine — four levels, up to club strength.

Play Chess →