- 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;