version 1.4b27
[polyglot.git] / xboard2uci.cpp
index 72e81e4..5ad952a 100644 (file)
@@ -7,7 +7,7 @@
 #include <cstdio>\r
 #include <cstdlib>\r
 #include <cstring>\r
-\r
+#include <ctime>\r
 \r
 #include "board.h"\r
 #include "book.h"\r
@@ -93,6 +93,8 @@ static void no_mess        (int move);
 static void search_update  ();\r
 static void search_clear   ();\r
 static void update_remaining_time();\r
+static int  report_best_score();\r
+static bool kibitz_throttle (bool searching);\r
 static void start_protected_command();\r
 static void end_protected_command();\r
 \r
@@ -827,6 +829,16 @@ static void send_xboard_options(){
     \r
 }\r
 \r
+// report_best_score()\r
+\r
+static int report_best_score(){\r
+    if(!option_get_bool("ScoreWhite") || colour_is_white(Uci->board->turn)){\r
+        return Uci->best_score;\r
+    }else{\r
+        return -Uci->best_score;\r
+    }\r
+}\r
+\r
 // comp_move()\r
 \r
 static void comp_move(int move) {\r
@@ -1421,9 +1433,9 @@ static void send_pv() {
          line_to_san(Uci->best_pv,Uci->board,pv_string,StringSize);\r
 \r
                 if(Uci->depth==-1) //hack to clear the engine output window\r
-         gui_send(GUI,"%d %+d %.0f "S64_FORMAT" ",0,Uci->best_score,Uci->time*100.0,Uci->node_nb);\r
+             gui_send(GUI,"%d %+d %.0f "S64_FORMAT" ",0,report_best_score(),Uci->time*100.0,Uci->node_nb);\r
 \r
-                gui_send(GUI,"%d %+d %.0f "S64_FORMAT" %s",Uci->best_depth,Uci->best_score,Uci->time*100.0,Uci->node_nb,pv_string);\r
+                gui_send(GUI,"%d %+d %.0f "S64_FORMAT" %s",Uci->best_depth,report_best_score(),Uci->time*100.0,Uci->node_nb,pv_string);\r
 \r
       } else if (State->state == PONDER && option_get_bool("ShowPonder")) {\r
 \r
@@ -1433,7 +1445,7 @@ static void send_pv() {
          if (move != MoveNone && move_is_legal(move,board)) {\r
             move_to_san(move,board,move_string,256);\r
             line_to_san(Uci->best_pv,Uci->board,pv_string,StringSize);\r
-            gui_send(GUI,"%d %+d %.0f "S64_FORMAT" (%s) %s",Uci->best_depth,Uci->best_score,Uci->time*100.0,Uci->node_nb,move_string,pv_string);\r
+            gui_send(GUI,"%d %+d %.0f "S64_FORMAT" (%s) %s",Uci->best_depth,report_best_score(),Uci->time*100.0,Uci->node_nb,move_string,pv_string);\r
          }\r
       }\r
    }\r
@@ -1446,8 +1458,9 @@ static void send_pv() {
       if (State->state == THINK || State->state == ANALYSE) {\r
 \r
          line_to_san(Uci->best_pv,Uci->board,pv_string,StringSize);\r
-         gui_send(GUI,"%s depth=%d time=%.2f node="S64_FORMAT" speed=%.0f score=%+.2f pv=\"%s\"",option_get_string("KibitzCommand"),Uci->best_depth,Uci->time,Uci->node_nb,Uci->speed,double(Uci->best_score)/100.0,pv_string);\r
-\r
+         if(kibitz_throttle(Uci->searching)){\r
+             gui_send(GUI,"%s depth=%d time=%.2f node="S64_FORMAT" speed=%.0f score=%+.2f pv=\"%s\"",option_get_string("KibitzCommand"),Uci->best_depth,Uci->time,Uci->node_nb,Uci->speed,double(report_best_score())/100.0,pv_string);\r
+         }\r
       } else if (State->state == PONDER) {\r
 \r
          game_get_board(Game,board);\r
@@ -1456,12 +1469,36 @@ static void send_pv() {
          if (move != MoveNone && move_is_legal(move,board)) {\r
             move_to_san(move,board,move_string,256);\r
             line_to_san(Uci->best_pv,Uci->board,pv_string,StringSize);\r
-            gui_send(GUI,"%s depth=%d time=%.2f node="S64_FORMAT" speed=%.0f score=%+.2f pv=\"(%s) %s\"",option_get_string("KibitzCommand"),Uci->best_depth,Uci->time,Uci->node_nb,Uci->speed,double(Uci->best_score)/100.0,move_string,pv_string);\r
+            if(kibitz_throttle(Uci->searching)){\r
+                gui_send(GUI,"%s depth=%d time=%.2f node="S64_FORMAT" speed=%.0f score=%+.2f pv=\"(%s) %s\"",option_get_string("KibitzCommand"),Uci->best_depth,Uci->time,Uci->node_nb,Uci->speed,double(report_best_score())/100.0,move_string,pv_string);\r
+            }\r
          }\r
       }\r
    }\r
 }\r
 \r
+// kibitz_throttle()\r
+\r
+static bool kibitz_throttle(bool searching){\r
+    time_t curr_time;\r
+    static time_t lastKibitzMove=0;\r
+    static time_t lastKibitzPV=0;\r
+    curr_time = time(NULL);\r
+    if(searching){   // KibitzPV\r
+        if(curr_time >= (option_get_int("KibitzInterval") + lastKibitzPV)){\r
+            lastKibitzPV=curr_time;\r
+            return true;\r
+        }\r
+    }else{       // KibitzMove\r
+        if(curr_time >= (option_get_int("KibitzInterval") + lastKibitzMove)){\r
+            lastKibitzPV=curr_time;\r
+            lastKibitzMove=curr_time;\r
+            return true;\r
+        }        \r
+    }\r
+    return false;\r
+}\r
+\r
 // learn()\r
 \r
 static void learn(int result) {\r