io-chess
UCI chess engine
Loading...
Searching...
No Matches
Evaluation

The evaluation subsystem assigns a numerical score to any chess position, estimating how favourable it is for the side to move. This score guides the search algorithm: a higher score means the position is better for the side to move.

Neural Evaluation — Factorized MoE

The primary evaluator is a Factorized Mixture-of-Experts (MoE) network that has been trained on hundreds of millions of positions and compiled to native C++ with SIMD-optimised inference. No external ML runtime (ONNX, TensorFlow, etc.) is required.

Architecture

The network consists of three main components:

  • 1×1 Mixer: Computes dense feature embeddings from the raw input planes (piece placements, Chebyshev distances, pawn structures) using pointwise convolutions. The mixer output feeds both the router and the expert bodies.
  • Router (Gating Network): A lightweight classification head that examines the mixer features and selects the top-2 experts (out of 4) for the current position. The router outputs a softmax distribution over experts, and only the top-2 are activated — keeping inference cost constant regardless of how many experts exist.
  • Expert Bodies: Four specialised 3×3 convolutional sub-networks, each trained to excel at a different class of positions:
Expert Specialisation Typical positions
Expert 0 Tactical Checks, captures, pins, forks
Expert 1 Strategical Pawn structure, piece activity, space
Expert 2 Major-piece endgame Rook endings, queen endings
Expert 3 Minor-piece endgame Bishop/knight endings, opposite-colour bishops
Factorized MoE Neural Network Architecture

Incremental Updates (Double-Accumulator)

Rather than recomputing all feature planes from scratch on every ply of the search tree, the engine maintains a double-accumulator that tracks incremental feature deltas as pieces move. When a move is made:

  1. The affected input planes are updated (piece added/removed).
  2. The mixer output is updated incrementally.
  3. Only the activated experts run their 3×3 convolutions.

This makes evaluation extremely fast inside the search tree — typically under 1 μs per position on modern hardware.

See also
EvalContextMoECache, MoERouting

Heuristic Fallback

When no neural network weights are loaded, the engine falls back to a classical evaluation implemented in SimpleEvalContext. This evaluator uses:

  • Material counting: Standard piece values (pawn=100, knight=320, etc.)
  • Piece-square tables: Phase-dependent positional bonuses for each piece on each square (e.g. centralised knights are worth more).
  • King safety terms: Penalty for exposed kings, bonus for castled king positions.

While far weaker than the neural evaluation, the heuristic fallback allows the engine to play reasonable chess without any external data files.

See also
SimpleEvalContext, Evaluator, IEvaluator

Win-Draw-Loss Conversion

Internal centipawn scores are converted to Win/Draw/Loss (WDL) probabilities using a logistic model fitted to self-play data. This enables the engine to report UCI wdl statistics and allows the search to make draw-aware decisions (e.g. avoiding drawn endgames when ahead).

See also
WDLConverter