Disable NNUE in case of virtual pieces
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 15 Oct 2021 16:42:27 +0000 (18:42 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 15 Oct 2021 16:42:27 +0000 (18:42 +0200)
src/position.h

index a8a523d..699d06c 100644 (file)
@@ -345,6 +345,7 @@ private:
   bool tsumeMode;
   bool chess960;
   int pieceCountInHand[COLOR_NB][PIECE_TYPE_NB];
+  int virtualPieces;
   Bitboard promotedPieces;
   void add_to_hand(Piece pc);
   void remove_from_hand(Piece pc);
@@ -540,7 +541,7 @@ 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();
+  return (!count_in_hand(ALL_PIECES) || nnue_use_pockets()) && !virtualPieces;
 }
 
 inline bool Position::checking_permitted() const {
@@ -1351,9 +1352,11 @@ inline void Position::drop_piece(Piece pc_hand, Piece pc_drop, Square s) {
   assert(pieceCountInHand[color_of(pc_hand)][type_of(pc_hand)] > 0 || var->twoBoards);
   put_piece(pc_drop, s, pc_drop != pc_hand, pc_drop != pc_hand ? pc_hand : NO_PIECE);
   remove_from_hand(pc_hand);
+  virtualPieces += (pieceCountInHand[color_of(pc_hand)][type_of(pc_hand)] < 0);
 }
 
 inline void Position::undrop_piece(Piece pc_hand, Square s) {
+  virtualPieces -= (pieceCountInHand[color_of(pc_hand)][type_of(pc_hand)] < 0);
   remove_piece(s);
   board[s] = NO_PIECE;
   add_to_hand(pc_hand);