Files
Rigby/src/eval.h
T
rektdieandclaude ed1c2b77f7 feat: SEE pruning of losing captures in quiescence
Profiling showed that 80-85% of a middlegame playout is the quiescence
search behind the value network: 15-41 quiescence nodes per leaf, since
every capture was searched, including ones that just lose the piece.

The quiescence search now skips captures whose static exchange on the
target square loses material (SEE < 0) when not in check. The SEE is the
usual threshold swap (least valuable attacker first, x-rays opened as
pieces leave, a king recaptures only an undefended square, pins
ignored); castling, en passant and promotions count as even.

Effect at 60k playouts (instrumented build, qsearch nodes per leaf and
time per playout):

  startpos           3.7 -> 2.2     -20%
  QGD middlegame    14.7 -> 4.2     -54%
  Kiwipete          41.4 -> 25.5    -25%
  Sicilian middle   21.0 -> 3.4     -68%
  rook endgame       2.6 -> 2.3      -2%

Checked: the SEE matches an independent python-chess reference exactly
on 9957 captures from 3000 random positions (4884 with recaptures).
Bench is deterministic. Move generation is untouched.

Bench: 546966

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 14:43:40 +01:00

34 lines
1.1 KiB
C++

#pragma once
#include "position.h"
namespace rigby::eval {
// Value: the network trained on Lc0 data, behind a capture-only quiescence
// search. Policy: move heuristics until a policy network exists.
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`.
void policy(const Position& pos, const MoveList& moves, float temperature, 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