void uci_open(uci_t * uci, engine_t * engine) { char string[StringSize]; int event; ASSERT(uci!=NULL); ASSERT(engine!=NULL); // init uci->engine = engine; uci->name = NULL; my_string_set(&uci->name,"<empty>"); uci->author = NULL; my_string_set(&uci->author,"<empty>"); uci->option_nb = 0; uci->ready_nb = 0; uci->searching = 0; uci->pending_nb = 0; uci->multipv_mode = false; board_start(uci->board); uci_clear(uci); // send "uci" and wait for "uciok" engine_send(uci->engine,"uci"); do { engine_get(uci->engine,string,StringSize); event = uci_parse(uci,string); } while (!engine_eof(Engine) && (event & EVENT_UCI) == 0); }
static void engine_step() { char string[StringSize]; int event; // parse UCI line engine_get(Engine,string,StringSize); event = uci_parse(Uci,string); // react to events if ((event & EVENT_READY) != 0) { // the engine is now ready if (!Uci->ready) { Uci->ready = true; if (XB->proto_ver >= 2) xboard_send(XBoard,"feature done=1"); } if (!DelayPong && XB->ping >= 0) { xboard_send(XBoard,"pong %d",XB->ping); XB->ping = -1; } } if ((event & EVENT_MOVE) != 0 && State->state == THINK) { // the engine is playing a move // MEGA HACK: estimate remaining time because XBoard won't send it! my_timer_stop(State->timer); XB->my_time -= my_timer_elapsed_real(State->timer); XB->my_time += XB->inc; if (XB->mps != 0 && (game_move_nb(Game) + 1) % XB->mps == 0) XB->my_time += XB->base; if (XB->my_time < 0.0) XB->my_time = 0.0; // play the engine move comp_move(Uci->best_move); } if ((event & EVENT_PV) != 0) { // the engine has sent a new PV send_pv(); } }
void uci_send_isready_sync(uci_t * uci) { char string[StringSize]; int event; ASSERT(uci_is_ok(uci)); // send "isready" and wait for "readyok" uci_send_isready(uci); do { engine_get(uci->engine,string,StringSize); event = uci_parse(uci,string); } while (!engine_eof(Engine) && (event & EVENT_READY) == 0); }
void uci_send_stop_sync(uci_t * uci) { char string[StringSize]; int event; ASSERT(uci_is_ok(uci)); ASSERT(uci->searching); ASSERT(uci->pending_nb>=1); // send "stop" and wait for "bestmove" uci_send_stop(uci); do { engine_get(uci->engine,string,StringSize); event = uci_parse(uci,string); } while (!engine_eof(Engine) && (event & EVENT_STOP) == 0); }
static bool engine_step() { char string[StringSize]; int event; engine_get(Engine,string,StringSize); event = uci_parse(Uci,string); if ((event & EVENT_MOVE) != 0) { return false; } if ((event & EVENT_PV) != 0) { LastMove = Uci->best_pv[0]; LastDepth = Uci->best_depth; LastSelDepth = Uci->best_sel_depth; LastScore = Uci->best_score; LastTime = Uci->time; LastNodeNb = Uci->node_nb; line_copy(LastPV,Uci->best_pv); if (LastMove != FirstMove) { FirstMove = LastMove; FirstDepth = LastDepth; FirstSelDepth = LastSelDepth; FirstScore = LastScore; FirstTime = LastTime; FirstNodeNb = LastNodeNb; line_copy(FirstPV,LastPV); } } return true; }
void xboard2uci_engine_step(char string[]) { int event; board_t board[1]; event = uci_parse(Uci,string); // react to events if ((event & EVENT_READY) != 0) { // the engine is now ready if (!Uci->ready) { Uci->ready = TRUE; // if (XB->proto_ver >= 2) xboard_send(XBoard,"feature done=1"); } if (!DelayPong && XB->ping >= 0) { gui_send(GUI,"pong %d",XB->ping); XB->ping = -1; } } if ((event & EVENT_MOVE) != 0 && State->state == THINK) { // the engine is playing a move // MEGA HACK: estimate remaining time because XBoard won't send it! my_timer_stop(State->timer); XB->my_time -= my_timer_elapsed_real(State->timer); XB->my_time += XB->inc; if (XB->mps != 0 && (game_move_nb(Game) + 1) % XB->mps == 0) XB->my_time += XB->base; if (XB->my_time < 0.0) XB->my_time = 0.0; // make sure to remember the ponder move State->hint_move=Uci->ponder_move; // play the engine move comp_move(Uci->best_move); } if ((event & EVENT_PV) != 0) { // the engine has sent a new PV send_pv(); } if ((event & EVENT_INFO) != 0) { // the engine has sent info send_info(); } if((event & (EVENT_DRAW|EVENT_RESIGN))!=0){ my_log("POYGLOT draw offer/resign from engine\n"); if(option_find(Uci->option,"UCI_DrawOffers")){ if(event & EVENT_DRAW) gui_send(GUI,"offer draw"); else gui_send(GUI,"resign"); } } 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 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(); } }
static void engine_step() { char string[StringSize]; int event; // parse UCI line engine_get(Engine,string,StringSize); //blocking read... event = uci_parse(Uci,string); // react to events if ((event & EVENT_READY) != 0) { #ifdef _WIN32 SetEvent(Engine_ready_ok); #endif if (!Uci->ready) { Uci->ready = true; if (XB->proto_ver >= 2) xboard_send(XBoard,"feature done=1"); } if (!DelayPong && XB->ping >= 0) { xboard_send(XBoard,"pong %d",XB->ping); XB->ping = -1; } } if ((event & EVENT_MOVE) != 0 && State->state == THINK) { // the engine is playing a move // MEGA HACK: estimate remaining time because XBoard won't send it! my_timer_stop(State->timer); XB->my_time -= my_timer_elapsed_real(State->timer); XB->my_time += XB->inc; if (XB->mps != 0 && (game_move_nb(Game) + 1) % XB->mps == 0) XB->my_time += XB->base; if (XB->my_time < 0.0) XB->my_time = 0.0; // play the engine move comp_move(Uci->best_move); } if ((event & EVENT_PV) != 0) { // the engine has sent a new PV send_pv(); } if ((event & EVENT_INFO) != 0){ if(!option_get_bool("InfoStrings")) xboard_send(XBoard,"#%d %+d %.0f " S64_FORMAT " %s ",Uci->best_depth,Uci->best_score,Uci->time*100.0,Uci->node_nb,Uci->info_string); else xboard_send(XBoard,"%d %+d %.0f " S64_FORMAT " %s ",Uci->best_depth,Uci->best_score,Uci->time*100.0,Uci->node_nb,Uci->info_string); } if((event & (EVENT_DRAW|EVENT_RESIGN))!=0){ my_log("POYGLOT draw offer/resign from engine\n"); if(uci_option_exist(Uci,"UCI_DrawOffers")){ if(event & EVENT_DRAW) xboard_send(XBoard,"offer draw"); else xboard_send(XBoard,"resign"); } } return ; }