+
+ int generate_pawn_checks(const PawnOffsets& ofs, const Position& pos, Bitboard dc, Square ksq, MoveStack* mlist, int n)
+ {
+ // Pawn moves which give discovered check. This is possible only if the
+ // pawn is not on the same file as the enemy king, because we don't
+ // generate captures.
+ Bitboard empty = pos.empty_squares();
+
+ // Find all friendly pawns not on the enemy king's file
+ Bitboard b1 = pos.pawns(pos.side_to_move()) & ~file_bb(ksq), b2, b3;
+
+ // Discovered checks, single pawn pushes
+ b2 = b3 = (ofs.forward)(b1 & dc) & ~ofs.Rank8BB & empty;
+ while (b3)
+ {
+ Square to = pop_1st_bit(&b3);
+ mlist[n++].move = make_move(to - ofs.DELTA_N, to);
+ }
+
+ // Discovered checks, double pawn pushes
+ b3 = (ofs.forward)(b2 & ofs.Rank3BB) & empty;
+ while (b3)
+ {
+ Square to = pop_1st_bit(&b3);
+ mlist[n++].move = make_move(to - ofs.DELTA_N - ofs.DELTA_N, to);
+ }
+
+ // Direct checks. These are possible only for pawns on neighboring files
+ // of the enemy king
+
+ b1 &= (~dc & neighboring_files_bb(ksq)); // FIXME why ~dc ??
+
+ // Direct checks, single pawn pushes
+ b2 = (ofs.forward)(b1) & empty;
+ b3 = b2 & pos.pawn_attacks(ofs.them, ksq);
+ while (b3)
+ {
+ Square to = pop_1st_bit(&b3);
+ mlist[n++].move = make_move(to - ofs.DELTA_N, to);
+ }
+
+ // Direct checks, double pawn pushes
+ b3 = (ofs.forward)(b2 & ofs.Rank3BB) & empty & pos.pawn_attacks(ofs.them, ksq);
+ while (b3)
+ {
+ Square to = pop_1st_bit(&b3);
+ mlist[n++].move = make_move(to - ofs.DELTA_N - ofs.DELTA_N, to);
+ }
+ return n;
+ }
+
+
+ int generate_piece_blocking_evasions(PieceType pce, const Position& pos, Bitboard b,
+ Bitboard blockSquares, MoveStack* mlist, int n) {
+
+ const Piece_attacks_fn mem_fn = piece_attacks_fn[pce];
+
+ while (b)
+ {
+ Square from = pop_1st_bit(&b);
+ Bitboard bb = (pos.*mem_fn)(from) & blockSquares;
+ while (bb)
+ {
+ Square to = pop_1st_bit(&bb);
+ mlist[n++].move = make_move(from, to);
+ }
+ }
+ return n;
+ }
+
+
+ int generate_pawn_blocking_evasions(const PawnOffsets& ofs, const Position& pos, Bitboard not_pinned,
+ Bitboard blockSquares, MoveStack* mlist, int n) {
+ // Find non-pinned pawns
+ Bitboard b1 = pos.pawns(ofs.us) & not_pinned;
+
+ // Single pawn pushes. We don't have to AND with empty squares here,
+ // because the blocking squares will always be empty.
+ Bitboard b2 = (ofs.forward)(b1) & blockSquares;
+ while (b2)
+ {
+ Square to = pop_1st_bit(&b2);
+
+ assert(pos.piece_on(to) == EMPTY);
+
+ if (square_rank(to) == ofs.RANK_8)
+ {
+ mlist[n++].move = make_promotion_move(to - ofs.DELTA_N, to, QUEEN);
+ mlist[n++].move = make_promotion_move(to - ofs.DELTA_N, to, ROOK);
+ mlist[n++].move = make_promotion_move(to - ofs.DELTA_N, to, BISHOP);
+ mlist[n++].move = make_promotion_move(to - ofs.DELTA_N, to, KNIGHT);
+ } else
+ mlist[n++].move = make_move(to - ofs.DELTA_N, to);
+ }
+
+ // Double pawn pushes
+ b2 = (ofs.forward)((ofs.forward)(b1) & pos.empty_squares() & ofs.Rank3BB) & blockSquares;
+ while (b2)
+ {
+ Square to = pop_1st_bit(&b2);
+
+ assert(pos.piece_on(to) == EMPTY);
+ assert(ofs.us != WHITE || square_rank(to) == RANK_4);
+ assert(ofs.us != BLACK || square_rank(to) == RANK_5);
+
+ mlist[n++].move = make_move(to - ofs.DELTA_N - ofs.DELTA_N, to);
+ }
+ return n;
+ }