Two Parts: Search And Evaluation
A chess engine is two programs working together. The search looks ahead: “if I play this, they can answer that, then I play this…”. The evaluation looks at a single position, without moving anything, and gives it one number: who is better, and by how much.
The two need each other. The deeper the search, the less a weak evaluation matters; the better the evaluation, the less depth is needed. Since the evaluation runs at every end of every line — hundreds of thousands of times a second — it has to be both good and very fast.
The Search
The engine thinks one level deeper at a time (iterative deepening), so it always has a move ready when the clock runs out. Looking at every move to every depth would take forever, so most of the work goes into not looking at moves that cannot matter:
- Alpha-beta. Once one reply refutes a move, the engine stops examining that move. With good move ordering this skips most of the tree without changing the result.
- Best moves first. The move that was best the last time this position was seen, captures of valuable pieces, and quiet moves that worked in similar positions (killer moves and a history table) are tried first.
- Memory. A transposition table remembers positions already searched, because the same position is often reached by different move orders.
- Educated shortcuts. Unpromising late moves are searched less deeply (late move reductions); a position so good that even passing a move would keep the advantage is cut short (null move pruning); checks are searched one move deeper.
- Quiet positions only. The search never stops in the middle of an exchange: at the end of every line it keeps following captures until the position settles (quiescence search), so the evaluation never sees a queen just about to be taken back.
- Several cores. The engine can search with several threads at once, all sharing one transposition table (Lazy SMP).
The Board
Inside the engine the board is a set of 64-bit numbers, one bit per square (bitboards): one number for the white knights, one for the black rooks, and so on. Moves and attacks become a few bit operations, and sliding pieces look up their attacks in precomputed tables (magic bitboards). The compound pieces of the variant — the Maharajah, the Archbishop and the Chancellor — move as the union of their components, so they reuse the same tables.
Judging A Position By Hand
The engine’s original evaluation is a list of chess rules of thumb, each with a weight: material, where each piece stands, how many squares it controls, passed and isolated pawns, the bishop pair, rooks on open files, the pawn shield in front of the king. The weights shift gradually from the opening to the endgame.
It works, and it plays the app today, but it only knows what someone thought to write down. Everything else is invisible to it.
The Neural Network
The neural network replaces only the evaluation. The search stays exactly as it is — the network does not choose moves, it answers one question, many times a second: how good is this position?
- The input is the board itself. There are 18 kinds of pieces — pawn, knight, bishop, rook, queen, king and the three compound pieces, in two colours — and 64 squares: 18 × 64 = 1152 yes-or-no questions such as “is there a white knight on f3?”. In a normal position about 32 of them are “yes”. The compound pieces are inputs of their own, not a mix of other pieces, so the network learns what a Maharajah is worth on its own terms.
- Both points of view. The board goes in twice: as the side to move sees it, and mirrored, as the opponent sees it. The network never has to learn chess twice, once for White and once for Black.
- The neurons are not programmed. No one tells a neuron what to look for. During training they turn into detectors of their own — something like “a king without pawn cover” or “a rook that has reached the seventh rank”.
Why It Is Fast
The network’s name, NNUE, stands for Efficiently Updatable Neural Network. The first layer is a table with one column of numbers per input, and the neurons are simply the sum of the columns of the inputs that are “yes”. A move changes only two to four inputs, so the sum is never recomputed — it is updated:
Everything is computed in small integers, many at a time with the processor’s vector instructions. In our measurements, the engine with the network reaches the same search depth about twice as fast as with the hand-written evaluation (0.95 against 2.0 seconds on our benchmark positions, one core of our test machine).
How It Learns
Every training example is a position with two labels: the score a search a few moves deep gave it, and how the game finally ended. The network learns to guess both at a glance. That is the whole trick: when the search asks the network about a position, the answer already carries what a deeper look would have found, as if the search had gone further for free.
The engine learns only from its own games, compound pieces and custom armies included — no other engine’s analysis goes into it. A new network is kept only if it beats the previous one in a match of hundreds of games. So far each round has been clearly stronger than the last:
| Network | Training positions | Result in self-play |
|---|---|---|
| First | 3 million | +44 Elo over the hand-written evaluation |
| Second | 10 million | +168 Elo over the first |
| Third | 30 million | +157 Elo over the second |
| Fourth | 68 million | +102 Elo over the third |
These figures come from games in classic openings between versions of our own engine, 600 games per match. Self-play tends to exaggerate gains; the measurement against an outside engine is on the engine strength page.
Where It Stands
- The fourth network is built into the engine. Against Fairy-Stockfish set to a strength of 2500 it scores 55%, about 2535 on that scale; the hand-written evaluation reaches about 2210 in the same test.
- The network knows the variant less well than classic chess. Every custom army it trained on came from our generator, not from a player, so those starting positions are somewhat artificial. Which armies real players would build, we do not know yet. The variant is also simply harder to play: more kinds of pieces, and a new starting position in almost every game.
- Players’ games are not collected yet. The plan is for the server to keep the games in which a player chose level 5 and beat the engine with a custom army. That is not possible yet. A network needs tens of millions of training positions — the fourth one learned from 68 million — and players have not yet played anywhere near enough variant games to provide them.