From e79af634b602e55ad9d141a0fa73bd130a4a3264 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Mon, 10 Nov 2025 17:34:09 +0100 Subject: [PATCH] Fix NNUE compatibility check to validate king count (#932) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/position.h | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) 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 { -- 1.7.0.4