]> git.sesse.net Git - stockfish/commitdiff
Last small touches in RootMoveList
authorMarco Costalba <mcostalba@gmail.com>
Tue, 28 Dec 2010 18:05:24 +0000 (19:05 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 28 Dec 2010 22:10:21 +0000 (23:10 +0100)
No functional change.

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

index 95a516d70e9a58a5bf3592cadf7826b417af2519..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);
   }
 
 
@@ -2657,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);
@@ -2673,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();
   }