From 20cac227bbc2080b3bd3a470f402c260ee827051 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Wed, 23 Sep 2009 11:18:04 +0100 Subject: [PATCH] Retire generate_pawn_captures() And unify in generate_pawn_noncaptures() renamed generate_pawn_moves() No functional change. Signed-off-by: Marco Costalba --- src/movegen.cpp | 123 ++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 72 deletions(-) diff --git a/src/movegen.cpp b/src/movegen.cpp index a6826981..aa9f26f1 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -59,15 +59,12 @@ namespace { template MoveStack* generate_castle_moves(const Position&, MoveStack*); - template - MoveStack* generate_pawn_captures(const Position&, MoveStack*); - template MoveStack* generate_pawn_captures_diagonal(MoveStack*, Bitboard, Bitboard, bool); template - MoveStack* generate_pawn_noncaptures(const Position&, MoveStack*, Bitboard = EmptyBoardBB, - Square = SQ_NONE, Bitboard = EmptyBoardBB); + MoveStack* generate_pawn_moves(const Position&, MoveStack*, Bitboard = EmptyBoardBB, + Square = SQ_NONE, Bitboard = EmptyBoardBB); template inline Bitboard move_pawns(Bitboard p) { @@ -89,8 +86,8 @@ namespace { template<> inline MoveStack* generate_piece_checks(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) { - return (us == WHITE ? generate_pawn_noncaptures(p, m, dc, ksq) - : generate_pawn_noncaptures(p, m, dc, ksq)); + return (us == WHITE ? generate_pawn_moves(p, m, dc, ksq) + : generate_pawn_moves(p, m, dc, ksq)); } // Template generate_piece_moves() with specializations and overloads @@ -103,14 +100,11 @@ namespace { template inline MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us) { - assert(Piece == PAWN); + assert(Piece == PAWN); + assert(Type == CAPTURE || Type == NON_CAPTURE); - if (Type == CAPTURE) - return (us == WHITE ? generate_pawn_captures(p, m) - : generate_pawn_captures(p, m)); - else - return (us == WHITE ? generate_pawn_noncaptures(p, m) - : generate_pawn_noncaptures(p, m)); + return (us == WHITE ? generate_pawn_moves(p, m) + : generate_pawn_moves(p, m)); } template @@ -120,8 +114,8 @@ namespace { inline MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t, Bitboard pnd) { - return (us == WHITE ? generate_pawn_noncaptures(p, m, pnd, SQ_NONE, t) - : generate_pawn_noncaptures(p, m, pnd, SQ_NONE, t)); + return (us == WHITE ? generate_pawn_moves(p, m, pnd, SQ_NONE, t) + : generate_pawn_moves(p, m, pnd, SQ_NONE, t)); } } @@ -568,56 +562,9 @@ namespace { return mlist; } - template - 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(mlist, pawns, enemyPieces, possiblePromotion); - mlist = generate_pawn_captures_diagonal(mlist, pawns, enemyPieces, possiblePromotion); - - // Non-capturing promotions - if (possiblePromotion) - { - Bitboard b1 = move_pawns(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(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; - } - template - MoveStack* generate_pawn_noncaptures(const Position& pos, MoveStack* mlist, Bitboard dcp, - Square ksq, Bitboard blockSquares) { + MoveStack* generate_pawn_moves(const Position& pos, MoveStack* mlist, Bitboard dcp, + Square ksq, Bitboard blockSquares) { // Calculate our parametrized parameters at compile time const Color Them = (Us == WHITE ? BLACK : WHITE); @@ -632,15 +579,24 @@ namespace { Square to; Bitboard pawns = (Type != EVASION ? pos.pieces(PAWN, Us) : pos.pieces(PAWN, Us) & ~dcp); Bitboard emptySquares = pos.empty_squares(); + bool possiblePromotion = (pawns & TRank7BB); - if (pawns & TRank7BB) // There is some promotion candidate ? + if (Type == CAPTURE) + { + // Standard captures and capturing promotions in both directions + Bitboard enemyPieces = pos.pieces_of_color(opposite_color(Us)); + mlist = generate_pawn_captures_diagonal(mlist, pawns, enemyPieces, possiblePromotion); + mlist = generate_pawn_captures_diagonal(mlist, pawns, enemyPieces, possiblePromotion); + } + + if (possiblePromotion) { // When generating checks consider under-promotion moves (both captures // and non captures) only if can give a discovery check. Note that dcp // is dc bitboard or pinned bitboard when Type == EVASION. Bitboard pp = (Type == CHECK ? pawns & dcp : pawns); - if (Type != EVASION) + if (Type != EVASION && Type != CAPTURE) { Bitboard enemyPieces = pos.pieces_of_color(opposite_color(Us)); @@ -665,22 +621,45 @@ namespace { } } - // Underpromotion pawn pushes + // Underpromotion pawn pushes. Also promotion for evasions and captures. b1 = move_pawns(pp) & TRank8BB; b1 &= (Type == EVASION ? blockSquares : emptySquares); while (b1) { to = pop_1st_bit(&b1); - if (Type == EVASION) + if (Type == EVASION || Type == CAPTURE) (*mlist++).move = make_promotion_move(to - TDELTA_N, to, QUEEN); - (*mlist++).move = make_promotion_move(to - TDELTA_N, to, ROOK); - (*mlist++).move = make_promotion_move(to - TDELTA_N, to, BISHOP); - (*mlist++).move = make_promotion_move(to - TDELTA_N, to, KNIGHT); + if (Type != CAPTURE) + { + (*mlist++).move = make_promotion_move(to - TDELTA_N, to, ROOK); + (*mlist++).move = make_promotion_move(to - TDELTA_N, to, BISHOP); + (*mlist++).move = make_promotion_move(to - TDELTA_N, to, KNIGHT); + } } } + if (Type == CAPTURE) + { + // 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(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; + } + dcPawns1 = dcPawns2 = EmptyBoardBB; if (Type == CHECK && (pawns & dcp)) { -- 2.39.2