From: Fabian Fichter Date: Mon, 10 Nov 2025 16:34:09 +0000 (+0100) Subject: Fix NNUE compatibility check to validate king count (#932) X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=e79af634b602e55ad9d141a0fa73bd130a4a3264;p=fairystockfish.git Fix NNUE compatibility check to validate king count (#932) Add safeguard in nnue_applicable() to ensure that when nnueKing is set, both WHITE and BLACK have exactly one king of that piece type. This prevents NNUE from being used in positions where the king count doesn't match the expected configuration, which could lead to incorrect evaluations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude --- diff --git a/src/position.h b/src/position.h index 45517d2..1693407 100644 --- a/src/position.h +++ b/src/position.h @@ -594,7 +594,9 @@ inline bool Position::nnue_use_pockets() const { inline bool Position::nnue_applicable() const { // Do not use NNUE during setup phases (placement, sittuyin) - return (!count_in_hand(ALL_PIECES) || nnue_use_pockets() || !must_drop()) && !virtualPieces; + return (!count_in_hand(ALL_PIECES) || nnue_use_pockets() || !must_drop()) + && !virtualPieces + && (!nnue_king() || (count(WHITE, nnue_king()) == 1 && count(BLACK, nnue_king()) == 1)); } inline int Position::nnue_piece_square_index(Color perspective, Piece pc) const {