Simplify and speed up previous patch
authorMarco Costalba <mcostalba@gmail.com>
Tue, 9 Apr 2013 21:18:28 +0000 (23:18 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 9 Apr 2013 21:32:06 +0000 (23:32 +0200)
Use an optinal argument instead of a template
parameter. Interestingly, not only is simpler,
but also faster, perhaps due to less L1 instruction
cache pressure because we don't duplicate the very
used SEE code path.

No functional change.

src/position.cpp
src/position.h
src/search.cpp

index 1b2defa..5193d20 100644 (file)
@@ -1129,10 +1129,10 @@ void Position::undo_null_move() {
 
 
 /// Position::see() is a static exchange evaluator: It tries to estimate the
-/// material gain or loss resulting from a move. There are three versions of
-/// this function: One which takes a destination square as input, one takes a
-/// move, and one which takes a 'from' and a 'to' square. The function does
-/// not yet understand promotions captures.
+/// material gain or loss resulting from a move. Parameter 'asymmThreshold' takes
+/// tempi into account. If the side who initiated the capturing sequence does the
+/// last capture, he loses a tempo and if the result is below 'asymmThreshold'
+/// the capturing sequence is considered bad.
 
 int Position::see_sign(Move m) const {
 
@@ -1147,22 +1147,7 @@ int Position::see_sign(Move m) const {
   return see(m);
 }
 
-int Position::see(Move m) const {
-  return do_see<false>(m, 0);
-}
-
-/// Position::see_asymm() takes tempi into account.
-/// If the side who initiated the capturing sequence does the last capture,
-/// he loses a tempo. In this case if the result is below asymmThreshold 
-/// the capturing sequence is considered bad.
-
-int Position::see_asymm(Move m, int asymmThreshold) const
-{
-  return do_see<true>(m, asymmThreshold);
-}
-
-template <bool Asymmetric>
-int Position::do_see(Move m, int asymmThreshold) const {
+int Position::see(Move m, int asymmThreshold) const {
 
   Square from, to;
   Bitboard occupied, attackers, stmAttackers;
@@ -1240,16 +1225,13 @@ int Position::do_see(Move m, int asymmThreshold) const {
   } while (stmAttackers);
 
   // If we are doing asymmetric SEE evaluation and the same side does the first
-  // and the last capture, he loses a tempo and gain must be at least worth "asymmThreshold".
-  // If not, we replace the score with a very low value, before negamaxing.
-  if (Asymmetric)
-  {
-      for (int i = 0; i < slIndex ; i += 2)
-      {
+  // and the last capture, he loses a tempo and gain must be at least worth
+  // 'asymmThreshold', otherwise we replace the score with a very low value,
+  // before negamaxing.
+  if (asymmThreshold)
+      for (int i = 0; i < slIndex; i += 2)
           if (swapList[i] < asymmThreshold)
-               swapList[i] = - QueenValueMg * 16;
-      }
-  }
+              swapList[i] = - QueenValueMg * 16;
 
   // Having built the swap list, we negamax through it to find the best
   // achievable score from the point of view of the side to move.
index 0951b46..c41d31c 100644 (file)
@@ -158,9 +158,8 @@ public:
   void undo_null_move();
 
   // Static exchange evaluation
-  int see(Move m) const;
+  int see(Move m, int asymmThreshold = 0) const;
   int see_sign(Move m) const;
-  int see_asymm(Move m, int asymmThreshold) const;
 
   // Accessing hash keys
   Key key() const;
@@ -194,7 +193,6 @@ private:
 
   // Helper functions
   void do_castle(Square kfrom, Square kto, Square rfrom, Square rto);
-  template<bool Asymmetric> int do_see(Move m, int asymmThreshold) const;
   template<bool FindPinned> Bitboard hidden_checkers() const;
 
   // Computing hash keys from scratch (for initialization and debugging)
index 5abbafb..f58baf3 100644 (file)
@@ -1225,11 +1225,11 @@ split_point_start: // At split points actual search starts from here
               continue;
           }
 
-          // Prune moves with negative or equal SEE.
-          // Also prune moves with positive SEE where capturing loses a tempo and SEE < beta - futilityBase.
+          // Prune moves with negative or equal SEE and also moves with positive
+          // SEE where capturing piece loses a tempo and SEE < beta - futilityBase.
           if (   futilityBase < beta
               && depth < DEPTH_ZERO
-              && pos.see_asymm(move, beta - futilityBase) <= 0)
+              && pos.see(move, beta - futilityBase) <= 0)
           {
               bestValue = std::max(bestValue, futilityBase);
               continue;