#include <cstdio>\r
#include <cstdlib>\r
#include <cstring>\r
-\r
+#include <ctime>\r
\r
#include "board.h"\r
#include "book.h"\r
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
\r
// functions\r
\r
-// xboard_init()\r
+// xboard2uci_init()\r
\r
-void xboard_init() {\r
+void xboard2uci_init() {\r
// init\r
\r
game_clear(Game);\r
XB->opp_time = 300.0;\r
}\r
\r
-void xboard_step(char string[]) {\r
+// xboard2uci_gui_step()\r
+\r
+void xboard2uci_gui_step(char string[]) {\r
\r
int move;\r
char move_string[256];\r
board_t board[1];\r
- static bool firsttime=true;\r
-\r
- if(firsttime){\r
- if((match(string,"uci"))){\r
- my_log("POLYGLOT *** Switching to UCI mode ***\n");\r
- send_uci_options();\r
- option_set("UCI","true");\r
- return;\r
- }else{\r
- //uci_send_isready(Uci); // In UCI mode this done by the GUI\r
- //Grrr...Toga can fixes the number of threads after "isready"\r
- //So we delay "isready" \r
- }\r
- firsttime=false;\r
- }\r
+\r
if (false) {\r
\r
} else if (match(string,"accepted *")) {\r
return;\r
}\r
\r
-// engine_step()\r
+// xboard2uci_engine_step()\r
\r
-void engine_step(char string[]) {\r
+void xboard2uci_engine_step(char string[]) {\r
\r
int event;\r
event = uci_parse(Uci,string);\r
\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
ASSERT(State->state==THINK);\r
ASSERT(!XB->analyse);\r
\r
- if(option_get_bool("RepeatPV")==true)\r
+ if(option_get_bool("RepeatPV"))\r
send_pv(); // to update time and nodes\r
\r
// send the move\r
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
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
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
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