- if (Type != CAPTURES && pos.can_castle(CastlingRights(OO | OOO)))
- {
- if (!pos.castling_impeded(OO) && pos.can_castle(OO))
- *moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OO));
-
- if (!pos.castling_impeded(OOO) && pos.can_castle(OOO))
- *moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OOO));
- }
+ if ((Type != CAPTURES) && pos.can_castle(Us & ANY_CASTLING))
+ for(CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } )
+ if (!pos.castling_impeded(cr) && pos.can_castle(cr))
+ *moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(cr));