]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Update piece list iteration also in evaluate_pieces()
[stockfish] / src / position.cpp
index 1725acbb4bc76ef68cb91249b76e0d9fa9beec98..443ba88141b6ae9c3303b4c361efd52c62df64a0 100644 (file)
@@ -704,7 +704,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
   struct ReducedStateInfo {
     Key key, pawnKey, materialKey;
     int castleRights, rule50;
-    Square kingSquare[2], epSquare;
+    Square epSquare;
     Value mgValue, egValue;
     Value npMaterial[2];
   };
@@ -784,10 +784,6 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
   board[to] = board[from];
   board[from] = EMPTY;
 
-  // If the moving piece was a king, update the king square
-  if (pt == KING)
-      st->kingSquare[us] = to;
-
   // Update piece lists, note that index[from] is not updated and
   // becomes stale. This works as long as index[] is accessed just
   // by known occupied squares.
@@ -842,6 +838,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
       Square lastPawnSquare = pieceList[us][PAWN][pieceCount[us][PAWN]];
       index[lastPawnSquare] = index[to];
       pieceList[us][PAWN][index[lastPawnSquare]] = lastPawnSquare;
+      pieceList[us][PAWN][pieceCount[us][PAWN]] = SQ_NONE;
       index[to] = pieceCount[us][promotion] - 1;
       pieceList[us][promotion][index[to]] = to;
 
@@ -947,6 +944,7 @@ void Position::do_capture_move(Bitboard& key, PieceType capture, Color them, Squ
     Square lastPieceSquare = pieceList[them][capture][pieceCount[them][capture]];
     index[lastPieceSquare] = index[capsq];
     pieceList[them][capture][index[lastPieceSquare]] = lastPieceSquare;
+    pieceList[them][capture][pieceCount[them][capture]] = SQ_NONE;
 
     // Reset rule 50 counter
     st->rule50 = 0;
@@ -1005,9 +1003,6 @@ void Position::do_castle_move(Move m) {
   board[kto] = king;
   board[rto] = rook;
 
-  // Update king square
-  st->kingSquare[us] = kto;
-
   // Update piece lists
   pieceList[us][KING][index[kfrom]] = kto;
   pieceList[us][ROOK][index[rfrom]] = rto;
@@ -1106,6 +1101,7 @@ void Position::undo_move(Move m) {
       Square lastPromotionSquare = pieceList[us][promotion][pieceCount[us][promotion]];
       index[lastPromotionSquare] = index[to];
       pieceList[us][promotion][index[lastPromotionSquare]] = lastPromotionSquare;
+      pieceList[us][promotion][pieceCount[us][promotion]] = SQ_NONE;
       index[to] = pieceCount[us][PAWN] - 1;
       pieceList[us][PAWN][index[to]] = to;
   }
@@ -1519,9 +1515,6 @@ void Position::put_piece(Piece p, Square s) {
   set_bit(&byTypeBB[0], s); // HACK: byTypeBB[0] contains all occupied squares.
 
   pieceCount[c][pt]++;
-
-  if (pt == KING)
-      st->kingSquare[c] = s;
 }