From 6897c7475210798967f62441e0e819bd9e1bfedc Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Fri, 14 Apr 2023 18:57:34 +0200 Subject: [PATCH] Ensure stable count for nnueKing --- src/variant.h | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/src/variant.h b/src/variant.h index a6dbee5..085e9b4 100644 --- a/src/variant.h +++ b/src/variant.h @@ -241,6 +241,15 @@ struct Variant { nnueKing = pieceTypes & KING ? KING : extinctionPieceCount == 0 && (extinctionPieceTypes & COMMONER) ? COMMONER : NO_PIECE_TYPE; + // The nnueKing has to present exactly once and must not change in count + if (nnueKing != NO_PIECE_TYPE) + { + // If the nnueKing is involved in promotion, count might change + if ( ((promotionPawnTypes[WHITE] | promotionPawnTypes[BLACK]) & nnueKing) + || ((promotionPieceTypes[WHITE] | promotionPieceTypes[BLACK]) & nnueKing) + || std::find(std::begin(promotedPieceType), std::end(promotedPieceType), nnueKing) != std::end(promotedPieceType)) + nnueKing = NO_PIECE_TYPE; + } if (nnueKing != NO_PIECE_TYPE) { std::string fenBoard = startFen.substr(0, startFen.find(' ')); -- 1.7.0.4