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 <noreply@anthropic.com>
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 {