- Bitboard occ = pos.occupied_squares();
- Color us = pos.side_to_move();
- Square ksq = pos.king_square(us);
- clear_bit(&occ, f2);
- if (type_of_piece(p) == BISHOP)
- {
- if (bit_is_set(bishop_attacks_bb(ksq, occ), t1))
- return true;
- }
- else if (type_of_piece(p) == ROOK)
- {
- if (bit_is_set(rook_attacks_bb(ksq, occ), t1))
- return true;
- }
- else
- {
- assert(type_of_piece(p) == QUEEN);
- if (bit_is_set(queen_attacks_bb(ksq, occ), t1))
- return true;
- }
+ // discovered_check_candidates() works also if the Position's side to
+ // move is the opposite of the checking piece.
+ Color them = opposite_color(pos.side_to_move());
+ Bitboard dcCandidates = pos.discovered_check_candidates(them);
+
+ if (bit_is_set(dcCandidates, f2))
+ return true;