- if (pos.can_castle_kingside(WHITE)) do_allow_oo(BLACK);
- if (pos.can_castle_queenside(WHITE)) do_allow_ooo(BLACK);
- if (pos.can_castle_kingside(BLACK)) do_allow_oo(WHITE);
- if (pos.can_castle_queenside(BLACK)) do_allow_ooo(WHITE);
-
- initialKFile = pos.initialKFile;
- initialKRFile = pos.initialKRFile;
- initialQRFile = pos.initialQRFile;
-
- castleRightsMask[make_square(initialKFile, RANK_1)] ^= (WHITE_OO | WHITE_OOO);
- castleRightsMask[make_square(initialKFile, RANK_8)] ^= (BLACK_OO | BLACK_OOO);
- castleRightsMask[make_square(initialKRFile, RANK_1)] ^= WHITE_OO;
- castleRightsMask[make_square(initialKRFile, RANK_8)] ^= BLACK_OO;
- castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO;
- castleRightsMask[make_square(initialQRFile, RANK_8)] ^= BLACK_OOO;
+ if (pos.can_castle(WHITE_OO))
+ set_castle(BLACK_OO, king_square(BLACK), flip_square(pos.castle_rook_square(WHITE_OO)));
+ if (pos.can_castle(WHITE_OOO))
+ set_castle(BLACK_OOO, king_square(BLACK), flip_square(pos.castle_rook_square(WHITE_OOO)));
+ if (pos.can_castle(BLACK_OO))
+ set_castle(WHITE_OO, king_square(WHITE), flip_square(pos.castle_rook_square(BLACK_OO)));
+ if (pos.can_castle(BLACK_OOO))
+ set_castle(WHITE_OOO, king_square(WHITE), flip_square(pos.castle_rook_square(BLACK_OOO)));