]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Fix book move with searchmoves compatibility
[stockfish] / src / search.cpp
index ef247420d161345abb37ed6e18127a61db9c575b..4a4e058f9f731436e476642d0f4f0bbced3209ec 100644 (file)
@@ -328,13 +328,12 @@ void Search::think() {
           book.open(Options["Book File"].value<string>());
 
       Move bookMove = book.probe(pos, Options["Best Book Move"].value<bool>());
-      if (bookMove != MOVE_NONE)
-      {
-          if (!Signals.stop && (Limits.ponder || Limits.infinite))
-              Threads.wait_for_stop_or_ponderhit();
 
-          cout << "bestmove " << bookMove << endl;
-          return;
+      if (   bookMove != MOVE_NONE
+          && std::count(RootMoves.begin(), RootMoves.end(), bookMove))
+      {
+          std::swap(RootMoves[0], *std::find(RootMoves.begin(), RootMoves.end(), bookMove));
+          goto finish;
       }
   }
 
@@ -404,6 +403,8 @@ void Search::think() {
       pos.undo_move(RootMoves[0].pv[0]);
   }
 
+finish:
+
   // When we reach max depth we arrive here even without a StopRequest, but if
   // we are pondering or in infinite search, we shouldn't print the best move
   // before we are told to do so.