]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Last small touches in RootMoveList
[stockfish] / src / search.cpp
index 92e7273b4510e11e19b3b0f55d3f326cbf19e1b3..b75b6fa850f7d359d269faeac62b58258c55b3c2 100644 (file)
@@ -129,32 +129,34 @@ namespace {
     void set_pv(const Move newPv[]);
 
     int64_t nodes;
-    Value pv_score, non_pv_score;
-    Move move, pv[PLY_MAX_PLUS_2];
+    Value pv_score;
+    Value non_pv_score;
+    Move move;
+    Move pv[PLY_MAX_PLUS_2];
   };
 
-  RootMove::RootMove() : nodes(0) {
+  RootMove::RootMove() {
 
-      pv_score = non_pv_score = -VALUE_INFINITE;
-      move = pv[0] = MOVE_NONE;
+    nodes = 0;
+    pv_score = non_pv_score = -VALUE_INFINITE;
+    move = pv[0] = MOVE_NONE;
   }
 
   RootMove& RootMove::operator=(const RootMove& rm) {
 
-      pv_score = rm.pv_score; non_pv_score = rm.non_pv_score;
-      nodes = rm.nodes; move = rm.move;
-      set_pv(rm.pv); // Skip costly full pv[] copy
-      return *this;
+    nodes = rm.nodes;
+    pv_score = rm.pv_score;
+    non_pv_score = rm.non_pv_score;
+    move = rm.move;
+    set_pv(rm.pv); // Skip costly full pv[] copy
+    return *this;
   }
 
   void RootMove::set_pv(const Move newPv[]) {
 
     Move* p = pv;
 
-    while (*newPv != MOVE_NONE)
-        *p++ = *newPv++;
-
-    *p = MOVE_NONE;
+    do *p++ = *newPv; while (*newPv++ != MOVE_NONE);
   }
 
 
@@ -828,18 +830,6 @@ namespace {
                             value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, 1);
                             doFullDepthSearch = (value > alpha);
                         }
-
-                        // The move failed high, but if reduction is very big we could
-                        // face a false positive, retry with a less aggressive reduction,
-                        // if the move fails high again then go with full depth search.
-                        if (doFullDepthSearch && ss->reduction > 2 * ONE_PLY)
-                        {
-                            assert(newDepth - ONE_PLY >= ONE_PLY);
-
-                            ss->reduction = ONE_PLY;
-                            value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, 1);
-                            doFullDepthSearch = (value > alpha);
-                        }
                         ss->reduction = DEPTH_ZERO; // Restore original reduction
                     }
 
@@ -1347,19 +1337,6 @@ split_point_start: // At split points actual search starts from here
 
                   doFullDepthSearch = (value > alpha);
               }
-
-              // The move failed high, but if reduction is very big we could
-              // face a false positive, retry with a less aggressive reduction,
-              // if the move fails high again then go with full depth search.
-              if (doFullDepthSearch && ss->reduction > 2 * ONE_PLY)
-              {
-                  assert(newDepth - ONE_PLY >= ONE_PLY);
-
-                  ss->reduction = ONE_PLY;
-                  alpha = SpNode ? sp->alpha : alpha;
-                  value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, ply+1);
-                  doFullDepthSearch = (value > alpha);
-              }
               ss->reduction = DEPTH_ZERO; // Restore original reduction
           }
 
@@ -2682,14 +2659,12 @@ split_point_start: // At split points actual search starts from here
 
   /// The RootMoveList class
 
-  // RootMoveList c'tor
-
   RootMoveList::RootMoveList(Position& pos, Move searchMoves[]) {
 
     SearchStack ss[PLY_MAX_PLUS_2];
     MoveStack mlist[MOVES_MAX];
     StateInfo st;
-    bool includeAllMoves = (searchMoves[0] == MOVE_NONE);
+    Move* sm;
 
     // Initialize search stack
     init_ss_array(ss, PLY_MAX_PLUS_2);
@@ -2698,25 +2673,26 @@ split_point_start: // At split points actual search starts from here
     // Generate all legal moves
     MoveStack* last = generate_moves(pos, mlist);
 
-    // Add each move to the moves[] array
+    // Add each move to the RootMoveList's vector
     for (MoveStack* cur = mlist; cur != last; cur++)
     {
-        bool includeMove = includeAllMoves;
-
-        for (int k = 0; !includeMove && searchMoves[k] != MOVE_NONE; k++)
-            includeMove = (searchMoves[k] == cur->move);
+        // If we have a searchMoves[] list then verify cur->move
+        // is in the list before to add it.
+        for (sm = searchMoves; *sm && *sm != cur->move; sm++) {}
 
-        if (!includeMove)
+        if (searchMoves[0] && *sm != cur->move)
             continue;
 
         // Find a quick score for the move and add to the list
+        pos.do_move(cur->move, st);
+
         RootMove rm;
         rm.move = ss[0].currentMove = rm.pv[0] = cur->move;
         rm.pv[1] = MOVE_NONE;
-        pos.do_move(cur->move, st);
         rm.pv_score = -qsearch<PV>(pos, ss+1, -VALUE_INFINITE, VALUE_INFINITE, DEPTH_ZERO, 1);
-        pos.undo_move(cur->move);
         push_back(rm);
+
+        pos.undo_move(cur->move);
     }
     sort();
   }