]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Skip castle rights update when not needed
[stockfish] / src / position.cpp
index 480a92ec9cfcd1a7e3850aea8fbc94f61c570ece..c17c5c5757e550680ee9929e144dcbf5bf3f2216 100644 (file)
@@ -796,11 +796,14 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
     pieceList[us][piece][index[from]] = to;
     index[to] = index[from];
 
-    // Update castle rights
-    st->key ^= zobCastle[st->castleRights];
-    st->castleRights &= castleRightsMask[from];
-    st->castleRights &= castleRightsMask[to];
-    st->key ^= zobCastle[st->castleRights];
+    // Update castle rights, try to shortcut a common case
+    if ((castleRightsMask[from] & castleRightsMask[to]) != ALL_CASTLES)
+    {
+        st->key ^= zobCastle[st->castleRights];
+        st->castleRights &= castleRightsMask[from];
+        st->castleRights &= castleRightsMask[to];
+        st->key ^= zobCastle[st->castleRights];
+    }
 
     // Update checkers bitboard, piece must be already moved
     st->checkersBB = EmptyBoardBB;
@@ -1594,7 +1597,7 @@ int Position::see(Square from, Square to) const {
       if (pt == KING && stmAttackers)
       {
           assert(n < 32);
-          swapList[n++] = 100;
+          swapList[n++] = QueenValueMidgame*10;
           break;
       }
   } while (stmAttackers);