]> git.sesse.net Git - stockfish/commitdiff
Change pawn_attacks() API
authorMarco Costalba <mcostalba@gmail.com>
Sun, 20 Sep 2009 07:59:18 +0000 (08:59 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 20 Sep 2009 08:09:27 +0000 (09:09 +0100)
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 <mcostalba@gmail.com>
src/endgame.cpp
src/evaluate.cpp
src/movegen.cpp
src/pawns.cpp
src/position.cpp
src/position.h

index 882c07cbf43d7c9ec3d08218920408c3509f7e07..bc9b75eaabb84301abe4b7e344a9577cd20b77ff 100644 (file)
@@ -437,7 +437,7 @@ ScaleFactor ScalingFunction<KQKRPs>::apply(const Position& pos) {
       && (pos.piece_attacks<KING>(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;
index 7fbe9af5092a92f04e2c5f6a7053cfa46f30ba84..a105132f0a7a8f6a72eb62df47b013ac23fffc7b 100644 (file)
@@ -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
index e7ac705feeea78716923ca21b7aa4f44f8247a0d..551c4c0e84090006e047916fbf74ce24703b923e 100644 (file)
@@ -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<Us, DELTA_N>(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<Us, DELTA_N>(b2 & TRank3BB) & empty & pos.pawn_attacks(Them, ksq);
+    b3 =  move_pawns<Us, DELTA_N>(b2 & TRank3BB) & empty & pos.pawn_attacks(ksq, Them);
     SERIALIZE_MOVES_D(b3, -TDELTA_N -TDELTA_N);
     return mlist;
   }
index 71b1738cc253f8b3b5bafc215d7d160ea71c8c01..a681571dd9c72c90d76bb23365f7b914ecc7af71 100644 (file)
@@ -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);
index 9c91a0969e7ae0f9012cb3b973405803c4244448..20829da26f782ca52b8fef5c18ba9aced711183c 100644 (file)
@@ -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<KNIGHT>(s) & pieces(KNIGHT))
         | (piece_attacks<ROOK>(s)   & pieces(ROOK, QUEEN))
         | (piece_attacks<BISHOP>(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<KNIGHT>(f, t);
   case WB: case BB: return piece_attacks_square<BISHOP>(f, t);
   case WR: case BR: return piece_attacks_square<ROOK>(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<Piece>(ksq), to))
+           && bit_is_set(Piece == PAWN ? pawn_attacks(ksq, opposite_color(sideToMove)) : piece_attacks<Piece>(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<KNIGHT>(to)  & pieces(KNIGHT))
                  | (piece_attacks<KING>(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;
index b3f5e98b46a6337320e439f16be46216a4980ae6..1505874e9f0269111f338fd5d09f0a2efca95b7b 100644 (file)
@@ -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<PieceType>
-  Bitboard piece_attacks(Square s) const;
-
-  template<PieceType>
-  Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
+  template<PieceType> 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<PieceType> 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<PieceType Piece>