]> git.sesse.net Git - stockfish/blobdiff - src/movegen.cpp
Triviality in SERIALIZE_PAWNS() macro usage
[stockfish] / src / movegen.cpp
index 64c44f28a0eba0d4d985854339e3aa50bd2f130f..289b51adefa43e8749bd53c008e6d173bf3dad28 100644 (file)
@@ -29,7 +29,7 @@
 
 /// Version used for pawns, where the 'from' square is given as a delta from the 'to' square
 #define SERIALIZE_PAWNS(b, d) while (b) { Square to = pop_1st_bit(&b); \
-                                         (*mlist++).move = make_move(to + (d), to); }
+                                         (*mlist++).move = make_move(to - (d), to); }
 namespace {
 
   enum CastlingSide { KING_SIDE, QUEEN_SIDE };
@@ -91,35 +91,20 @@ namespace {
   template<Square Delta>
   inline Bitboard move_pawns(Bitboard p) {
 
-    return Delta == DELTA_N  ? p << 8 : Delta == DELTA_S  ? p >> 8 :
-           Delta == DELTA_NE ? p << 9 : Delta == DELTA_SE ? p >> 7 :
-           Delta == DELTA_NW ? p << 7 : Delta == DELTA_SW ? p >> 9 : p;
-  }
-
-
-  template<Square Delta>
-  inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard target) {
-
-    const Bitboard TFileABB = (   Delta == DELTA_NE
-                               || Delta == DELTA_SE ? FileABB : FileHBB);
-
-    Bitboard b = move_pawns<Delta>(pawns) & target & ~TFileABB;
-    SERIALIZE_PAWNS(b, -Delta);
-    return mlist;
+    return  Delta == DELTA_N  ?  p << 8
+          : Delta == DELTA_S  ?  p >> 8
+          : Delta == DELTA_NE ? (p & ~FileHBB) << 9
+          : Delta == DELTA_SE ? (p & ~FileHBB) >> 7
+          : Delta == DELTA_NW ? (p & ~FileABB) << 7
+          : Delta == DELTA_SW ? (p & ~FileABB) >> 9 : p;
   }
 
 
   template<MoveType Type, Square Delta>
   inline MoveStack* generate_promotions(MoveStack* mlist, Bitboard pawnsOn7, Bitboard target, Square ksq) {
 
-    const Bitboard TFileABB = (   Delta == DELTA_NE
-                               || Delta == DELTA_SE ? FileABB : FileHBB);
-
     Bitboard b = move_pawns<Delta>(pawnsOn7) & target;
 
-    if (Delta != DELTA_N && Delta != DELTA_S)
-        b &= ~TFileABB;
-
     while (b)
     {
         Square to = pop_1st_bit(&b);
@@ -152,6 +137,7 @@ namespace {
     // Calculate our parametrized parameters at compile time, named according to
     // the point of view of white side.
     const Color    Them     = (Us == WHITE ? BLACK    : WHITE);
+    const Bitboard TRank8BB = (Us == WHITE ? Rank8BB  : Rank1BB);
     const Bitboard TRank7BB = (Us == WHITE ? Rank7BB  : Rank2BB);
     const Bitboard TRank3BB = (Us == WHITE ? Rank3BB  : Rank6BB);
     const Square   UP       = (Us == WHITE ? DELTA_N  : DELTA_S);
@@ -182,7 +168,6 @@ namespace {
 
         if (Type == MV_NON_CAPTURE_CHECK)
         {
-            // Consider only direct checks
             b1 &= pos.attacks_from<PAWN>(ksq, Them);
             b2 &= pos.attacks_from<PAWN>(ksq, Them);
 
@@ -200,12 +185,12 @@ namespace {
             }
         }
 
-        SERIALIZE_PAWNS(b1, -UP);
-        SERIALIZE_PAWNS(b2, -UP -UP);
+        SERIALIZE_PAWNS(b1, UP);
+        SERIALIZE_PAWNS(b2, UP + UP);
     }
 
     // Promotions and underpromotions
-    if (pawnsOn7)
+    if (pawnsOn7 && (Type != MV_EVASION || (target & TRank8BB)))
     {
         if (Type == MV_CAPTURE)
             emptySquares = pos.empty_squares();
@@ -221,12 +206,15 @@ namespace {
     // Standard and en-passant captures
     if (Type == MV_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION)
     {
-        mlist = generate_pawn_captures<RIGHT>(mlist, pawnsNotOn7, enemies);
-        mlist = generate_pawn_captures<LEFT >(mlist, pawnsNotOn7, enemies);
+        b1 = move_pawns<RIGHT>(pawnsNotOn7) & enemies;
+        b2 = move_pawns<LEFT >(pawnsNotOn7) & enemies;
+
+        SERIALIZE_PAWNS(b1, RIGHT);
+        SERIALIZE_PAWNS(b2, LEFT);
 
         if (pos.ep_square() != SQ_NONE)
         {
-            assert(rank_of(pos.ep_square()) == (Us == WHITE ? RANK_6 : RANK_3));
+            assert(rank_of(pos.ep_square()) == relative_rank(Us, RANK_6));
 
             // An en passant capture can be an evasion only if the checking piece
             // is the double pushed pawn and so is in the target. Otherwise this