]> git.sesse.net Git - stockfish/commitdiff
Change piece_attacks_square() API
authorMarco Costalba <mcostalba@gmail.com>
Tue, 17 Feb 2009 11:00:05 +0000 (12:00 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 17 Feb 2009 11:00:05 +0000 (12:00 +0100)
An extra argument let us simplify some code.

No functional change.

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

index 817b4f98f0763f01007e728299b23ff5ca8a5696..a002e19fe98c92b64f29e547143633ba619e1416 100644 (file)
@@ -539,7 +539,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
   }
 
   // Luckly we can handle all the other pieces in one go
   }
 
   // Luckly we can handle all the other pieces in one go
-  return (   pos.piece_attacks_square(from, to)
+  return (   pos.piece_attacks_square(pos.piece_on(from), from, to)
           && pos.pl_move_is_legal(m, pinned)
           && !move_promotion(m));
 }
           && pos.pl_move_is_legal(m, pinned)
           && !move_promotion(m));
 }
index 501674d6a283bf734f5d79d2d0e7e904fb1b2bb0..1b1fef8ac3978a694209d8eacc18f754fb4f2971 100644 (file)
@@ -399,12 +399,12 @@ Bitboard Position::attacks_to(Square s) const {
 /// Position::piece_attacks_square() tests whether the piece on square f
 /// attacks square t.
 
 /// Position::piece_attacks_square() tests whether the piece on square f
 /// attacks square t.
 
-bool Position::piece_attacks_square(Square f, Square t) const {
+bool Position::piece_attacks_square(Piece p, Square f, Square t) const {
 
   assert(square_is_ok(f));
   assert(square_is_ok(t));
 
 
   assert(square_is_ok(f));
   assert(square_is_ok(t));
 
-  switch (piece_on(f))
+  switch (p)
   {
   case WP:          return pawn_attacks_square(WHITE, f, t);
   case BP:          return pawn_attacks_square(BLACK, f, t);
   {
   case WP:          return pawn_attacks_square(WHITE, f, t);
   case BP:          return pawn_attacks_square(BLACK, f, t);
@@ -427,24 +427,11 @@ bool Position::move_attacks_square(Move m, Square s) const {
   assert(move_is_ok(m));
   assert(square_is_ok(s));
 
   assert(move_is_ok(m));
   assert(square_is_ok(s));
 
-  bool is_attack;
   Square f = move_from(m), t = move_to(m);
 
   assert(square_is_occupied(f));
 
   Square f = move_from(m), t = move_to(m);
 
   assert(square_is_occupied(f));
 
-  switch (piece_on(f))
-  {
-  case WP:          is_attack = pawn_attacks_square(WHITE, t, s); break;
-  case BP:          is_attack = pawn_attacks_square(BLACK, t, s); break;
-  case WN: case BN: is_attack = piece_attacks_square<KNIGHT>(t, s); break;
-  case WB: case BB: is_attack = piece_attacks_square<BISHOP>(t, s); break;
-  case WR: case BR: is_attack = piece_attacks_square<ROOK>(t, s); break;
-  case WQ: case BQ: is_attack = piece_attacks_square<QUEEN>(t, s); break;
-  case WK: case BK: is_attack = piece_attacks_square<KING>(t, s); break;
-  default: break;
-  }
-
-  if (is_attack)
+  if (piece_attacks_square(piece_on(f), t, s))
       return true;
 
   // Move the piece and scan for X-ray attacks behind it
       return true;
 
   // Move the piece and scan for X-ray attacks behind it
index 8e2ecf6019b812eb5872e2f7db27d36d65ea2528..ceebce1c61c79e47683338ce7d913c6e8b1bb38c 100644 (file)
@@ -215,7 +215,7 @@ public:
   template<PieceType>
   Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
 
   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
+  bool piece_attacks_square(Piece p, Square f, Square t) const; // Dispatch at run-time
 
   // Properties of moves
   bool pl_move_is_legal(Move m) const;
 
   // Properties of moves
   bool pl_move_is_legal(Move m) const;
index b00c270bbd94bd034dcfe96fcd2bd6d979c0ccbc..c93780b37db7d8f4288f65e73372251b43ad746c 100644 (file)
@@ -2113,7 +2113,7 @@ namespace {
 
     // Case 4: The destination square for m2 is attacked by the moving piece
     // in m1:
 
     // Case 4: The destination square for m2 is attacked by the moving piece
     // in m1:
-    if(pos.piece_attacks_square(t1, t2))
+    if(pos.piece_attacks_square(pos.piece_on(t1), t1, t2))
       return true;
 
     // Case 5: Discovered check, checking piece is the piece moved in m1:
       return true;
 
     // Case 5: Discovered check, checking piece is the piece moved in m1: