Restart search on bughouse holding command
authorFabian Fichter <ianfab@users.noreply.github.com>
Sun, 5 Jan 2020 12:42:04 +0000 (13:42 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sun, 5 Jan 2020 12:42:04 +0000 (13:42 +0100)
Instead of moving instantly, update the board state and restart the search.

src/search.cpp
src/thread.cpp
src/thread.h
src/xboard.cpp

index c49e4d8..d022a0f 100644 (file)
@@ -319,7 +319,7 @@ void MainThread::search() {
   if (Options["Protocol"] == "xboard")
   {
       // Send move only when not in analyze mode and not at game end
-      if (!Options["UCI_AnalyseMode"] && rootMoves[0].pv[0] != MOVE_NONE)
+      if (!Options["UCI_AnalyseMode"] && rootMoves[0].pv[0] != MOVE_NONE && !Threads.abort.exchange(true))
           sync_cout << "move " << UCI::move(rootPos, bestThread->rootMoves[0].pv[0]) << sync_endl;
       return;
   }
index 53d214a..88437f6 100644 (file)
@@ -178,7 +178,7 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states,
 
   main()->wait_for_search_finished();
 
-  main()->stopOnPonderhit = stop = false;
+  main()->stopOnPonderhit = stop = abort = false;
   main()->ponder = ponderMode;
   Search::Limits = limits;
   Search::RootMoves rootMoves;
index 3f03242..ac9de07 100644 (file)
@@ -109,6 +109,7 @@ struct ThreadPool : public std::vector<Thread*> {
   uint64_t tb_hits()        const { return accumulate(&Thread::tbHits); }
 
   std::atomic_bool stop;
+  std::atomic_bool abort;
 
   StateListPtr setupStates;
 
index 970da98..88c5a0f 100644 (file)
@@ -89,12 +89,17 @@ namespace XBoard {
 /// StateMachine::process_command() processes commands of the XBoard protocol.
 
 void StateMachine::process_command(Position& pos, std::string token, std::istringstream& is, StateListPtr& states) {
-  if (moveAfterSearch)
+  if (moveAfterSearch && token != "ptell")
   {
+      // abort search in bughouse when receiving "holding" command
+      bool doMove = token != "holding" || Threads.abort.exchange(true);
       Threads.stop = true;
       Threads.main()->wait_for_search_finished();
-      do_move(pos, moveList, states, Threads.main()->bestThread->rootMoves[0].pv[0]);
-      moveAfterSearch = false;
+      if (doMove)
+      {
+          do_move(pos, moveList, states, Threads.main()->bestThread->rootMoves[0].pv[0]);
+          moveAfterSearch = false;
+      }
   }
   if (token == "protover")
   {
@@ -234,6 +239,9 @@ void StateMachine::process_command(Position& pos, std::string token, std::istrin
           std::string fen = pos.fen(false, white_holdings + black_holdings);
           setboard(pos, states, fen);
       }
+      // restart search
+      if (moveAfterSearch)
+          go(pos, limits, states);
   }
   // Additional custom non-XBoard commands
   else if (token == "perft")