- }
- return n;
- }
-
- template<Color Us, Color Them, Bitboard TRank8BB, Bitboard TRank3BB,
- SquareDelta TDELTA_NE, SquareDelta TDELTA_NW, SquareDelta TDELTA_N
- >
- int do_generate_pawn_noncaptures(const Position& pos, MoveStack* mlist) {
-
- Bitboard pawns = pos.pawns(Us);
- Bitboard enemyPieces = pos.pieces_of_color(Them);
- Bitboard emptySquares = pos.empty_squares();
- Bitboard b1, b2;
- Square sq;
- int n = 0;
-
- // Underpromotion captures in the a1-h8 (a8-h1 for black) direction
- b1 = (Us == WHITE ? pawns << 9 : pawns >> 7) & ~FileABB & enemyPieces & TRank8BB;
- while (b1)
- {
- sq = pop_1st_bit(&b1);
- mlist[n++].move = make_promotion_move(sq - TDELTA_NE, sq, ROOK);
- mlist[n++].move = make_promotion_move(sq - TDELTA_NE, sq, BISHOP);
- mlist[n++].move = make_promotion_move(sq - TDELTA_NE, sq, KNIGHT);
- }
-
- // Underpromotion captures in the h1-a8 (h8-a1 for black) direction
- b1 = (Us == WHITE ? pawns << 7 : pawns >> 9) & ~FileHBB & enemyPieces & TRank8BB;
- while (b1)
- {
- sq = pop_1st_bit(&b1);
- mlist[n++].move = make_promotion_move(sq - TDELTA_NW, sq, ROOK);
- mlist[n++].move = make_promotion_move(sq - TDELTA_NW, sq, BISHOP);
- mlist[n++].move = make_promotion_move(sq - TDELTA_NW, sq, KNIGHT);
- }
-
- // Single pawn pushes
- b1 = (Us == WHITE ? pawns << 8 : pawns >> 8) & emptySquares;
- b2 = b1 & TRank8BB;
- while (b2)
- {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_promotion_move(sq - TDELTA_N, sq, ROOK);
- mlist[n++].move = make_promotion_move(sq - TDELTA_N, sq, BISHOP);
- mlist[n++].move = make_promotion_move(sq - TDELTA_N, sq, KNIGHT);
- }
- b2 = b1 & ~TRank8BB;
- while (b2)
- {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_move(sq - TDELTA_N, sq);
- }
-
- // Double pawn pushes
- b2 = (Us == WHITE ? (b1 & TRank3BB) << 8 : (b1 & TRank3BB) >> 8) & emptySquares;
- while (b2)
- {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_move(sq - TDELTA_N - TDELTA_N, sq);
- }
- return n;
- }
-
-
- template<Color Us, Color Them, Bitboard TRank8BB, Bitboard TRank3BB, SquareDelta TDELTA_N>
- int do_generate_pawn_checks(const Position& pos, Bitboard dc, Square ksq, MoveStack* mlist)
- {
- // 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.
- int n = 0;
- Bitboard empty = pos.empty_squares();
-
- // Find all friendly pawns not on the enemy king's file
- Bitboard b1 = pos.pawns(Us) & ~file_bb(ksq), b2, b3;
-
- // Discovered checks, single pawn pushes
- b2 = b3 = (Us == WHITE ? (b1 & dc) << 8 : (b1 & dc) >> 8) & ~TRank8BB & empty;
- while (b3)
- {
- Square to = pop_1st_bit(&b3);
- mlist[n++].move = make_move(to - TDELTA_N, to);