X-Git-Url: http://winboard.nl/cgi-bin?p=polyglot.git;a=blobdiff_plain;f=xboard2uci.cpp;h=5ad952ae91c9074baa318228e5ef31f5f25f67c2;hp=1ffda48329f90e8d6f6583196b8440d96e3000ce;hb=0d182b4efac85dce968068bfe4509e52e9a30051;hpb=ad2265d4fc54fc9ba99fc606e6174df34bfb4a0f diff --git a/xboard2uci.cpp b/xboard2uci.cpp index 1ffda48..5ad952a 100644 --- a/xboard2uci.cpp +++ b/xboard2uci.cpp @@ -7,7 +7,7 @@ #include #include #include - +#include #include "board.h" #include "book.h" @@ -93,6 +93,8 @@ static void no_mess (int move); static void search_update (); static void search_clear (); static void update_remaining_time(); +static int report_best_score(); +static bool kibitz_throttle (bool searching); static void start_protected_command(); static void end_protected_command(); @@ -112,9 +114,9 @@ static void learn (int result); // functions -// xboard_init() +// xboard2uci_init() -void xboard_init() { +void xboard2uci_init() { // init game_clear(Game); @@ -161,26 +163,14 @@ void xboard_init() { XB->opp_time = 300.0; } -void xboard_step(char string[]) { +// xboard2uci_gui_step() + +void xboard2uci_gui_step(char string[]) { int move; char move_string[256]; board_t board[1]; - static bool firsttime=true; - - if(firsttime){ - if((match(string,"uci"))){ - my_log("POLYGLOT *** Switching to UCI mode ***\n"); - send_uci_options(); - option_set("UCI","true"); - return; - }else{ - //uci_send_isready(Uci); // In UCI mode this done by the GUI - //Grrr...Toga can fixes the number of threads after "isready" - //So we delay "isready" - } - firsttime=false; - } + if (false) { } else if (match(string,"accepted *")) { @@ -661,9 +651,9 @@ void xboard_step(char string[]) { return; } -// engine_step() +// xboard2uci_engine_step() -void engine_step(char string[]) { +void xboard2uci_engine_step(char string[]) { int event; event = uci_parse(Uci,string); @@ -839,6 +829,16 @@ static void send_xboard_options(){ } +// report_best_score() + +static int report_best_score(){ + if(!option_get_bool("ScoreWhite") || colour_is_white(Uci->board->turn)){ + return Uci->best_score; + }else{ + return -Uci->best_score; + } +} + // comp_move() static void comp_move(int move) { @@ -851,7 +851,7 @@ static void comp_move(int move) { ASSERT(State->state==THINK); ASSERT(!XB->analyse); - if(option_get_bool("RepeatPV")==true) + if(option_get_bool("RepeatPV")) send_pv(); // to update time and nodes // send the move @@ -1433,9 +1433,9 @@ static void send_pv() { line_to_san(Uci->best_pv,Uci->board,pv_string,StringSize); if(Uci->depth==-1) //hack to clear the engine output window - gui_send(GUI,"%d %+d %.0f "S64_FORMAT" ",0,Uci->best_score,Uci->time*100.0,Uci->node_nb); + gui_send(GUI,"%d %+d %.0f "S64_FORMAT" ",0,report_best_score(),Uci->time*100.0,Uci->node_nb); - gui_send(GUI,"%d %+d %.0f "S64_FORMAT" %s",Uci->best_depth,Uci->best_score,Uci->time*100.0,Uci->node_nb,pv_string); + gui_send(GUI,"%d %+d %.0f "S64_FORMAT" %s",Uci->best_depth,report_best_score(),Uci->time*100.0,Uci->node_nb,pv_string); } else if (State->state == PONDER && option_get_bool("ShowPonder")) { @@ -1445,7 +1445,7 @@ static void send_pv() { if (move != MoveNone && move_is_legal(move,board)) { move_to_san(move,board,move_string,256); line_to_san(Uci->best_pv,Uci->board,pv_string,StringSize); - 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); + 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); } } } @@ -1458,8 +1458,9 @@ static void send_pv() { if (State->state == THINK || State->state == ANALYSE) { line_to_san(Uci->best_pv,Uci->board,pv_string,StringSize); - 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); - + if(kibitz_throttle(Uci->searching)){ + 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); + } } else if (State->state == PONDER) { game_get_board(Game,board); @@ -1468,12 +1469,36 @@ static void send_pv() { if (move != MoveNone && move_is_legal(move,board)) { move_to_san(move,board,move_string,256); line_to_san(Uci->best_pv,Uci->board,pv_string,StringSize); - 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); + if(kibitz_throttle(Uci->searching)){ + 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); + } } } } } +// kibitz_throttle() + +static bool kibitz_throttle(bool searching){ + time_t curr_time; + static time_t lastKibitzMove=0; + static time_t lastKibitzPV=0; + curr_time = time(NULL); + if(searching){ // KibitzPV + if(curr_time >= (option_get_int("KibitzInterval") + lastKibitzPV)){ + lastKibitzPV=curr_time; + return true; + } + }else{ // KibitzMove + if(curr_time >= (option_get_int("KibitzInterval") + lastKibitzMove)){ + lastKibitzPV=curr_time; + lastKibitzMove=curr_time; + return true; + } + } + return false; +} + // learn() static void learn(int result) {