Fix incremental update for hand pieces
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 4 Sep 2021 21:08:24 +0000 (23:08 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 4 Sep 2021 21:08:24 +0000 (23:08 +0200)
src/nnue/features/half_ka_v2_variants.cpp
src/position.cpp

index 8e766f8..692ad52 100644 (file)
@@ -85,7 +85,7 @@ namespace Stockfish::Eval::NNUE::Features {
       if (dp.from[i] != SQ_NONE)
         removed.push_back(make_index(perspective, dp.from[i], pc, oriented_ksq, pos));
       else if (dp.handPiece[i] != NO_PIECE)
-        removed.push_back(make_index(perspective, dp.handCount[i], dp.handPiece[i], oriented_ksq, pos));
+        removed.push_back(make_index(perspective, dp.handCount[i] - 1, dp.handPiece[i], oriented_ksq, pos));
       if (dp.to[i] != SQ_NONE)
         added.push_back(make_index(perspective, dp.to[i], pc, oriented_ksq, pos));
       else if (dp.handPiece[i] != NO_PIECE)
index 8342845..f51e349 100644 (file)
@@ -1679,9 +1679,6 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
       Square gate = gating_square(m);
       Piece gating_piece = make_piece(us, gating_type(m));
 
-      put_piece(gating_piece, gate);
-      remove_from_hand(gating_piece);
-
       if (Eval::useNNUE)
       {
           // Add gating piece
@@ -1693,6 +1690,9 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
           dp.dirty_num++;
       }
 
+      put_piece(gating_piece, gate);
+      remove_from_hand(gating_piece);
+
       st->gatesBB[us] ^= gate;
       k ^= Zobrist::psq[gating_piece][gate];
       st->materialKey ^= Zobrist::psq[gating_piece][pieceCount[gating_piece]];