diff options
| author | Scott Gasch <[email protected]> | 2026-09-05 00:19:59 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2026-09-05 00:19:59 -0700 |
| commit | 2ce3570dc6aa67f82dd6f02fc4e518be3e33aabf (patch) | |
| tree | 111f28a4b9587be62e3252aebc4c64b7d8350f4f /src/chess.h | |
| parent | 5883f5a64f4f464b877b7637b8e13c25f7d208fc (diff) | |
Maintain pos->bbOccupied incrementally, dedupe its two from-scratch builders
chess.h: add POSITION::bbOccupied (full-board occupancy, both colors,
every piece including kings), maintained incrementally alongside
bbPieces/bbPawns rather than rebuilt on demand -- resolves the open
question in EVAL.md section 0 about whether this is worth doing given
both generate.c and the planned eval.c mobility rewrite need it.
move.c: SlidePiece/SlidePawn/LiftPiece/PlacePiece and their
WithoutSigs variants now maintain bbOccupied at the same choke points
that already maintain bbPieces/bbPawns -- unconditionally, since
occupancy doesn't care about piece type or color. Kings only ever
move through SlidePiece/SlidePieceWithoutSigs (never Lift/Place), so
no separate king-specific update site was needed.
fen.c: populate bbOccupied when parsing a FEN.
board.c: VerifyPositionConsistency cross-checks pos->bbOccupied
against a from-scratch rebuild, same pattern already used for
bbPieces/bbPawns.
generate.c/movesup.c/see.c: replace call sites that rebuilt full
occupancy via _BuildFullOccupiedBB/_BuildOccupiedBB with direct reads
of pos->bbOccupied; delete see.c's _BuildOccupiedBB, which was a
byte-for-byte duplicate of generate.c's _BuildFullOccupiedBB (kept
only as the from-scratch ground truth for the new consistency check
and testgenerate.c's benchmark harness).
testsup.c: GenerateRandomLegalPosition builds POSITIONs by poking
rgSquare/bbPieces/bbPawns directly, bypassing both move.c and fen.c --
a third construction path the above missed. It never set bbOccupied,
so the new VerifyPositionConsistency check failed on every generated
position, and since generation retries until a position verifies, the
self-test suite spun forever (100% CPU, no progress) instead of
crashing outright. Fixed by setting bbOccupied at all four placement
sites (both kings, pawn, non-pawn piece). Full self-test suite and
precommit_check.sh verified clean afterward.
board_representation/EVAL.md: record the bbOccupied decision and
rationale, resolving section 0's open question.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01P6g6iF6mD1Hau6nCZCzwYj
Diffstat (limited to 'src/chess.h')
| -rwxr-xr-x | src/chess.h | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/chess.h b/src/chess.h index f39a956..41c8734 100755 --- a/src/chess.h +++ b/src/chess.h @@ -659,8 +659,8 @@ typedef struct _POSITION // Per-color pawn location bitboard -- same incremental-maintenance // idea as bbPieces above, but for pawns (which bbPieces - // deliberately excludes). Exists so _BuildOccupiedBB (see.c) can - // build full-board occupancy via two ORs instead of looping + // deliberately excludes). Exists so full-board occupancy + // (pos->bbOccupied below) can be built via two ORs instead of looping // cPawns[2][8] (up to 16 iterations) on every call -- see // board_representation/MIGRATION.md section 3. Also the single // source of truth for pawn locations used by pawn eval @@ -671,6 +671,23 @@ typedef struct _POSITION // this field directly instead. BITBOARD bbPawns[2]; + // Full-board occupancy (both colors, every piece including pawns + // and kings) -- same incremental-maintenance idea as bbPieces/ + // bbPawns above, added 2026-09-05 per board_representation/ + // EVAL.md section 0 (was previously only on MOVE_STACK, rebuilt + // on demand via _BuildFullOccupiedBB at many independent call + // sites in generate.c/movesup.c/see.c, and needed again by the + // planned eval.c mobility rewrite -- one incrementally-maintained + // copy here replaces all of that). Maintained by move.c's + // SlidePiece/SlidePawn/LiftPiece/PlacePiece (and their + // WithoutSigs variants) at the same sites that already maintain + // bbPieces/bbPawns, unconditionally (no per-color/per-type branch + // needed, unlike those). _BuildFullOccupiedBB(pos) (generate.c) + // remains as the from-scratch ground truth used to verify this + // field stays in sync (see VerifyPositionConsistency, board.c), + // not as something callers should call directly anymore. + BITBOARD bbOccupied; + ULONG uWhiteSqBishopCount[2]; // num bishops on white squares SCORE iMaterialBalance[2]; // material balance |
