Files
Rigby/src/eval.h
T
rektdieandclaude 15258f952a feat: policy network inference
src/policy.cpp runs the network train/policy writes: 3072 threat
inputs (side to move's view, flipped horizontally when its king is on
files e-h, +768 attacked, +1536 defended), a hidden layer with CReLU
and pairwise product, and one output row per move, i8 weights scaled
by 128. The hidden width is read from the file's size, so any trained
width loads. When a network is loaded, eval::policy uses its logits
plus the butterfly-history bias instead of the move heuristics; the
temperature and softmax are unchanged.

A network is built in with make POLICYFILE=<net> (default: none, so
the engine plays as before) or loaded at runtime with the UCI option
PolicyFile. policyfens prints the priors of the trainer's --check
positions.

Checked: with a smoke-trained network policyfens matches the trainer's
float output to a few tenths of a percent in all six positions (black
to move, mirrored king, castling, promotion). Speed with a network:
-13% nps at 512 hidden, -41% at 2048. A zero network built in with
POLICYFILE gives uniform priors. Without a network the bench is
unchanged.

Bench: 529903

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 21:27:38 +01:00

36 lines
1.3 KiB
C++

#pragma once
#include "position.h"
namespace rigby::eval {
// Value: the network trained on Lc0 data, behind a capture-only quiescence
// search. Policy: the policy network when one is loaded (see policy.h),
// otherwise move heuristics.
void init();
// Static evaluation (the value network) in centipawns, side to move's view.
int static_eval(const Position& pos);
// Static exchange evaluation: true when the exchange `m` starts on its target
// square gains at least `threshold` centipawns for the side to move (pins ignored).
bool see_ge(const Position& pos, Move m, int threshold);
// Capture-only search on top of the static evaluation, side to move's view.
int quiescence(const Position& pos, int alpha, int beta, int ply);
// Expected score in [-1, 1] for the side to move.
float value(const Position& pos);
// Writes softmax-normalised priors for `moves` into `out`. `bias`, when not
// null, is added to each move's logit before the softmax (and the temperature).
void policy(const Position& pos, const MoveList& moves, float temperature, const float* bias, float* out);
// Conversion between centipawns and Q in [-1, 1]. One scale for both directions,
// so reported scores match what the search actually optimises.
float cp_to_q(int cp);
int q_to_cp(float q);
} // namespace rigby::eval