X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=537674c9119c123370c44456cfb7b9ea94301451;hp=bf415b34d22ac48485e9b6cc24dd1d5928fb8fdc;hb=34178205fc762638e633a61ecc45360e1662bdee;hpb=5bb766e826af935b159cbd2ab9c59b279930dc5e diff --git a/src/position.cpp b/src/position.cpp index bf415b34..537674c9 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; }