X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovegen.cpp;h=14705d30df86c733a0519169bae8fb171777bfb9;hp=440dd83985f8b5902db5f30f53af8f65037047f3;hb=be4ee0729ddc7eddcbb7912143a75769ea20fcd1;hpb=1d15b38cd8b15610a660bde417923c642a413a22 diff --git a/src/movegen.cpp b/src/movegen.cpp index 440dd839..14705d30 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -53,7 +53,7 @@ namespace { template MoveStack* generate_castle_moves(const Position& pos, MoveStack* mlist); - template + template MoveStack* generate_pawn_blocking_evasions(const Position&, Bitboard, Bitboard, MoveStack*); template @@ -65,7 +65,7 @@ namespace { template MoveStack* generate_pawn_noncaptures(const Position& pos, MoveStack* mlist); - template + template MoveStack* generate_pawn_checks(const Position&, Bitboard, Square, MoveStack*); template @@ -88,11 +88,8 @@ namespace { template<> inline MoveStack* generate_piece_checks(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) { - if (us == WHITE) - return generate_pawn_checks(p, dc, ksq, m); - else - return generate_pawn_checks(p, dc, ksq, m); - + return (us == WHITE ? generate_pawn_checks(p, dc, ksq, m) + : generate_pawn_checks(p, dc, ksq, m)); } // Template generate_piece_moves() with specializations and overloads @@ -121,10 +118,9 @@ namespace { template<> inline MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t, Bitboard pnd) { - if (us == WHITE) - return generate_pawn_blocking_evasions(p, pnd, t, m); - else - return generate_pawn_blocking_evasions(p, pnd, t, m); + + return (us == WHITE ? generate_pawn_blocking_evasions(p, pnd, t, m) + : generate_pawn_blocking_evasions(p, pnd, t, m)); } } @@ -752,18 +748,25 @@ namespace { } - template + template MoveStack* generate_pawn_checks(const Position& pos, Bitboard dc, Square ksq, 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 TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB); + const SquareDelta TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S); + Bitboard b1, b2, b3; Bitboard empty = pos.empty_squares(); + Bitboard pawns = pos.pawns(Us); - if (dc != EmptyBoardBB) + if (dc & pawns) { // Pawn moves which gives 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. - b1 = pos.pawns(Us) & ~file_bb(ksq); + b1 = pawns & ~file_bb(ksq); // Discovered checks, single pawn pushes, no promotions b2 = b3 = move_pawns(b1 & dc) & empty & ~TRank8BB; @@ -784,7 +787,7 @@ namespace { // Direct checks. These are possible only for pawns on neighboring files // of the enemy king. - b1 = pos.pawns(Us) & neighboring_files_bb(ksq) & ~dc; + b1 = pawns & neighboring_files_bb(ksq) & ~dc; // Direct checks, single pawn pushes b2 = move_pawns(b1) & empty; @@ -846,9 +849,15 @@ namespace { return mlist; } - template + template MoveStack* generate_pawn_blocking_evasions(const Position& pos, Bitboard pinned, Bitboard blockSquares, MoveStack* mlist) { + + // Calculate our parametrized parameters at compile time + const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB); + const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB); + const SquareDelta TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S); + Square to; // Find non-pinned pawns and push them one square @@ -863,7 +872,7 @@ namespace { assert(pos.piece_on(to) == EMPTY); - if (square_rank(to) == TRANK_8) + if (square_rank(to) == TRank8BB) { (*mlist++).move = make_promotion_move(to - TDELTA_N, to, QUEEN); (*mlist++).move = make_promotion_move(to - TDELTA_N, to, ROOK);