- template<Color Us>
- MoveStack* generate_pawn_captures(const Position& pos, MoveStack* mlist) {
-
- // Calculate our parametrized parameters at compile time
- const Color Them = (Us == WHITE ? BLACK : WHITE);
- const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
- const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
- const SquareDelta TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S);
-
- Square to;
- Bitboard pawns = pos.pieces(PAWN, Us);
- Bitboard enemyPieces = pos.pieces_of_color(opposite_color(Us));
- bool possiblePromotion = (pawns & TRank7BB);
-
- // Standard captures and capturing promotions in both directions
- mlist = generate_pawn_captures_diagonal<Us, DELTA_NE>(mlist, pawns, enemyPieces, possiblePromotion);
- mlist = generate_pawn_captures_diagonal<Us, DELTA_NW>(mlist, pawns, enemyPieces, possiblePromotion);
-
- // Non-capturing promotions
- if (possiblePromotion)
- {
- Bitboard b1 = move_pawns<Us, DELTA_N>(pawns) & pos.empty_squares() & TRank8BB;
- while (b1)
- {
- to = pop_1st_bit(&b1);
- (*mlist++).move = make_promotion_move(to - TDELTA_N, to, QUEEN);
- }
- }
-
- // En passant captures
- if (pos.ep_square() != SQ_NONE)
- {
- assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
- assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3);
-
- Bitboard b1 = pawns & pos.attacks_from<PAWN>(pos.ep_square(), Them);
- assert(b1 != EmptyBoardBB);
-
- while (b1)
- {
- to = pop_1st_bit(&b1);
- (*mlist++).move = make_ep_move(to, pos.ep_square());
- }
- }
- return mlist;
- }
-