X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard2uci.c;h=80e0a623a9e861d07ba8b9958048e6f38a3684a9;hb=e516b96c20d27e7d86d3485b010d6d48cecec9f1;hp=2097de919bfeda018126fd614feba00940286dae;hpb=ac968003c13bde5c86ffa19f8819e436b5bc03e6;p=polyglot.git diff --git a/xboard2uci.c b/xboard2uci.c index 2097de9..80e0a62 100644 --- a/xboard2uci.c +++ b/xboard2uci.c @@ -75,6 +75,8 @@ typedef struct { double my_time; double opp_time; + + int node_rate; } xb_t; typedef enum { WAIT, THINK, PONDER, ANALYSE } dummy_state_t; @@ -165,6 +167,8 @@ void xboard2uci_init() { XB->my_time = 300.0; XB->opp_time = 300.0; + + XB->node_rate = -1; } // xboard2uci_gui_step() @@ -301,7 +305,7 @@ void xboard2uci_gui_step(char string[]) { } else if (match(string,"new")) { - uci_send_isready(Uci); + uci_send_isready_sync(Uci); my_log("POLYGLOT NEW GAME\n"); option_set(Option,"Chess960","false"); @@ -320,6 +324,7 @@ void xboard2uci_gui_step(char string[]) { XB->result = FALSE; XB->depth_limit = FALSE; + XB->node_rate=-1; XB->computer = FALSE; my_string_set(&XB->name,""); @@ -351,12 +356,15 @@ void xboard2uci_gui_step(char string[]) { if (DelayPong) { if (XB->ping >= 0) gui_send(GUI,"pong %d",XB->ping); // HACK: get rid of old ping XB->ping = atoi(Star[0]); - uci_send_isready(Uci); + uci_send_isready_sync(Uci); } else { ASSERT(XB->ping==-1); gui_send(GUI,"pong %s",Star[0]); } - + } else if (match(string,"nps *")) { + + // fake WB play-by-nodes mode + XB->node_rate = atoi(Star[0]); } else if (match(string,"playother")) { State->computer[game_turn(Game)] = FALSE; @@ -744,18 +752,18 @@ void xboard2uci_engine_step(char string[]) { } } if(((event & EVENT_ILLEGAL_MOVE)!=0) && (State->state == THINK)){ - game_get_board(Game,board); - if(board->turn==White){ - gui_send(GUI,"0-1 {polyglot: resign" - " (illegal engine move white)}"); - }else{ - gui_send(GUI,"1-0 {polyglot: resign" - " (illegal engine move black)}"); - } - board_disp(board); - XB->result = TRUE; - mess(); - } + game_get_board(Game,board); + if(board->turn==White){ + gui_send(GUI,"0-1 {polyglot: resign" + " (illegal engine move by white: %s)}",Uci->bestmove); + }else{ + gui_send(GUI,"1-0 {polyglot: resign" + " (illegal engine move by black: %s)}",Uci->bestmove); + } + board_disp(board); + XB->result = TRUE; + mess(); + } } // format_xboard_option_line @@ -774,7 +782,7 @@ void format_xboard_option_line(char * option_line, option_t *opt){ strcat(option_line,option_string); sprintf(option_string," -%s",opt->type); strcat(option_line,option_string); - if(!IS_BUTTON(opt) && strcmp(opt->type,"combo")){ + if(!IS_BUTTON(opt->type) && strcmp(opt->type,"combo")){ if(strcmp(opt->type,"check")){ sprintf(option_string," %s",opt->value); }else{ @@ -785,11 +793,11 @@ void format_xboard_option_line(char * option_line, option_t *opt){ } strcat(option_line,option_string); } - if(IS_SPIN(opt)){ + if(IS_SPIN(opt->type)){ sprintf(option_string," %s",opt->min); strcat(option_line,option_string); } - if(IS_SPIN(opt)){ + if(IS_SPIN(opt->type)){ sprintf(option_string," %s",opt->max); strcat(option_line,option_string); } @@ -830,6 +838,7 @@ static void send_xboard_options(){ gui_send(GUI,"feature pause=0"); gui_send(GUI,"feature ping=1"); gui_send(GUI,"feature playother=1"); + gui_send(GUI,"feature sigint=1"); gui_send(GUI,"feature reuse=1"); gui_send(GUI,"feature san=0"); gui_send(GUI,"feature setboard=1"); @@ -837,6 +846,7 @@ static void send_xboard_options(){ gui_send(GUI,"feature sigterm=0"); gui_send(GUI,"feature time=1"); gui_send(GUI,"feature usermove=1"); + gui_send(GUI,"feature nps=1"); if (XB->has_feature_memory){ gui_send(GUI,"feature memory=1"); }else{ @@ -1281,30 +1291,63 @@ static void search_update() { if (XB->time_limit) { // fixed time per move - - engine_send_queue(Engine," movetime %.0f",XB->time_max*1000.0); + + if(XB->node_rate > 0){ + engine_send_queue(Engine, + " nodes %.0f", + XB->time_max*((double)XB->node_rate)); + }else{ + engine_send_queue(Engine, + " movetime %.0f", + XB->time_max*1000.0); + } } else { // time controls - if (colour_is_white(Uci->board->turn)) { - engine_send_queue(Engine," wtime %.0f btime %.0f",XB->my_time*1000.0,XB->opp_time*1000.0); - } else { - engine_send_queue(Engine," wtime %.0f btime %.0f",XB->opp_time*1000.0,XB->my_time*1000.0); - } - - if (XB->inc != 0.0) engine_send_queue(Engine," winc %.0f binc %.0f",XB->inc*1000.0,XB->inc*1000.0); - - if (XB->mps != 0) { - - move_nb = XB->mps - (Uci->board->move_nb % XB->mps); - ASSERT(move_nb>=1&&move_nb<=XB->mps); - - engine_send_queue(Engine," movestogo %d",move_nb); - } + if(XB->node_rate > 0) { + double time; + move_nb = 40; + if (XB->mps != 0){ + move_nb = XB->mps - (Uci->board->move_nb % XB->mps); + } + time = XB->my_time / move_nb; + if(XB->inc != 0){ + time += XB->inc; + } + if(time > XB->my_time){ + time = XB->my_time; + } + engine_send_queue(Engine, + " nodes %.0f", + time*XB->node_rate); + } else { + + if (colour_is_white(Uci->board->turn)) { + engine_send_queue(Engine, + " wtime %.0f btime %.0f", + XB->my_time*1000.0,XB->opp_time*1000.0); + } else { + engine_send_queue(Engine, + " wtime %.0f btime %.0f", + XB->opp_time*1000.0,XB->my_time*1000.0); + } + + if (XB->inc != 0.0){ + engine_send_queue(Engine, + " winc %.0f binc %.0f", + XB->inc*1000.0,XB->inc*1000.0); + } + if (XB->mps != 0) { + + move_nb = XB->mps - (Uci->board->move_nb % XB->mps); + ASSERT(move_nb>=1&&move_nb<=XB->mps); + + engine_send_queue(Engine," movestogo %d",move_nb); + } + } } - if (XB->depth_limit) engine_send_queue(Engine," depth %d",XB->depth_max); if (State->state == PONDER) engine_send_queue(Engine," ponder");