Speed up attackers_to
authorFabian Fichter <ianfab@users.noreply.github.com>
Tue, 28 Aug 2018 18:19:27 +0000 (20:19 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Tue, 28 Aug 2018 18:19:27 +0000 (20:19 +0200)
Loop only over relevant piece types for a speed-up with no functional change.

src/position.cpp

index c2b40da..9cc14b8 100644 (file)
@@ -658,7 +658,7 @@ Bitboard Position::attackers_to(Square s, Bitboard occupied) const {
 
   Bitboard b = 0;
   for (Color c = WHITE; c <= BLACK; ++c)
-      for (PieceType pt = PAWN; pt <= KING; ++pt)
+      for (PieceType pt : piece_types())
           b |= attacks_bb(~c, pt, s, occupied) & pieces(c, pt);
   return b;
 }