]> git.sesse.net Git - stockfish/commitdiff
Further tweak accurate pv
authorMarco Costalba <mcostalba@gmail.com>
Fri, 21 Nov 2014 08:10:52 +0000 (09:10 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 21 Nov 2014 19:37:45 +0000 (20:37 +0100)
It is a non functional change, but because
we now skip copying of pv[] in SpNode, patch
has been tested for regression with 3 threads:

STC
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 54668 W: 9873 L: 9809 D: 34986

No functional change.

src/search.cpp
src/search.h

index 31e944473b30eb8adab991760ae2669e2cc182be..e2cf76b81b7d97fc312de720bf8a41c88c068e6e 100644 (file)
@@ -87,7 +87,7 @@ namespace {
   void id_loop(Position& pos);
   Value value_to_tt(Value v, int ply);
   Value value_from_tt(Value v, int ply);
-  void update_pv(Move* pv, Move move, Move* child);
+  void update_pv(Move* pv, Move move, Move* childPv);
   void update_stats(const Position& pos, Stack* ss, Move move, Depth depth, Move* quiets, int quietsCnt);
   string uci_pv(const Position& pos, Depth depth, Value alpha, Value beta);
 
@@ -864,8 +864,9 @@ moves_loop: // When in check and at SpNode search starts from here
       // parent node fail low with value <= alpha and to try another move.
       if (PvNode && (moveCount == 1 || (value > alpha && (RootNode || value < beta))))
       {
-          pv[0] = MOVE_NONE;
           (ss+1)->pv = pv;
+          (ss+1)->pv[0] = MOVE_NONE;
+
           value = newDepth <   ONE_PLY ?
                             givesCheck ? -qsearch<PV,  true>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
                                        : -qsearch<PV, false>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
@@ -900,8 +901,11 @@ moves_loop: // When in check and at SpNode search starts from here
           {
               rm.score = value;
               rm.pv.resize(1);
-              for (int i = 0; (ss+1)->pv && (ss+1)->pv[i] != MOVE_NONE; ++i)
-                  rm.pv.push_back((ss+1)->pv[i]);
+
+              assert((ss+1)->pv);
+
+              for (Move* m = (ss+1)->pv; *m != MOVE_NONE; ++m)
+                  rm.pv.push_back(*m);
 
               // We record how often the best move has been changed in each
               // iteration. This information is used for time management: When
@@ -924,12 +928,8 @@ moves_loop: // When in check and at SpNode search starts from here
           {
               bestMove = SpNode ? splitPoint->bestMove = move : move;
 
-              if (PvNode && !RootNode)
-              {
-                  update_pv(ss->pv, move, (ss+1)->pv);
-                  if (SpNode)
-                      update_pv(splitPoint->ss->pv, move, (ss+1)->pv);
-              }
+              if (PvNode && !RootNode) // Update pv even in fail-high case
+                  update_pv(SpNode ? splitPoint->ss->pv : ss->pv, move, (ss+1)->pv);
 
               if (PvNode && value < beta) // Update alpha! Always alpha < beta
                   alpha = SpNode ? splitPoint->alpha = value : value;
@@ -1179,7 +1179,7 @@ moves_loop: // When in check and at SpNode search starts from here
 
           if (value > alpha)
           {
-              if (PvNode)
+              if (PvNode) // Update pv even in fail-high case
                   update_pv(ss->pv, move, (ss+1)->pv);
 
               if (PvNode && value < beta) // Update alpha here! Always alpha < beta
@@ -1238,12 +1238,12 @@ moves_loop: // When in check and at SpNode search starts from here
   }
 
 
-  // update_pv() copies child node pv[] adding current move
+  // update_pv() adds current move and appends child pv[]
 
-  void update_pv(Move* pv, Move move, Move* child) {
+  void update_pv(Move* pv, Move move, Move* childPv) {
 
-    for (*pv++ = move; child && *child != MOVE_NONE; )
-        *pv++ = *child++;
+    for (*pv++ = move; childPv && *childPv != MOVE_NONE; )
+        *pv++ = *childPv++;
     *pv = MOVE_NONE;
   }
 
index a399beba9a6069ebedeccc619a82f8fbc8457fed..0c552d39f5058220350e233a0a155af8ad188296 100644 (file)
@@ -56,9 +56,7 @@ struct Stack {
 /// all non-pv moves.
 struct RootMove {
 
-  RootMove(Move m) : score(-VALUE_INFINITE), prevScore(-VALUE_INFINITE) {
-    pv.push_back(m); pv.push_back(MOVE_NONE);
-  }
+  RootMove(Move m) : score(-VALUE_INFINITE), prevScore(-VALUE_INFINITE), pv(1, m) {}
 
   bool operator<(const RootMove& m) const { return score > m.score; } // Ascending sort
   bool operator==(const Move& m) const { return pv[0] == m; }