From 538c410e1a36a3af788390f643a7b44c02eff81a Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Sun, 5 Jan 2020 13:42:04 +0100 Subject: [PATCH] Restart search on bughouse holding command Instead of moving instantly, update the board state and restart the search. --- src/search.cpp | 2 +- src/thread.cpp | 2 +- src/thread.h | 1 + src/xboard.cpp | 14 +++++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index c49e4d8..d022a0f 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -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; } diff --git a/src/thread.cpp b/src/thread.cpp index 53d214a..88437f6 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -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; diff --git a/src/thread.h b/src/thread.h index 3f03242..ac9de07 100644 --- a/src/thread.h +++ b/src/thread.h @@ -109,6 +109,7 @@ struct ThreadPool : public std::vector { uint64_t tb_hits() const { return accumulate(&Thread::tbHits); } std::atomic_bool stop; + std::atomic_bool abort; StateListPtr setupStates; diff --git a/src/xboard.cpp b/src/xboard.cpp index 970da98..88c5a0f 100644 --- a/src/xboard.cpp +++ b/src/xboard.cpp @@ -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") -- 1.7.0.4