]> git.sesse.net Git - stockfish/commitdiff
Simplify and micro-optimize hidden_checkers()
authorMarco Costalba <mcostalba@gmail.com>
Fri, 15 Jul 2011 21:24:18 +0000 (22:24 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 16 Jul 2011 07:53:21 +0000 (08:53 +0100)
No functional change.

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

index b9594ba1cf998689596a139300ffc473688a9285..e9f31456ac110a88833e92e571bbf046e448ed7c 100644 (file)
@@ -51,12 +51,12 @@ namespace {
   const uint8_t QsearchRecapturesTable[] = { PH_TT_MOVE, PH_QRECAPTURES, PH_STOP };
   const uint8_t ProbCutTable[] = { PH_TT_MOVE, PH_GOOD_PROBCUT, PH_STOP };
 
   const uint8_t QsearchRecapturesTable[] = { PH_TT_MOVE, PH_QRECAPTURES, PH_STOP };
   const uint8_t ProbCutTable[] = { PH_TT_MOVE, PH_GOOD_PROBCUT, PH_STOP };
 
-  // Unary predicate used by std::partition to split positive scores from ramining
+  // Unary predicate used by std::partition to split positive scores from remaining
   // ones so to sort separately the two sets, and with the second sort delayed.
   inline bool has_positive_score(const MoveStack& move) { return move.score > 0; }
 
   // Picks and pushes to the front the best move in range [firstMove, lastMove),
   // ones so to sort separately the two sets, and with the second sort delayed.
   inline bool has_positive_score(const MoveStack& move) { return move.score > 0; }
 
   // Picks and pushes to the front the best move in range [firstMove, lastMove),
-  // it is faster then sorting all the moves in advance when moves are few, as
+  // it is faster than sorting all the moves in advance when moves are few, as
   // normally are the possible captures.
   inline MoveStack* pick_best(MoveStack* firstMove, MoveStack* lastMove)
   {
   // normally are the possible captures.
   inline MoveStack* pick_best(MoveStack* firstMove, MoveStack* lastMove)
   {
index f25ee276b9ef70787d221f9a0454a4388c396223..43de667841764ee5fcf4bfe58e46955856a3d2d4 100644 (file)
@@ -361,36 +361,28 @@ void Position::print(Move move) const {
 
 
 /// Position:hidden_checkers<>() returns a bitboard of all pinned (against the
 
 
 /// Position:hidden_checkers<>() returns a bitboard of all pinned (against the
-/// king) pieces for the given color and for the given pinner type. Or, when
-/// template parameter FindPinned is false, the pieces of the given color
-/// candidate for a discovery check against the enemy king.
-/// Bitboard checkersBB must be already updated when looking for pinners.
+/// king) pieces for the given color. Or, when template parameter FindPinned is
+/// false, the function return the pieces of the given color candidate for a
+/// discovery check against the enemy king.
 
 template<bool FindPinned>
 Bitboard Position::hidden_checkers(Color c) const {
 
 
 template<bool FindPinned>
 Bitboard Position::hidden_checkers(Color c) const {
 
-  Bitboard result = EmptyBoardBB;
+  // Pinned pieces protect our king, dicovery checks attack the enemy king
+  Bitboard b, result = EmptyBoardBB;
   Bitboard pinners = pieces(FindPinned ? opposite_color(c) : c);
   Bitboard pinners = pieces(FindPinned ? opposite_color(c) : c);
-
-  // Pinned pieces protect our king, dicovery checks attack
-  // the enemy king.
   Square ksq = king_square(FindPinned ? c : opposite_color(c));
 
   Square ksq = king_square(FindPinned ? c : opposite_color(c));
 
-  // Pinners are sliders, not checkers, that give check when candidate pinned is removed
-  pinners &= (pieces(ROOK, QUEEN) & RookPseudoAttacks[ksq]) | (pieces(BISHOP, QUEEN) & BishopPseudoAttacks[ksq]);
-
-  if (FindPinned && pinners)
-      pinners &= ~st->checkersBB;
+  // Pinners are sliders, that give check when candidate pinned is removed
+  pinners &=  (pieces(ROOK, QUEEN) & RookPseudoAttacks[ksq])
+            | (pieces(BISHOP, QUEEN) & BishopPseudoAttacks[ksq]);
 
   while (pinners)
   {
 
   while (pinners)
   {
-      Square s = pop_1st_bit(&pinners);
-      Bitboard b = squares_between(s, ksq) & occupied_squares();
-
-      assert(b);
+      b = squares_between(ksq, pop_1st_bit(&pinners)) & occupied_squares();
 
 
-      if (  !(b & (b - 1)) // Only one bit set?
-          && (b & pieces(c))) // Is an our piece?
+      // Only one bit set and is an our piece?
+      if (b && !(b & (b - 1)) && (b & pieces(c)))
           result |= b;
   }
   return result;
           result |= b;
   }
   return result;