diff options
| author | Scott Gasch <[email protected]> | 2026-10-15 11:12:37 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2026-10-15 11:12:37 -0700 |
| commit | ef2c2f667c4fc2c0303f56ea487183916f82fb67 (patch) | |
| tree | d781a71ea958ca421521b21c93eb9c2ce59df65c /src/board.c | |
| parent | d9419c104e9fe193649931cee167b819044c6ca3 (diff) | |
Fix several latent search/move-generation bugs found via NNUE annotation tooling
- probe.c: EGTB win/loss scores now render as +-MATE100 (literal +-NMATE)
instead of a misleading float, matching how a real forced mate prints.
- hash.c: fix a sign error in StoreExactScore's loss-side hash bound
(iValue +NMATE paired with HASH_FLAG_UPPER, should be -NMATE) -- dormant
until the probe.c fix made it reachable every EGTB loss.
- san.c: a checking castle move (O-O+/O-O-O+) printed as +-O/+-O-O --
the check-suffix pointer was captured before strcpy filled the
buffer, so '+' overwrote the leading 'O' instead of appending.
- search.c/searchsup.c: MATEMOVE/DRAWMOVE/RECOGNMOVE/EGTBMOVE now record
into the PV unconditionally instead of only when the ambient alpha-beta
window happens to strictly contain the score -- these are exact,
game-theoretic results, not heuristic bounds, so a PVS scout-window
tie (common once a line's value is already known) shouldn't suppress
them. This is why <#>/<=>/<REC>/<EGTB> almost never showed up in a
printed PV.
- util.c: WalkPV now reconstructs a still-missing final move/sentinel
directly from the board when the recorded PV runs out one ply short
of (or exactly at) a forced mate/stalemate/draw, instead of leaving
the printed PV silently truncated.
- gamelist.c/board.c/testsup.c: SetRootPosition now parses into a local
staging POSITION and validates IsBoardLegal + VerifyPositionConsistency
(both moved/enabled for all build profiles, not just TEST/EVAL_DUMP)
before committing to g_RootPosition. Previously a rejected setboard
(e.g. a hand-built FEN leaving the side not on move in check) still
left the partially-parsed, illegal position in g_RootPosition for the
next `go` to search -- GetRootPosition() hands out a stable pointer
straight to it with no defensive copy -- causing a crash instead of
the clean "Error (malformed FEN)" rejection already printed.
All verified via precommit_check.sh (TEST=1 self-test suite + DEBUG
smoke test) in addition to targeted manual repros for each bug.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Diffstat (limited to 'src/board.c')
| -rw-r--r-- | src/board.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/board.c b/src/board.c index 2f2820a..0f3db09 100644 --- a/src/board.c +++ b/src/board.c @@ -134,6 +134,68 @@ Return value: FLAG +IsBoardLegal(POSITION *pos) +/** + +Routine description: + + True if *pos describes a position reachable through legal chess + play: no pawns on rank 1/8, and the side NOT on move isn't in + check (that can only happen if whoever moved last left their own + king in check -- illegal, and never reachable through real play). + Moved here (2026-10-15, was testsup.c) from test-only status: + gamelist.c's SetRootPosition needs this on every build profile, + since testsup.c only linked under TEST/EVAL_DUMP. + +Parameters: + + POSITION *pos + +Return value: + + FLAG + +**/ +{ + COOR c; + + for (c = A1; c <= H1; c++) + { + if (!IS_EMPTY(pos->rgSquare[c].pPiece)) + { + if (IS_PAWN(pos->rgSquare[c].pPiece)) + { + return(FALSE); + } + } + } + + for (c = A8; c <= H8; c++) + { + if (!IS_EMPTY(pos->rgSquare[c].pPiece)) + { + if (IS_PAWN(pos->rgSquare[c].pPiece)) + { + return(FALSE); + } + } + } + + if (InCheck(pos, WHITE) && + InCheck(pos, BLACK)) + { + return(FALSE); + } + + if (InCheck(pos, FLIP(pos->uToMove))) + { + return(FALSE); + } + return(TRUE); +} + + +FLAG VerifyPositionConsistency(POSITION *pos, FLAG fContinue) /** |
