Play fast when partner is dead in bughouse
authorFabian Fichter <ianfab@users.noreply.github.com>
Sun, 8 Mar 2020 20:28:38 +0000 (21:28 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sun, 8 Mar 2020 20:28:38 +0000 (21:28 +0100)
bughouse
Total: 500 W: 263 L: 233 D: 4

src/partner.cpp
src/partner.h
src/search.cpp
src/timeman.cpp
src/xboard.cpp

index 4eb3120..77ef9da 100644 (file)
 
 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;
index 1b378ad..47fbc7d 100644 (file)
 /// 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<bool> isFairy;
-    std::atomic<bool> sitRequested;
+    std::atomic<bool> sitRequested, partnerDead, weDead;
     Move moveRequested;
 };
 
index 2e442a7..86d9828 100644 (file)
@@ -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
index 7cbeefc..b63d000 100644 (file)
@@ -22,6 +22,7 @@
 #include <cfloat>
 #include <cmath>
 
+#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;
 }
index 956211c..f540571 100644 (file)
@@ -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")
   {