]> git.sesse.net Git - stockfish/commitdiff
Split calculation of pinners from dc candidates
authorMarco Costalba <mcostalba@gmail.com>
Sat, 28 Feb 2009 09:20:57 +0000 (10:20 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 28 Feb 2009 17:43:02 +0000 (18:43 +0100)
This let us to calculate only pinners when we now that
dc candidates are not possible.

No functional change.

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

index 81208ac2262b87b3a7113d1297ade6218e12c268..ec54da9e9e3161b382120acfaadfe7c9866129fd 100644 (file)
@@ -451,20 +451,24 @@ void Position::find_checkers() {
 /// computes bitboards relative to that color only, the other computes both
 /// colors. Bitboard checkersBB must be already updated.
 
-void Position::find_hidden_checks(Color us) {
+void Position::find_hidden_checks(Color us, unsigned int types) {
 
   Bitboard p1, p2;
   Color them = opposite_color(us);
   Square ksq = king_square(them);
-  st->pinned[them] = hidden_checks<ROOK, true>(them, ksq, p1) | hidden_checks<BISHOP, true>(them, ksq, p2);
-  st->pinners[them] = p1 | p2;
-  st->dcCandidates[us] = hidden_checks<ROOK, false>(us, ksq, p1) | hidden_checks<BISHOP, false>(us, ksq, p2);
+  if (types & Pinned)
+  {
+      st->pinned[them] = hidden_checks<ROOK, true>(them, ksq, p1) | hidden_checks<BISHOP, true>(them, ksq, p2);
+      st->pinners[them] = p1 | p2;
+  }
+  if (types & DcCandidates)
+      st->dcCandidates[us] = hidden_checks<ROOK, false>(us, ksq, p1) | hidden_checks<BISHOP, false>(us, ksq, p2);
 }
 
 void Position::find_hidden_checks() {
 
   for (Color c = WHITE; c <= BLACK; c++)
-      find_hidden_checks(c);
+      find_hidden_checks(c, Pinned | DcCandidates);
 }
 
 
@@ -702,13 +706,13 @@ void Position::update_hidden_checks(Square from, Square to) {
   // otherwise skip because our dcCandidates and opponent pinned pieces are not changed.
   if (   (moveSquares & RookPseudoAttacks[ksq])   && (checkerMoved || (rooks_and_queens(us)   & RookPseudoAttacks[ksq]))
       || (moveSquares & BishopPseudoAttacks[ksq]) && (checkerMoved || (bishops_and_queens(us) & BishopPseudoAttacks[ksq])))
-      find_hidden_checks(us);
+      find_hidden_checks(us, Pinned | DcCandidates);
 
   ksq = king_square(us);
 
   if (ksq == to)
   {
-      find_hidden_checks(them);
+      find_hidden_checks(them, Pinned | DcCandidates);
       return;
   }
 
@@ -720,7 +724,18 @@ void Position::update_hidden_checks(Square from, Square to) {
   // dcCandidates and our pinned pieces are not changed.
   if (   (moveSquares & RookPseudoAttacks[ksq])   && (checkerCaptured || (rooks_and_queens(them)   & RookPseudoAttacks[ksq]))
       || (moveSquares & BishopPseudoAttacks[ksq]) && (checkerCaptured || (bishops_and_queens(them) & BishopPseudoAttacks[ksq])))
-      find_hidden_checks(them);
+  {
+
+      // If we don't have opponent dc candidates and we are moving in the
+      // attack line then won't be dc candidates also after the move.
+      if (   st->dcCandidates[them]
+          || bit_is_set(RookPseudoAttacks[ksq], from)
+          || bit_is_set(BishopPseudoAttacks[ksq], from))
+
+          find_hidden_checks(them, Pinned | DcCandidates);
+      else
+          find_hidden_checks(them, Pinned);
+  }
 }
 
 
index 11d31f8a80d17cb445f9d24e89bfd8f36393c0fd..4f18e67feeb37381c97534ec8abc0d7719167ebd 100644 (file)
@@ -288,6 +288,12 @@ public:
   static void init_piece_square_tables();
 
 private:
+
+  enum {
+      Pinned       = 1,
+      DcCandidates = 2
+  };
+
   // Initialization helper functions (used while setting up a position)
   void clear();
   void put_piece(Piece p, Square s);
@@ -303,7 +309,7 @@ private:
   void undo_promotion_move(Move m);
   void undo_ep_move(Move m);
   void find_checkers();
-  void find_hidden_checks(Color us);
+  void find_hidden_checks(Color us, unsigned int types);
   void find_hidden_checks();
   void update_hidden_checks(Square from, Square to);