X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=b10ea9ea49c787bab1b08670917505cb3cb5023e;hp=bf415b34d22ac48485e9b6cc24dd1d5928fb8fdc;hb=19540c9ee824abc156d5a12ab353c250a083da4b;hpb=5bb766e826af935b159cbd2ab9c59b279930dc5e diff --git a/src/position.cpp b/src/position.cpp index bf415b34..b10ea9ea 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -242,14 +242,27 @@ void Position::from_fen(const string& fenStr, bool isChess960) { /// Position::set_castle_right() is an helper function used to set castling /// rights given the corresponding color and the rook starting square. -void Position::set_castle_right(Color c, Square rsq) { +void Position::set_castle_right(Color c, Square rfrom) { - int f = (rsq < king_square(c) ? WHITE_OOO : WHITE_OO) << c; + Square kfrom = king_square(c); + bool kingSide = kfrom < rfrom; + int cr = (kingSide ? WHITE_OO : WHITE_OOO) << c; - st->castleRights |= f; - castleRightsMask[king_square(c)] |= f; - castleRightsMask[rsq] |= f; - castleRookSquare[f] = rsq; + st->castleRights |= cr; + castleRightsMask[kfrom] |= cr; + castleRightsMask[rfrom] |= cr; + castleRookSquare[cr] = rfrom; + + Square kto = relative_square(c, kingSide ? SQ_G1 : SQ_C1); + Square rto = relative_square(c, kingSide ? SQ_F1 : SQ_D1); + + for (Square s = std::min(rfrom, rto); s <= std::max(rfrom, rto); s++) + if (s != kfrom && s != rfrom) + castlePath[cr] |= s; + + for (Square s = std::min(kfrom, kto); s <= std::max(kfrom, kto); s++) + if (s != kfrom && s != rfrom) + castlePath[cr] |= s; } @@ -366,8 +379,7 @@ Bitboard Position::hidden_checkers() const { { b = squares_between(ksq, pop_1st_bit(&pinners)) & occupied_squares(); - // Only one bit set and is an our piece? - if (b && !(b & (b - 1)) && (b & pieces(sideToMove))) + if (b && single_bit(b) && (b & pieces(sideToMove))) result |= b; } return result; @@ -1507,7 +1519,7 @@ void Position::init() { Bitboard b = cr; while (b) { - Key k = zobCastle[1 << pop_1st_bit(&b)]; + Key k = zobCastle[1ULL << pop_1st_bit(&b)]; zobCastle[cr] ^= k ? k : rk.rand(); } }