- template<Color C>
- int generate_pawn_blocking_evasions(const Position& pos, Bitboard not_pinned,
- Bitboard blockSquares, MoveStack* mlist, int n) {
+ template<PieceType Piece>
+ int generate_piece_checks(const Position& pos, Bitboard target, Bitboard dc,
+ Square ksq, MoveStack* mlist) {
+ // Discovered checks
+ int n = 0;
+ Bitboard b = target & dc;
+ while (b)
+ {
+ Square from = pop_1st_bit(&b);
+ Bitboard bb = pos.piece_attacks<Piece>(from) & pos.empty_squares();
+ while (bb)
+ {
+ Square to = pop_1st_bit(&bb);
+ mlist[n++].move = make_move(from, to);
+ }
+ }
+ // Direct checks
+ b = target & ~dc;
+ Bitboard checkSqs = pos.piece_attacks<Piece>(ksq) & pos.empty_squares();
+ while (b)
+ {
+ Square from = pop_1st_bit(&b);
+ Bitboard bb = pos.piece_attacks<Piece>(from) & checkSqs;
+ while (bb)
+ {
+ Square to = pop_1st_bit(&bb);
+ mlist[n++].move = make_move(from, to);
+ }
+ }
+ return n;
+ }
+
+ int generate_piece_checks_king(const Position& pos, Square from, Bitboard dc,
+ Square ksq, MoveStack* mlist) {
+ int n = 0;
+ if (bit_is_set(dc, from))
+ {
+ Bitboard b = pos.piece_attacks<KING>(from)
+ & pos.empty_squares()
+ & ~QueenPseudoAttacks[ksq];
+ while (b)
+ {
+ Square to = pop_1st_bit(&b);
+ mlist[n++].move = make_move(from, to);
+ }
+ }
+ return n;
+ }