]> git.sesse.net Git - stockfish/commitdiff
Cleanup piece_attacks_square() functions
authorMarco Costalba <mcostalba@gmail.com>
Sun, 20 Sep 2009 08:43:28 +0000 (09:43 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 20 Sep 2009 09:12:56 +0000 (10:12 +0100)
Most of them are not required to be public and are
used in one place only so remove them and use its
definitions.

Also rename piece_attacks_square() in piece_attacks()
to be aligned to the current naming policy.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/movegen.cpp
src/position.cpp
src/position.h
src/search.cpp

index c7f729e51f397554cfb1dae589fa95ec66216302..7bddeb6e8aa27a2d16b70b2596737961ed884894 100644 (file)
@@ -557,7 +557,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
   }
 
   // Luckly we can handle all the other pieces in one go
-  return (   pos.piece_attacks_square(pos.piece_on(from), from, to)
+  return (   bit_is_set(pos.piece_attacks(pc, from), to)
           && pos.pl_move_is_legal(m, pinned)
           && !move_is_promotion(m));
 }
index 162c9423f223f8128969aff16f30a440b82ce204..c4798fb504c5890f98174cb184d568bb8a3b15ca 100644 (file)
@@ -392,23 +392,22 @@ Bitboard Position::attackers_to(Square s) const {
         | (piece_attacks<KING>(s)   & pieces(KING));
 }
 
-/// Position::piece_attacks_square() tests whether the piece on square f
-/// attacks square t.
+/// Position::piece_attacks() computes a bitboard of all attacks
+/// of a given piece put in a given square.
 
-bool Position::piece_attacks_square(Piece p, Square f, Square t) const {
+Bitboard Position::piece_attacks(Piece p, Square s) const {
 
-  assert(square_is_ok(f));
-  assert(square_is_ok(t));
+  assert(square_is_ok(s));
 
   switch (p)
   {
-  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);
-  case WQ: case BQ: return piece_attacks_square<QUEEN>(f, t);
-  case WK: case BK: return piece_attacks_square<KING>(f, t);
+  case WP:          return pawn_attacks(s, WHITE);
+  case BP:          return pawn_attacks(s, BLACK);
+  case WN: case BN: return piece_attacks<KNIGHT>(s);
+  case WB: case BB: return piece_attacks<BISHOP>(s);
+  case WR: case BR: return piece_attacks<ROOK>(s);
+  case WQ: case BQ: return piece_attacks<QUEEN>(s);
+  case WK: case BK: return piece_attacks<KING>(s);
   default: break;
   }
   return false;
@@ -427,7 +426,7 @@ bool Position::move_attacks_square(Move m, Square s) const {
 
   assert(square_is_occupied(f));
 
-  if (piece_attacks_square(piece_on(f), t, s))
+  if (bit_is_set(piece_attacks(piece_on(f), t), s))
       return true;
 
   // Move the piece and scan for X-ray attacks behind it
index de6d186bc1c19bc3f97b43d229e850ead260ba42..d47d84b7633c40924e38439e4b41a4fb0dd54ba6 100644 (file)
@@ -198,13 +198,9 @@ public:
   // Attack information to a given square
   Bitboard attackers_to(Square s) const;
   Bitboard attackers_to(Square s, Color c) const;
-  template<PieceType> Bitboard piece_attacks(Square s) const;
+  Bitboard piece_attacks(Piece p, 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;
+  template<PieceType> Bitboard piece_attacks(Square s) const;
 
   // Properties of moves
   bool pl_move_is_legal(Move m) const;
@@ -474,15 +470,6 @@ inline bool Position::is_check() const {
   return st->checkersBB != EmptyBoardBB;
 }
 
-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>
-inline Bitboard Position::piece_attacks_square(Square f, Square t) const {
-  return bit_is_set(piece_attacks<Piece>(f), t);
-}
-
 inline Bitboard Position::attackers_to(Square s, Color c) const {
 
   return attackers_to(s) & pieces_of_color(c);
index 049328e15f1f8f61ab6800d159e7115894e5ed19..acd5d1da4ef7793f7ba02668b5907c2a461ff75e 100644 (file)
@@ -2153,7 +2153,9 @@ namespace {
   // the second move is assumed to be a move from the current position.
 
   bool connected_moves(const Position& pos, Move m1, Move m2) {
+
     Square f1, t1, f2, t2;
+    Piece p;
 
     assert(move_is_ok(m1));
     assert(move_is_ok(m2));
@@ -2179,11 +2181,12 @@ namespace {
       return true;
 
     // Case 4: The destination square for m2 is attacked by the moving piece in m1
-    if (pos.piece_attacks_square(pos.piece_on(t1), t1, t2))
+    p = pos.piece_on(t1);
+    if (bit_is_set(pos.piece_attacks(p, t1), t2))
         return true;
 
     // Case 5: Discovered check, checking piece is the piece moved in m1
-    if (   piece_is_slider(pos.piece_on(t1))
+    if (   piece_is_slider(p)
         && bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), f2)
         && !bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), t2))
     {
@@ -2191,19 +2194,19 @@ namespace {
         Color us = pos.side_to_move();
         Square ksq = pos.king_square(us);
         clear_bit(&occ, f2);
-        if (pos.type_of_piece_on(t1) == BISHOP)
+        if (type_of_piece(p) == BISHOP)
         {
             if (bit_is_set(bishop_attacks_bb(ksq, occ), t1))
                 return true;
         }
-        else if (pos.type_of_piece_on(t1) == ROOK)
+        else if (type_of_piece(p) == ROOK)
         {
             if (bit_is_set(rook_attacks_bb(ksq, occ), t1))
                 return true;
         }
         else
         {
-            assert(pos.type_of_piece_on(t1) == QUEEN);
+            assert(type_of_piece(p) == QUEEN);
             if (bit_is_set(queen_attacks_bb(ksq, occ), t1))
                 return true;
         }