]> git.sesse.net Git - stockfish/blobdiff - src/movegen.cpp
Change pawn_attacks() API
[stockfish] / src / movegen.cpp
index 0b052e5bb105dd822e771c4ba3f098164ae84bd4..551c4c0e84090006e047916fbf74ce24703b923e 100644 (file)
@@ -135,7 +135,7 @@ namespace {
 
 
 /// generate_captures generates() all pseudo-legal captures and queen
-/// promotions. The return value is the number of moves generated.
+/// promotions. Returns a pointer to the end of the move list.
 
 MoveStack* generate_captures(const Position& pos, MoveStack* mlist) {
 
@@ -155,7 +155,7 @@ MoveStack* generate_captures(const Position& pos, MoveStack* mlist) {
 
 
 /// generate_noncaptures() generates all pseudo-legal non-captures and
-/// underpromotions. The return value is the number of moves generated.
+/// underpromotions. Returns a pointer to the end of the move list.
 
 MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
 
@@ -177,7 +177,7 @@ MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
 
 
 /// generate_non_capture_checks() generates all pseudo-legal non-capturing,
-/// non-promoting checks. It returns the number of generated moves.
+/// non-promoting checks. Returns a pointer to the end of the move list.
 
 MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc) {
 
@@ -214,7 +214,7 @@ MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bi
 
 /// generate_evasions() generates all check evasions when the side to move is
 /// in check. Unlike the other move generation functions, this one generates
-/// only legal moves. It returns the number of generated moves.
+/// only legal moves. Returns a pointer to the end of the move list.
 
 MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned) {
 
@@ -235,7 +235,7 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
   // Find squares attacked by slider checkers, we will
   // remove them from king evasions set so to avoid a couple
   // of cycles in the slow king evasions legality check loop
-  // and to be able to use square_is_attacked().
+  // and to be able to use attacks_to().
   Bitboard checkers = pos.checkers();
   Bitboard checkersAttacks = EmptyBoardBB;
   Bitboard b = checkers & pos.pieces(BISHOP, QUEEN);
@@ -257,9 +257,9 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
   while (b1)
   {
       to = pop_1st_bit(&b1);
-      // Note that we can use square_is_attacked() only because we
+      // Note that we can use attacks_to() only because we
       // have already removed slider checkers.
-      if (!pos.square_is_attacked(to, them))
+      if (!pos.attacks_to(to, them))
           (*mlist++).move = make_move(ksq, to);
   }
 
@@ -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.
@@ -441,7 +441,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
       // is occupied or under attack.
       for (s = Min(from, g1); s <= Max(from, g1); s++)
           if (  (s != from && s != to && !pos.square_is_empty(s))
-              || pos.square_is_attacked(s, them))
+              || pos.attacks_to(s, them))
               illegal = true;
 
       // Check if any of the squares between king and rook
@@ -472,7 +472,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
 
       for (s = Min(from, c1); s <= Max(from, c1); s++)
           if(  (s != from && s != to && !pos.square_is_empty(s))
-             || pos.square_is_attacked(s, them))
+             || pos.attacks_to(s, them))
               illegal = true;
 
       for (s = Min(to, d1); s <= Max(to, d1); s++)
@@ -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;
   }
@@ -942,7 +942,7 @@ namespace {
         // It is a bit complicated to correctly handle Chess960
         for (s = Min(ksq, s1); s <= Max(ksq, s1); s++)
             if (  (s != ksq && s != rsq && pos.square_is_occupied(s))
-                || pos.square_is_attacked(s, them))
+                || pos.attacks_to(s, them))
                 illegal = true;
 
         for (s = Min(rsq, s2); s <= Max(rsq, s2); s++)