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

+2 -1
View File
@@ -198,7 +198,7 @@ int quiescence(const Position& pos, int alpha, int beta, int ply) {
float value(const Position& pos) { return cp_to_q(quiescence(pos, -MATE, MATE, 0)); }
void policy(const Position& pos, const MoveList& moves, float temperature, float* out) {
void policy(const Position& pos, const MoveList& moves, float temperature, const float* bias, float* out) {
const int us = pos.stm;
const int them = us ^ 1;
const u64 occ = pos.occupancy();
@@ -238,6 +238,7 @@ void policy(const Position& pos, const MoveList& moves, float temperature, float
if (pawn_threats & bb(from)) s += 0.003f * SEE_VALUE[type];
}
if (check_squares[m.is_promotion() ? m.promo_type() : type] & bb(to)) s += 0.5f;
if (bias) s += bias[i];
out[i] = s * inv_temp;
max_logit = std::max(max_logit, out[i]);