-namespace {
-
- int generate_white_pawn_captures(const Position &pos, MoveStack *mlist) {
- Bitboard pawns = pos.pawns(WHITE);
- Bitboard enemyPieces = pos.pieces_of_color(BLACK);
- Bitboard b1, b2;
- Square sq;
- int n = 0;
-
- // Captures in the a1-h8 direction:
- b1 = (pawns << 9) & ~FileABB & enemyPieces;
-
- // Promotions:
- b2 = b1 & Rank8BB;
- while(b2) {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_promotion_move(sq - DELTA_NE, sq, QUEEN);
- }
-
- // Non-promotions:
- b2 = b1 & ~Rank8BB;
- while(b2) {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_move(sq - DELTA_NE, sq);
- }
-
- // Captures in the h1-a8 direction:
- b1 = (pawns << 7) & ~FileHBB & enemyPieces;
-
- // Promotions:
- b2 = b1 & Rank8BB;
- while(b2) {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_promotion_move(sq - DELTA_NW, sq, QUEEN);
- }
-
- // Non-promotions:
- b2 = b1 & ~Rank8BB;
- while(b2) {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_move(sq - DELTA_NW, sq);
- }
-
- // Non-capturing promotions:
- b1 = (pawns << 8) & pos.empty_squares() & Rank8BB;
- while(b1) {
- sq = pop_1st_bit(&b1);
- mlist[n++].move = make_promotion_move(sq - DELTA_N, sq, QUEEN);
- }
-
- // En passant captures:
- if(pos.ep_square() != SQ_NONE) {
- assert(square_rank(pos.ep_square()) == RANK_6);
- b1 = pawns & pos.black_pawn_attacks(pos.ep_square());
- assert(b1 != EmptyBoardBB);
- while(b1) {
- sq = pop_1st_bit(&b1);
- mlist[n++].move = make_ep_move(sq, pos.ep_square());
- }
- }
-
- return n;
- }
-
-
- int generate_black_pawn_captures(const Position &pos, MoveStack *mlist) {
- Bitboard pawns = pos.pawns(BLACK);
- Bitboard enemyPieces = pos.pieces_of_color(WHITE);
- Bitboard b1, b2;
- Square sq;
- int n = 0;
-
- // Captures in the a8-h1 direction:
- b1 = (pawns >> 7) & ~FileABB & enemyPieces;
-
- // Promotions:
- b2 = b1 & Rank1BB;
- while(b2) {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_promotion_move(sq - DELTA_SE, sq, QUEEN);
- }
-
- // Non-promotions:
- b2 = b1 & ~Rank1BB;
- while(b2) {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_move(sq - DELTA_SE, sq);
- }
-
- // Captures in the h8-a1 direction:
- b1 = (pawns >> 9) & ~FileHBB & enemyPieces;
-
- // Promotions:
- b2 = b1 & Rank1BB;
- while(b2) {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_promotion_move(sq - DELTA_SW, sq, QUEEN);
- }
-
- // Non-promotions:
- b2 = b1 & ~Rank1BB;
- while(b2) {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_move(sq - DELTA_SW, sq);
- }
-
- // Non-capturing promotions:
- b1 = (pawns >> 8) & pos.empty_squares() & Rank1BB;
- while(b1) {
- sq = pop_1st_bit(&b1);
- mlist[n++].move = make_promotion_move(sq - DELTA_S, sq, QUEEN);
- }
-
- // En passant captures:
- if(pos.ep_square() != SQ_NONE) {
- assert(square_rank(pos.ep_square()) == RANK_3);
- b1 = pawns & pos.white_pawn_attacks(pos.ep_square());
- assert(b1 != EmptyBoardBB);
- while(b1) {
- sq = pop_1st_bit(&b1);
- mlist[n++].move = make_ep_move(sq, pos.ep_square());
- }
- }
-
- return n;
- }
-
-
- int generate_white_pawn_noncaptures(const Position &pos, MoveStack *mlist) {
- Bitboard pawns = pos.pawns(WHITE);
- Bitboard enemyPieces = pos.pieces_of_color(BLACK);
- Bitboard emptySquares = pos.empty_squares();
- Bitboard b1, b2;
- Square sq;
- int n = 0;
-
- // Underpromotion captures in the a1-h8 direction:
- b1 = (pawns << 9) & ~FileABB & enemyPieces & Rank8BB;
- while(b1) {
- sq = pop_1st_bit(&b1);
- mlist[n++].move = make_promotion_move(sq - DELTA_NE, sq, ROOK);
- mlist[n++].move = make_promotion_move(sq - DELTA_NE, sq, BISHOP);
- mlist[n++].move = make_promotion_move(sq - DELTA_NE, sq, KNIGHT);
- }
-
- // Underpromotion captures in the h1-a8 direction:
- b1 = (pawns << 7) & ~FileHBB & enemyPieces & Rank8BB;
- while(b1) {
- sq = pop_1st_bit(&b1);
- mlist[n++].move = make_promotion_move(sq - DELTA_NW, sq, ROOK);
- mlist[n++].move = make_promotion_move(sq - DELTA_NW, sq, BISHOP);
- mlist[n++].move = make_promotion_move(sq - DELTA_NW, sq, KNIGHT);
- }
-
- // Single pawn pushes:
- b1 = (pawns << 8) & emptySquares;
- b2 = b1 & Rank8BB;
- while(b2) {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_promotion_move(sq - DELTA_N, sq, ROOK);
- mlist[n++].move = make_promotion_move(sq - DELTA_N, sq, BISHOP);
- mlist[n++].move = make_promotion_move(sq - DELTA_N, sq, KNIGHT);
- }
- b2 = b1 & ~Rank8BB;
- while(b2) {
- sq = pop_1st_bit(&b2);
- mlist[n++].move = make_move(sq - DELTA_N, sq);
- }