]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Stockfish 2.0
[stockfish] / src / search.cpp
index 6aef6179d28737398587acae1fe08d46c6f8d217..bd24b0f8837914d4fdcb632869b85e915eb5983a 100644 (file)
@@ -267,6 +267,7 @@ namespace {
 
   // Node counters, used only by thread[0] but try to keep in different cache
   // lines (64 bytes each) from the heavy multi-thread read accessed variables.
+  bool SendSearchedNodes;
   int NodesSincePoll;
   int NodesBetweenPolls = 30000;
 
@@ -401,7 +402,7 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[
            int movesToGo, int maxDepth, int maxNodes, int maxTime, Move searchMoves[]) {
 
   // Initialize global search variables
-  StopOnPonderhit = AbortSearch = Quit = AspirationFailLow = false;
+  StopOnPonderhit = AbortSearch = Quit = AspirationFailLow = SendSearchedNodes = false;
   NodesSincePoll = 0;
   SearchStartTime = get_system_time();
   ExactMaxTime = maxTime;
@@ -451,10 +452,7 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[
   MultiPV                   = Options["MultiPV"].value<int>();
   UseLogFile                = Options["Use Search Log"].value<bool>();
 
-  if (UseLogFile)
-      LogFile.open(Options["Search Log Filename"].value<std::string>().c_str(), std::ios::out | std::ios::app);
-
-  read_weights(pos.side_to_move());
+  read_evaluation_uci_options(pos.side_to_move());
 
   // Set the number of active threads
   ThreadsMgr.read_uci_options();
@@ -483,12 +481,17 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[
 
   // Write search information to log file
   if (UseLogFile)
-      LogFile << "Searching: " << pos.to_fen() << endl
-              << "infinite: "  << infinite
-              << " ponder: "   << ponder
-              << " time: "     << myTime
+  {
+      std::string name = Options["Search Log Filename"].value<std::string>();
+      LogFile.open(name.c_str(), std::ios::out | std::ios::app);
+
+      LogFile << "Searching: "  << pos.to_fen()
+              << "\ninfinite: " << infinite
+              << " ponder: "    << ponder
+              << " time: "      << myTime
               << " increment: " << myIncrement
               << " moves to go: " << movesToGo << endl;
+  }
 
   // We're ready to start thinking. Call the iterative deepening loop function
   Move ponderMove = MOVE_NONE;
@@ -499,22 +502,8 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[
        << " nps " << nps(pos)
        << " time " << current_search_time() << endl;
 
-  // If we are pondering or in infinite search, we shouldn't print the
-  // best move before we are told to do so.
-  if (!AbortSearch && (PonderSearch || InfiniteSearch))
-      wait_for_stop_or_ponderhit();
-
-  // Could be both MOVE_NONE when searching on a stalemate position
-  cout << "bestmove " << bestMove << " ponder " << ponderMove << endl;
-
   if (UseLogFile)
   {
-      if (dbg_show_mean)
-          dbg_print_mean(LogFile);
-
-      if (dbg_show_hit_rate)
-          dbg_print_hit_rate(LogFile);
-
       LogFile << "\nNodes: " << pos.nodes_searched()
               << "\nNodes/second: " << nps(pos)
               << "\nBest move: " << move_to_san(pos, bestMove);
@@ -524,14 +513,21 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[
       LogFile << "\nPonder move: "
               << move_to_san(pos, ponderMove) // Works also with MOVE_NONE
               << endl;
-  }
 
-  if (UseLogFile)
       LogFile.close();
+  }
 
   // This makes all the threads to go to sleep
   ThreadsMgr.set_active_threads(1);
 
+  // If we are pondering or in infinite search, we shouldn't print the
+  // best move before we are told to do so.
+  if (!AbortSearch && (PonderSearch || InfiniteSearch))
+      wait_for_stop_or_ponderhit();
+
+  // Could be both MOVE_NONE when searching on a stalemate position
+  cout << "bestmove " << bestMove << " ponder " << ponderMove << endl;
+
   return !Quit;
 }
 
@@ -726,6 +722,16 @@ namespace {
             // Save the current node count before the move is searched
             nodes = pos.nodes_searched();
 
+            // If it's time to send nodes info, do it here where we have the
+            // correct accumulated node counts searched by each thread.
+            if (SendSearchedNodes)
+            {
+                SendSearchedNodes = false;
+                cout << "info nodes " << nodes
+                     << " nps " << nps(pos)
+                     << " time " << current_search_time() << endl;
+            }
+
             // Pick the next root move, and print the move and the move number to
             // the standard output.
             move = ss->currentMove = rml[i].pv[0];
@@ -2012,8 +2018,8 @@ split_point_start: // At split points actual search starts from here
         if (dbg_show_hit_rate)
             dbg_print_hit_rate();
 
-        cout << "info nodes " << pos.nodes_searched() << " nps " << nps(pos)
-             << " time " << t << endl;
+        // Send info on searched nodes as soon as we return to root
+        SendSearchedNodes = true;
     }
 
     // Should we stop the search?
@@ -2616,19 +2622,21 @@ split_point_start: // At split points actual search starts from here
 
   std::string RootMove::pv_info_to_uci(const Position& pos, Value alpha, Value beta, int pvLine) {
 
-    std::stringstream s;
+    std::stringstream s, l;
+    Move* m = pv;
+
+    while (*m != MOVE_NONE)
+        l << *m++ << " ";
 
     s << "info depth " << Iteration // FIXME
+      << " seldepth " << int(m - pv)
       << " multipv " << pvLine + 1
       << " score " << value_to_uci(pv_score)
       << (pv_score >= beta ? " lowerbound" : pv_score <= alpha ? " upperbound" : "")
       << " time "  << current_search_time()
       << " nodes " << pos.nodes_searched()
       << " nps "   << nps(pos)
-      << " pv ";
-
-    for (Move* m = pv; *m != MOVE_NONE; m++)
-        s << *m << " ";
+      << " pv "    << l.str();
 
     if (UseLogFile && pvLine == 0)
     {