X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=c17c5c5757e550680ee9929e144dcbf5bf3f2216;hp=3ae7f50ddae6a99e0c5bb6dbbbefd1ea00e3d84a;hb=190f88e5324ffd048c5234e78b41748432dc7579;hpb=8acb1d7e4ddb9627ed3c2910f6c47f466b94ad90;ds=sidebyside diff --git a/src/position.cpp b/src/position.cpp index 3ae7f50d..c17c5c57 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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;