diff options
| author | Scott Gasch <[email protected]> | 2026-09-05 21:52:40 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2026-09-05 21:52:40 -0700 |
| commit | 9e995e7c39a83ae9b5ba86f3346e0281744bf773 (patch) | |
| tree | 27b4587287b0259fba2811084aba1f60c9e1e6bb /src/command.c | |
| parent | 53694883d63674a97a3960514dd4e0a4e1b67f01 (diff) | |
King-safety recalibration, lazy-eval material floor, eval hot-path trimming
Recalibrate iKingSwingP90 against the bitboard-rewritten
CountKingSafetyDefects (~1.28B samples via new CALIBRATE_POSITIONAL/
CALIBRATE_BASE_MARGIN/CALIBRATE_MARGIN_SAFETY diagnostic build flags,
board_representation/EVAL.md section 9). Add LAZY_EVAL_MIN_MATERIAL:
measured the regular lazy exit's real swing exceeding its own assumed
margin 20.6% of the time in near-bare-king endgames (vs <=0.36%
elsewhere) -- skip lazy eval entirely below that material floor.
Double the stale search.c/searchsup.c CountKingSafetyDefects extension
thresholds as a stopgap pending their own recalibration.
Eval hot-path trimming (measured via EVAL_TIME, ~1759 -> ~1386 avg
cycles/eval on a representative middlegame position):
- Pull _GetFileStormDefects out of EstimatePositionalScore's hot path
(cost more than the "cheap cached lookup" it was assumed to be,
running on ~90% of all Eval() calls).
- Add pos->bbOccupiedSide[2], incrementally maintained alongside
bbOccupied, so _BuildFriendlySideBB is a field read instead of a
6-term OR.
- Switch CoorFromBitBoardRank8ToRank1/Rank1ToRank8 to the existing
static-inline FastFirstBit/FastLastBit (same bsf/bsr instruction,
no call/ret overhead).
- Defer EvalPasserRaces' uRacerDist/fDontCountMeOut past its
no-passer early return.
- Remove the mailbox-era "max mobility in a row" term from
_EvalBishop/_EvalRook (no bitboard-mobility equivalent need for it).
- Simplify _EvalBishopPairs and rook file-openness/passer bonuses to
flat DNA-tunable constants instead of distance/pawn-count-scaled
tables, rook file-openness now a branchless bitboard-indexed lookup.
- Remove pos->cPiece (write-only, no reader anywhere).
- Collapse WHITE/BLACK mirror-branches (castle-rights block,
rook-trapped-in-corner) to color-indexed constants.
- Close the PAWN_BIT..KING_BIT gap (bits 7-3 -> bits 4-0), removing
the bvPattern >>= 3 before its KING_COUNTER_BY_ATTACK_PATTERN
lookup. This also fixes a real bug introduced earlier this session
when _WhoControlsSquareFast was converted to read these constants
directly: g_SwapTable is only [32][32], but the old bit values
(up to 0xF8) indexed far out of bounds on any attacked square --
data.c's InitializeSwapTable was always built assuming the bits
0-4 range this change now actually produces.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XxmVi2sTMwpPp4i6WYFjan
Diffstat (limited to 'src/command.c')
| -rwxr-xr-x | src/command.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/command.c b/src/command.c index a51bb33..cf8f939 100755 --- a/src/command.c +++ b/src/command.c @@ -753,6 +753,74 @@ Return value: } +COMMAND(CalibrateCommand) +/** + +Routine description: + + This function implements the 'calibrate' engine command, only + available in a CALIBRATE_POSITIONAL build (board_representation/ + EVAL.md section 9's king-safety recalibration). + + Usage: + + calibrate dump + + Prints a fresh iKingSwingP90[]-shaped table (p90 of the real + KING_SAFETY_BY_COUNTER magnitude observed at each cheap + defect-index bucket) built from every full-eval sample seen so + far this run. Run a representative workload first (the curated + suites or an ecm.ep_ slice, at real search depth via `sd`/ + `script`) so the histogram reflects positions the search tree + actually evaluates, not just root positions. + +Parameters: + + The COMMAND macro hides four arguments from the input parser: + + CHAR *szInput : the full line of input + ULONG argc : number of argument chunks + CHAR *argv[] : array of ptrs to each argument chunk + POSITION *pos : a POSITION pointer to operate on + +Return value: + + void + +**/ +{ + if (argc >= 2 && !STRCMPI(argv[1], "basemargin")) + { +#ifdef CALIBRATE_BASE_MARGIN + DumpBaseMarginCalibration(); +#else + Trace("This binary was not built with CALIBRATE_BASE_MARGIN.\n"); +#endif + return; + } + if (argc >= 2 && !STRCMPI(argv[1], "marginsafety")) + { +#ifdef CALIBRATE_MARGIN_SAFETY + DumpMarginSafetyCalibration(); +#else + Trace("This binary was not built with CALIBRATE_MARGIN_SAFETY.\n"); +#endif + return; + } +#ifdef CALIBRATE_POSITIONAL + if ((argc < 2) || STRCMPI(argv[1], "dump")) + { + Trace("Usage: calibrate dump | calibrate basemargin | " + "calibrate marginsafety\n"); + return; + } + DumpPositionalCalibration(); +#else + Trace("This binary was not built with CALIBRATE_POSITIONAL.\n"); +#endif +} + + COMMAND(ExitCommand) /** @@ -2352,6 +2420,12 @@ COMMAND_PARSER_ENTRY g_ParserTable[] = FALSE, FALSE, "Offer the engine a draw" }, + { "calibrate", + CalibrateCommand, + FALSE, + FALSE, + FALSE, + "Dump the CALIBRATE_POSITIONAL king-safety histogram (calibrate dump)" }, { "edit", EditCommand, FALSE, |
