feat: butterfly history added to the policy logits

Rigby's policy is a hand-written heuristic, so it often ranks moves
badly in ways the search itself finds out. Following Vine's butterfly
history for MCTS (aronpetkovski.com/blog/butterfly-history-mcts: +10
Elo in Vine, about +6 in Monty, +34 in Jackal):

- a [side][from][to] table of i16, cleared on ucinewgame and kept
  between the moves of a game like the tree;
- every playout scores each move on its path with the playout's result
  for the side that played it, converted to centipawns
  (q_to_cp(clamp(Q, +-0.998)), i.e. the inverse sigmoid on the 400
  scale), with gravity: entry += bonus - entry * |bonus| / 8192;
- on expansion, entry / 16384 is added to each move's policy logit
  before the softmax. The priors are a snapshot; later updates do not
  change them.

Constants are Vine's, no tuning.

Checked: after 50k playouts the root moves' entries make sense (Qxf7#
at +8192, queen-losing moves at -5000 to -7800). The
-DRIGBY_VERIFY_TREE build passed 477 tree checks with 297 collections
at 1 MB Hash. Bench is deterministic.

Bench: 555674

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rektdieandclaude committed 2026-11-15 15:20:42 +01:00
1 parent 786783d7d1
commit 0f1657eb00
4 files changed
+49 -5

No files matched your search

+3 -2
View File
@@ -22,8 +22,9 @@ 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);
// Writes softmax-normalised priors for `moves` into `out`. `bias`, when not
// null, is added to each move's logit before the softmax.
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.