From: Fabian Fichter Date: Sun, 8 Mar 2020 20:28:38 +0000 (+0100) Subject: Play fast when partner is dead in bughouse X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=9f8ce566d0efb717eeef98ce9c597f0327ceaa90;p=fairystockfish.git Play fast when partner is dead in bughouse bughouse Total: 500 W: 263 L: 233 D: 4 --- diff --git a/src/partner.cpp b/src/partner.cpp index 4eb3120..77ef9da 100644 --- a/src/partner.cpp +++ b/src/partner.cpp @@ -26,10 +26,18 @@ PartnerHandler Partner; // Global object +void PartnerHandler::reset() { + sitRequested = partnerDead = weDead = false; +} + +void PartnerHandler::ptell(const std::string& message) { + sync_cout << "tellics ptell " << message << sync_endl; +} + void PartnerHandler::parse_partner(std::istringstream& is) { std::string token; if (is >> token) - sync_cout << "tellics ptell partner Fairy-Stockfish is an engine. Ask it 'help' for supported commands." << sync_endl; + ptell("partner Fairy-Stockfish is an engine. Ask it 'help' for supported commands."); else isFairy = false; } @@ -45,15 +53,15 @@ void PartnerHandler::parse_ptell(std::istringstream& is, const Position& pos) { else if (token == "help") { if (!(is >> token)) - sync_cout << "tellics ptell I listen to the commands help, sit, go, and move. Ptell 'help sit', etc. for details." << sync_endl; + ptell("I listen to the commands help, sit, go, and move. Ptell 'help sit', etc. for details."); else if (token == "sit") - sync_cout << "tellics ptell After receiving 'sit', I stop moving. Also see 'go'." << sync_endl; + ptell("After receiving 'sit', I stop moving. Also see 'go'."); else if (token == "go") - sync_cout << "tellics ptell After receiving 'go', I will no longer sit." << sync_endl; + ptell("After receiving 'go', I will no longer sit."); else if (token == "move") { - sync_cout << "tellics ptell After receiving 'move', I will move immediately." << sync_endl; - sync_cout << "tellics ptell If you specify a valid move, e.g., 'move e2e4', I will play it." << sync_endl; + ptell("After receiving 'move', I will move immediately." ); + ptell("If you specify a valid move, e.g., 'move e2e4', I will play it."); } } else if (!pos.two_boards()) @@ -61,13 +69,23 @@ void PartnerHandler::parse_ptell(std::istringstream& is, const Position& pos) { else if (token == "sit") { sitRequested = true; - sync_cout << "tellics ptell I sit, tell me 'go' to continue" << sync_endl; + ptell("I sit, tell me 'go' to continue"); } else if (token == "go") { sitRequested = false; Threads.stop = true; } + else if (token == "dead") + { + partnerDead = true; + ptell("I will play fast"); + } + else if (token == "x") + { + partnerDead = false; + ptell("I will play normally again"); + } else if (token == "move") { if (is >> token) @@ -77,7 +95,7 @@ void PartnerHandler::parse_ptell(std::istringstream& is, const Position& pos) { if (move && !Threads.abort.exchange(true)) moveRequested = move; else - sync_cout << "tellics ptell sorry, not possible" << sync_endl; + ptell("sorry, not possible"); } else Threads.stop = true; diff --git a/src/partner.h b/src/partner.h index 1b378ad..47fbc7d 100644 --- a/src/partner.h +++ b/src/partner.h @@ -28,11 +28,13 @@ /// in games played on two boards, such as bughouse. struct PartnerHandler { + void reset(); + void ptell(const std::string& message); void parse_partner(std::istringstream& is); void parse_ptell(std::istringstream& is, const Position& pos); std::atomic isFairy; - std::atomic sitRequested; + std::atomic sitRequested, partnerDead, weDead; Move moveRequested; }; diff --git a/src/search.cpp b/src/search.cpp index 2e442a7..86d9828 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -258,6 +258,20 @@ void MainThread::search() { Thread::search(); // Let's start searching! } + if (rootPos.two_boards() && !Threads.abort) + { + if (!Partner.weDead && this->rootMoves[0].score <= VALUE_MATED_IN_MAX_PLY) + { + Partner.ptell("dead"); + Partner.weDead = true; + } + else if (Partner.weDead && this->rootMoves[0].score > VALUE_MATED_IN_MAX_PLY) + { + Partner.ptell("x"); + Partner.weDead = false; + } + } + // When we reach the maximum depth, we can arrive here without a raise of // Threads.stop. However, if we are pondering or in an infinite search, // the UCI protocol states that we shouldn't print the best move before the diff --git a/src/timeman.cpp b/src/timeman.cpp index 7cbeefc..b63d000 100644 --- a/src/timeman.cpp +++ b/src/timeman.cpp @@ -22,6 +22,7 @@ #include #include +#include "partner.h" #include "search.h" #include "timeman.h" #include "uci.h" @@ -128,6 +129,9 @@ void TimeManagement::init(const Position& pos, Search::LimitsType& limits, Color maximumTime = std::min(t2, maximumTime); } + if (pos.two_boards() && Partner.partnerDead) + optimumTime /= 4; + if (Options["Ponder"]) optimumTime += optimumTime / 4; } diff --git a/src/xboard.cpp b/src/xboard.cpp index 956211c..f540571 100644 --- a/src/xboard.cpp +++ b/src/xboard.cpp @@ -127,6 +127,7 @@ void StateMachine::process_command(Position& pos, std::string token, std::istrin // play second by default playColor = ~pos.side_to_move(); Threads.sit = false; + Partner.reset(); } else if (token == "variant") {