hobbieschess

Position Evaluation

For most of its life, typhoon only had a traditional "hand-crafted eval" (HCE) but, as part of my recent renovation work, I've now trained three versions of an incrementally updatable neural net (NNUE) evaluation function. Both of them have the same purpose in the engine: given a POSITION, assign it a score for how "good" it is for the side to move. Then, the search can try to move towards positions that are good for it and try to prevent the opponent from doing the same.

When I first started programming chess, I only ran the evaluation function at leaf nodes because it is expensive; eval is often the most expensive thing that an engine does (not because it is extremely arduous to evaluate one position so much as because the engine is likely to be considering hundreds of thousands or millions of positions every second). But, over time, I observed that having the current evaluation at every tree node, though, is both useful (for pruning decisions, for example) and relatively cheap because, relative to the leaves, there aren't that many interior nodes in the search tree. So I now call Eval() everywhere.

Both the new NNUE eval and the old HCE eval try to save time, though, by being "lazy". They know the current alpha and beta bounds (representing the minimum and maximum score window that is interesting right now) and both pay a lot of attention to the material balance of the board because the side with more/better pieces is usually winning. So, if the current material balance (which is very cheap to compute or maintain incrementally) is way above or below the current interesting score window, they simply return that and don't spend a lot of effort trying to determine the precise score by considering a bunch of positional terms. This is usually called a "lazy eval". I actually have three exits in the main HCE eval: full, lazy and "super lazy". Anyway, all of these ideas speed up search at the cost of accuracy, so they are used conservatively -- only when the score is way too extreme to possibly matter.

In the old HCE, I also hashed pawn structure related scoring terms and king safety related scoring terms to speed up the evaluation code. However, in the new NNUE code, we do not need these ideas anymore.

If you're interested in the old HCE's terms, have a look at eval.c. A rough overview of the features the HCE cares about:

PawnsKingsKnightsBishopsRooksQueen / Misc
Pawn duos
Rammed pawns / closed positions
Backward and backward-exposed pawns
Pawn-supports-pawn structures
Passed pawns, candidate passers
Isolated / doubled pawns
Pawn dispersion
Connected and outside passers
Pawn shield / storm
Unstoppable runners
Center control
Open files/ranks/diagonals nearby
Half-open files nearby
Square control around king
Castling incentives
Supporting passers
Attacking the enemy king
Centralization in the endgame
Enemy king tropism
Early development
Trapped vs. outposted
Blocking a passer/backward pawn
Open file behind
Mobility, centrality, relevance
Stronger in closed positions
Enemy king tropism
Bishop-pair bonus (two wings)
Development, fianchetto
Trapped bishops
Good vs. bad bishops
Mobility
Opposite-colored bishops in endgame
Connected rooks
Half-/full-open files
Attacking passers
Pointing at the enemy king
Mobility (h/v)
Supporting a passer
Trapping the enemy king on the edge
Trapped rooks
Open-file control
Queen: king tropism (both sides), pointing at the enemy king, early development penalty

Misc: material imbalances, stonewalls, edge-of-board mate threats, blocked positions

The new NNUE evaluator is a neural net trained on positions and scores (with search) from millions of games. I've now trained three of these nets.

The first was trained exclusively on stockfish self-play games while v2 and v3 brought in typhoon self-play to the mix -- I figured that I was running thousands to tens of thousands of self-play experiments to gauge the strength of code modifications so I might as well begin to use these games for something productive!

The first time I wired the NNUE eval into the codebase I noticed a couple of things: it was very slow -- much slower than the HCE, and it seemed to play interesting, good chess. The first version of the NNUE was trained on only ~1M games and I did it locally, with just my CPUs to build the network. It still solved more ECM test positions and my old HCE but it also lost in head-to-head games with my old HCE because it was an order of magnitude slower and thus searched a couple of ply less.

The second NNUE was trained on more games and was the first version that could regularly beat the old HCE despite still being slower to evaluate and, thus, still searching shallower trees.

NNUE evals version 1 and 2 used NNUE4 were 256x2-32-32-1 networks and used the HalfKAv2_hm feature encoding. But when I trained v3, I changed the network layout to widen the input layer (which I read was stronger) so it now uses 1024x2-SCReLU-1 architecture. The SCReLU stands for Squared Clipped ReLU (sometimes also called Clipped Squared ReLU). It is a nonlinear activation function applied to the concatenated accumulator vector (1024 x 2 = 2048 values, ordered side-to-move first) right before the final output layer. Mathematically, for each element of the accumulator vector clips to a fixed range 0..ceiling and is then squared. It acts like a standard Clipped ReLU (CReLU), zeroing out negative values and capping large ones—and then squares the result. This is another network strength enhancement feature.

Version 3 of the NNUE eval is trained on about 65 million positions and was an immediate (dramatic) strength improvement over v2. After seeing the NNUEs play chess, I am basically sold that this is the right way to move forward and the old HCE is kinda on "life support" at this point. There are a few things I miss about it, but, for the most part, the NNUE is just way better at assessing the position.

Unfortunately I still develop on a Zen2 generation machine; I have a buddy with a Zen4 where the same NNUE eval runs about 4x faster because of the VNNI AVX2 instruction support. Basically, to evaluate a position, the NNUE neural net needs to do a bunch of multiplication and addition operations. AVX2 is a set of instructions originally meant for multimedia operations supported by newer CPUs (including my Zen2). These instructions are "single instruction multiple data" (SIMD) instructions so that you can multiply a bunch of one byte numbers all at the same time for speed. But the VNNI instruction is a newer opcode in the AVX2 family and is custom made for evaluating neural nets so it speeds up the NNUE execution.

evaluation.html was last updated 2 December 2026 and is Copyright © 2002–2026 by Scott Gasch (scott.gasch@gmail.com).