]> git.sesse.net Git - stockfish/blobdiff - src/position.h
Remove white/black_pawn_attacks_square()
[stockfish] / src / position.h
index 91e0a5b69767ee247a3aa330e290708334ee06ea..0099ccd2f8e08f1a6e1b3fb2539da5cdff5b4803 100644 (file)
@@ -205,27 +205,20 @@ public:
   // Checking pieces
   Bitboard checkers() const;
 
-  // Piece lists:
+  // Piece lists
   Square piece_list(Color c, PieceType pt, int index) const;
-  Square pawn_list(Color c, int index) const;
-  Square knight_list(Color c, int index) const;
-  Square bishop_list(Color c, int index) const;
-  Square rook_list(Color c, int index) const;
-  Square queen_list(Color c, int index) const;
 
   // Attack information for a given square
   bool square_is_attacked(Square s, Color c) const;
   Bitboard attacks_to(Square s) const;
   Bitboard attacks_to(Square s, Color c) const;
   bool is_check() const;
-  bool piece_attacks_square(Square f, Square t) const;
-  bool white_pawn_attacks_square(Square f, Square t) const;
-  bool black_pawn_attacks_square(Square f, Square t) const;
-  bool knight_attacks_square(Square f, Square t) const;
-  bool bishop_attacks_square(Square f, Square t) const;
-  bool rook_attacks_square(Square f, Square t) const;
-  bool queen_attacks_square(Square f, Square t) const;
-  bool king_attacks_square(Square f, Square t) const;
+  bool pawn_attacks_square(Color c, Square f, Square t) const;
+
+  template<PieceType>
+  Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
+
+  bool piece_attacks_square(Square f, Square t) const; // Dispatch at run-time
 
   // Properties of moves
   bool move_is_legal(Move m) const;
@@ -522,26 +515,6 @@ inline Square Position::piece_list(Color c, PieceType pt, int index) const {
   return pieceList[c][pt][index];
 }
 
-inline Square Position::pawn_list(Color c, int index) const {
-  return piece_list(c, PAWN, index);
-}
-
-inline Square Position::knight_list(Color c, int index) const {
-  return piece_list(c, KNIGHT, index);
-}
-
-inline Square Position::bishop_list(Color c, int index) const {
-  return piece_list(c, BISHOP, index);
-}
-
-inline Square Position::rook_list(Color c, int index) const {
-  return piece_list(c, ROOK, index);
-}
-
-inline Square Position::queen_list(Color c, int index) const {
-  return piece_list(c, QUEEN, index);
-}
-
 inline Square Position::ep_square() const {
   return epSquare;
 }
@@ -607,32 +580,13 @@ inline bool Position::is_check() const {
   return checkers() != EmptyBoardBB;
 }
 
-inline bool Position::white_pawn_attacks_square(Square f, Square t) const {
-  return bit_is_set(pawn_attacks(WHITE, f), t);
-}
-
-inline bool Position::black_pawn_attacks_square(Square f, Square t) const {
-  return bit_is_set(pawn_attacks(BLACK, f), t);
-}
-
-inline bool Position::knight_attacks_square(Square f, Square t) const {
-  return bit_is_set(piece_attacks<KNIGHT>(f), t);
-}
-
-inline bool Position::bishop_attacks_square(Square f, Square t) const {
-  return bit_is_set(piece_attacks<BISHOP>(f), t);
-}
-
-inline bool Position::rook_attacks_square(Square f, Square t) const {
-  return bit_is_set(piece_attacks<ROOK>(f), t);
-}
-
-inline bool Position::queen_attacks_square(Square f, Square t) const {
-  return bit_is_set(piece_attacks<QUEEN>(f), t);
+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::king_attacks_square(Square f, Square t) const {
-  return bit_is_set(piece_attacks<KING>(f), t);
+template<PieceType Piece>
+Bitboard Position::piece_attacks_square(Square f, Square t) const {
+  return bit_is_set(piece_attacks<Piece>(f), t);
 }
 
 inline bool Position::pawn_is_passed(Color c, Square s) const {
@@ -754,8 +708,8 @@ inline int Position::rule_50_counter() const {
 inline bool Position::opposite_colored_bishops() const {
 
   return   bishop_count(WHITE) == 1
-        && bishop_count(BLACK) == 1
-        && square_color(bishop_list(WHITE, 0)) != square_color(bishop_list(BLACK, 0));
+        && bishop_count(BLACK) == 1        
+        && square_color(piece_list(WHITE, BISHOP, 0)) != square_color(piece_list(BLACK, BISHOP, 0));
 }
 
 inline bool Position::has_pawn_on_7th(Color c) const {