+ Color us = side_to_move();
+ Bitboard b = occupied_squares();
+ Square ksq = king_square(flip(us));
+
+ // Promotion with check ?
+ if (is_promotion(m))
+ {
+ clear_bit(&b, from);
+
+ switch (promotion_piece_type(m))
+ {
+ case KNIGHT:
+ return bit_is_set(attacks_from<KNIGHT>(to), ksq);
+ case BISHOP:
+ return bit_is_set(bishop_attacks_bb(to, b), ksq);
+ case ROOK:
+ return bit_is_set(rook_attacks_bb(to, b), ksq);
+ case QUEEN:
+ return bit_is_set(queen_attacks_bb(to, b), ksq);
+ default:
+ assert(false);
+ }
+ }
+
+ // En passant capture with check ? We have already handled the case
+ // of direct checks and ordinary discovered check, the only case we
+ // need to handle is the unusual case of a discovered check through
+ // the captured pawn.
+ if (is_enpassant(m))
+ {
+ Square capsq = make_square(file_of(to), rank_of(from));
+ clear_bit(&b, from);
+ clear_bit(&b, capsq);
+ set_bit(&b, to);
+ return (rook_attacks_bb(ksq, b) & pieces(ROOK, QUEEN, us))
+ ||(bishop_attacks_bb(ksq, b) & pieces(BISHOP, QUEEN, us));
+ }
+
+ // Castling with check ?
+ if (is_castle(m))
+ {
+ Square kfrom, kto, rfrom, rto;
+ kfrom = from;
+ rfrom = to;
+
+ if (rfrom > kfrom)
+ {
+ kto = relative_square(us, SQ_G1);
+ rto = relative_square(us, SQ_F1);
+ } else {
+ kto = relative_square(us, SQ_C1);
+ rto = relative_square(us, SQ_D1);
+ }
+ clear_bit(&b, kfrom);
+ clear_bit(&b, rfrom);
+ set_bit(&b, rto);
+ set_bit(&b, kto);
+ return bit_is_set(rook_attacks_bb(rto, b), ksq);