From: Marco Costalba Date: Sun, 20 Sep 2009 07:59:18 +0000 (+0100) Subject: Change pawn_attacks() API X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=049139d025b26a9fbc9cf87f51b578a4fab447cf Change pawn_attacks() API Instead of pawn_attacks(Color c, Square s) define as pawn_attacks(Square s, Color c) to be more aligned to the others attack info functions. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/endgame.cpp b/src/endgame.cpp index 882c07cb..bc9b75ea 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -437,7 +437,7 @@ ScaleFactor ScalingFunction::apply(const Position& pos) { && (pos.piece_attacks(kingSq) & pos.pieces(PAWN, weakerSide))) { Square rsq = pos.piece_list(weakerSide, ROOK, 0); - if (pos.pawn_attacks(strongerSide, rsq) & pos.pieces(PAWN, weakerSide)) + if (pos.pawn_attacks(rsq, strongerSide) & pos.pieces(PAWN, weakerSide)) return ScaleFactor(0); } return SCALE_FACTOR_NONE; diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 7fbe9af5..a105132f 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -590,7 +590,7 @@ namespace { // Increase bonus if supported by pawn, especially if the opponent has // no minor piece which can exchange the outpost piece - if (bonus && (p.pawn_attacks(them, s) & p.pieces(PAWN, us))) + if (bonus && (p.pawn_attacks(s, them) & p.pieces(PAWN, us))) { if ( p.pieces(KNIGHT, them) == EmptyBoardBB && (SquaresByColorBB[square_color(s)] & p.pieces(BISHOP, them)) == EmptyBoardBB) @@ -954,7 +954,7 @@ namespace { b2 = pos.pieces(PAWN, us) & neighboring_files_bb(s); if (b2 & rank_bb(s)) ebonus += Value(r * 20); - else if (pos.pawn_attacks(them, s) & b2) + else if (pos.pawn_attacks(s, them) & b2) ebonus += Value(r * 12); // If the other side has only a king, check whether the pawn is diff --git a/src/movegen.cpp b/src/movegen.cpp index e7ac705f..551c4c0e 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -275,7 +275,7 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin // Generate captures of the checking piece // Pawn captures - b1 = pos.pawn_attacks(them, checksq) & pos.pieces(PAWN, us) & ~pinned; + b1 = pos.pawn_attacks(checksq, them) & pos.pieces(PAWN, us) & ~pinned; while (b1) { from = pop_1st_bit(&b1); @@ -326,7 +326,7 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin if (pos.ep_square() != SQ_NONE && (checkers & pos.pieces(PAWN, them))) { to = pos.ep_square(); - b1 = pos.pawn_attacks(them, to) & pos.pieces(PAWN, us); + b1 = pos.pawn_attacks(to, them) & pos.pieces(PAWN, us); // The checking pawn cannot be a discovered (bishop) check candidate // otherwise we were in check also before last double push move. @@ -700,7 +700,7 @@ namespace { assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6); assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3); - Bitboard b1 = pawns & pos.pawn_attacks(Them, pos.ep_square()); + Bitboard b1 = pawns & pos.pawn_attacks(pos.ep_square(), Them); assert(b1 != EmptyBoardBB); while (b1) @@ -819,11 +819,11 @@ namespace { // Direct checks, single pawn pushes Bitboard empty = pos.empty_squares(); b2 = move_pawns(b1) & empty; - b3 = b2 & pos.pawn_attacks(Them, ksq); + b3 = b2 & pos.pawn_attacks(ksq, Them); SERIALIZE_MOVES_D(b3, -TDELTA_N); // Direct checks, double pawn pushes - b3 = move_pawns(b2 & TRank3BB) & empty & pos.pawn_attacks(Them, ksq); + b3 = move_pawns(b2 & TRank3BB) & empty & pos.pawn_attacks(ksq, Them); SERIALIZE_MOVES_D(b3, -TDELTA_N -TDELTA_N); return mlist; } diff --git a/src/pawns.cpp b/src/pawns.cpp index 71b1738c..a681571d 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -303,7 +303,7 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) { if ( passed || isolated || chain - || (pos.pawn_attacks(us, s) & theirPawns) + || (pos.pawn_attacks(s, us) & theirPawns) || (ourPawns & behind_bb(us, r) & neighboring_files_bb(f))) backward = false; else @@ -312,7 +312,7 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) { // pawn on neighboring files. We now check whether the pawn is // backward by looking in the forward direction on the neighboring // files, and seeing whether we meet a friendly or an enemy pawn first. - Bitboard b = pos.pawn_attacks(us, s); + Bitboard b = pos.pawn_attacks(s, us); if (us == WHITE) { for ( ; !(b & (ourPawns | theirPawns)); b <<= 8); diff --git a/src/position.cpp b/src/position.cpp index 9c91a096..20829da2 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -384,8 +384,8 @@ Bitboard Position::discovered_check_candidates(Color c) const { Bitboard Position::attacks_to(Square s) const { - return (pawn_attacks(BLACK, s) & pieces(PAWN, WHITE)) - | (pawn_attacks(WHITE, s) & pieces(PAWN, BLACK)) + return (pawn_attacks(s, BLACK) & pieces(PAWN, WHITE)) + | (pawn_attacks(s, WHITE) & pieces(PAWN, BLACK)) | (piece_attacks(s) & pieces(KNIGHT)) | (piece_attacks(s) & pieces(ROOK, QUEEN)) | (piece_attacks(s) & pieces(BISHOP, QUEEN)) @@ -402,8 +402,8 @@ bool Position::piece_attacks_square(Piece p, Square f, Square t) const { switch (p) { - case WP: return pawn_attacks_square(WHITE, f, t); - case BP: return pawn_attacks_square(BLACK, f, t); + case WP: return pawn_attacks_square(f, t, WHITE); + case BP: return pawn_attacks_square(f, t, BLACK); case WN: case BN: return piece_attacks_square(f, t); case WB: case BB: return piece_attacks_square(f, t); case WR: case BR: return piece_attacks_square(f, t); @@ -548,7 +548,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const { { case PAWN: - if (bit_is_set(pawn_attacks(them, ksq), to)) // Normal check? + if (bit_is_set(pawn_attacks(ksq, them), to)) // Normal check? return true; if ( dcCandidates // Discovered check? @@ -667,7 +667,7 @@ inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square else if ( Piece != KING && !Slider - && bit_is_set(Piece == PAWN ? pawn_attacks(opposite_color(sideToMove), ksq) : piece_attacks(ksq), to)) + && bit_is_set(Piece == PAWN ? pawn_attacks(ksq, opposite_color(sideToMove)) : piece_attacks(ksq), to)) set_bit(pCheckersBB, to); // Discovery checks @@ -806,7 +806,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) { // Set en passant square, only if moved pawn can be captured if (abs(int(to) - int(from)) == 16) { - if (pawn_attacks(us, from + (us == WHITE ? DELTA_N : DELTA_S)) & pieces(PAWN, them)) + if (pawn_attacks(from + (us == WHITE ? DELTA_N : DELTA_S), us) & pieces(PAWN, them)) { st->epSquare = Square((int(from) + int(to)) / 2); key ^= zobEp[st->epSquare]; @@ -1362,8 +1362,8 @@ int Position::see(Square from, Square to) const { | (bishop_attacks_bb(to, occ) & pieces(BISHOP, QUEEN)) | (piece_attacks(to) & pieces(KNIGHT)) | (piece_attacks(to) & pieces(KING)) - | (pawn_attacks(WHITE, to) & pieces(PAWN, BLACK)) - | (pawn_attacks(BLACK, to) & pieces(PAWN, WHITE)); + | (pawn_attacks(to, WHITE) & pieces(PAWN, BLACK)) + | (pawn_attacks(to, BLACK) & pieces(PAWN, WHITE)); if (from != SQ_NONE) break; diff --git a/src/position.h b/src/position.h index b3f5e98b..1505874e 100644 --- a/src/position.h +++ b/src/position.h @@ -195,19 +195,16 @@ public: // Piece lists Square piece_list(Color c, PieceType pt, int index) const; - // Attack information for a given square + // Attack information to a given square Bitboard attacks_to(Square s) const; Bitboard attacks_to(Square s, Color c) const; - bool pawn_attacks_square(Color c, Square f, Square t) const; - Bitboard pawn_attacks(Color c, Square s) const; - - template - Bitboard piece_attacks(Square s) const; - - template - Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time + template Bitboard piece_attacks(Square s) const; + Bitboard pawn_attacks(Square s, Color c) const; + // Attack information to a given square from another given square + template Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time bool piece_attacks_square(Piece p, Square f, Square t) const; // Dispatch at run-time + bool pawn_attacks_square(Square f, Square t, Color c) const; // Properties of moves bool pl_move_is_legal(Move m) const; @@ -273,7 +270,7 @@ public: // Position consistency check, for debugging bool is_ok(int* failedStep = NULL) const; - // Static member functions: + // Static member functions static void init_zobrist(); static void init_piece_square_tables(); @@ -440,7 +437,7 @@ inline Square Position::initial_qr_square(Color c) const { return relative_square(c, make_square(initialQRFile, RANK_1)); } -inline Bitboard Position::pawn_attacks(Color c, Square s) const { +inline Bitboard Position::pawn_attacks(Square s, Color c) const { return StepAttackBB[piece_of_color_and_type(c, PAWN)][s]; } @@ -477,8 +474,8 @@ inline bool Position::is_check() const { return st->checkersBB != EmptyBoardBB; } -inline bool Position::pawn_attacks_square(Color c, Square f, Square t) const { - return bit_is_set(pawn_attacks(c, f), t); +inline bool Position::pawn_attacks_square(Square f, Square t, Color c) const { + return bit_is_set(pawn_attacks(f, c), t); } template