+
+ int generate_piece_checks(PieceType pce, const Position& pos, Bitboard target,
+ Bitboard dc, Square ksq, MoveStack* mlist) {
+
+ const Piece_attacks_fn mem_fn = piece_attacks_fn[pce];
+ int n = 0;
+
+ // Discovered checks
+ Bitboard b = target & dc;
+ while (b)
+ {
+ Square from = pop_1st_bit(&b);
+ Bitboard bb = (pos.*mem_fn)(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.*mem_fn)(ksq) & pos.empty_squares();
+ while (b)
+ {
+ Square from = pop_1st_bit(&b);
+ Bitboard bb = (pos.*mem_fn)(from) & checkSqs;
+ while (bb)
+ {
+ Square to = pop_1st_bit(&bb);
+ mlist[n++].move = make_move(from, to);
+ }
+ }
+ return n;
+ }