]> git.sesse.net Git - stockfish/commitdiff
Simplify hidden_checkers()
authorMarco Costalba <mcostalba@gmail.com>
Sun, 23 Jun 2013 06:08:16 +0000 (08:08 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 23 Jun 2013 07:03:40 +0000 (09:03 +0200)
De-templetize and pass color as function argument.
No speed change.

No functional change.

src/position.cpp
src/position.h

index 2a6b8989fcc8148b29037bd026562e433535ed15..d58fdec1339cfffec3665c3830003824875ac310 100644 (file)
@@ -416,36 +416,28 @@ const string Position::pretty(Move move) const {
 }
 
 
 }
 
 
-/// Position:hidden_checkers<>() returns a bitboard of all pinned (against the
-/// 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() const {
-
-  // Pinned pieces protect our king, dicovery checks attack the enemy king
-  Bitboard b, result = 0;
-  Bitboard pinners = pieces(FindPinned ? ~sideToMove : sideToMove);
-  Square ksq = king_square(FindPinned ? sideToMove : ~sideToMove);
-
-  // Pinners are sliders, that give check when candidate pinned is removed
-  pinners &=  (pieces(ROOK, QUEEN) & PseudoAttacks[ROOK][ksq])
-            | (pieces(BISHOP, QUEEN) & PseudoAttacks[BISHOP][ksq]);
+/// Position:hidden_checkers() returns a bitboard of all pinned / discovery check
+/// pieces, according to the call parameters. Pinned pieces protect our king,
+/// discovery check pieces attack the enemy king.
+
+Bitboard Position::hidden_checkers(Square ksq, Color c) const {
+
+  Bitboard b, pinners, result = 0;
+
+  // Pinners are sliders that give check when pinned piece is removed
+  pinners = (  (pieces(  ROOK, QUEEN) & PseudoAttacks[ROOK  ][ksq])
+             | (pieces(BISHOP, QUEEN) & PseudoAttacks[BISHOP][ksq])) & pieces(c);
 
   while (pinners)
   {
       b = between_bb(ksq, pop_lsb(&pinners)) & pieces();
 
 
   while (pinners)
   {
       b = between_bb(ksq, pop_lsb(&pinners)) & pieces();
 
-      if (b && !more_than_one(b) && (b & pieces(sideToMove)))
-          result |= b;
+      if (!more_than_one(b))
+          result |= b & pieces(sideToMove);
   }
   return result;
 }
 
   }
   return result;
 }
 
-// Explicit template instantiations
-template Bitboard Position::hidden_checkers<true>() const;
-template Bitboard Position::hidden_checkers<false>() const;
-
 
 /// Position::attackers_to() computes a bitboard of all pieces which attack a
 /// given square. Slider attacks use occ bitboard as occupancy.
 
 /// Position::attackers_to() computes a bitboard of all pieces which attack a
 /// given square. Slider attacks use occ bitboard as occupancy.
index d2343d10cb8507adc2d1732dbb980826edb8efb0..5a4c594df8e3d7055f196ed430cd1fd1f9320aeb 100644 (file)
@@ -193,7 +193,7 @@ private:
 
   // Helper functions
   void do_castle(Square kfrom, Square kto, Square rfrom, Square rto);
 
   // Helper functions
   void do_castle(Square kfrom, Square kto, Square rfrom, Square rto);
-  template<bool FindPinned> Bitboard hidden_checkers() const;
+  Bitboard hidden_checkers(Square ksq, Color c) const;
 
   // Computing hash keys from scratch (for initialization and debugging)
   Key compute_key() const;
 
   // Computing hash keys from scratch (for initialization and debugging)
   Key compute_key() const;
@@ -331,11 +331,11 @@ inline Bitboard Position::checkers() const {
 }
 
 inline Bitboard Position::discovered_check_candidates() const {
 }
 
 inline Bitboard Position::discovered_check_candidates() const {
-  return hidden_checkers<false>();
+  return hidden_checkers(king_square(~sideToMove), sideToMove);
 }
 
 inline Bitboard Position::pinned_pieces() const {
 }
 
 inline Bitboard Position::pinned_pieces() const {
-  return hidden_checkers<true>();
+  return hidden_checkers(king_square(sideToMove), ~sideToMove);
 }
 
 inline bool Position::pawn_is_passed(Color c, Square s) const {
 }
 
 inline bool Position::pawn_is_passed(Color c, Square s) const {