void adapter_loop() { // init game_clear(Game); // state State->state = WAIT; State->computer[White] = false; State->computer[Black] = true; State->exp_move = MoveNone; State->resign_nb = 0; my_timer_reset(State->timer); #ifndef _WIN32 // xboard XBoard->io->in_fd = STDIN_FILENO; XBoard->io->out_fd = STDOUT_FILENO; XBoard->io->name = "XBOARD"; io_init(XBoard->io); #endif XB->analyse = false; XB->computer = false; XB->name = NULL; my_string_set(&XB->name,"<empty>"); XB->ics = false; XB->new_hack = true; XB->ping = -1; XB->ponder = false; XB->post = false; XB->proto_ver = 1; XB->result = false; XB->mps = 0; XB->base = 300.0; XB->inc = 0.0; XB->time_limit = false; XB->time_max = 5.0; XB->depth_limit = false; XB->depth_max = 127; XB->my_time = 300.0; XB->opp_time = 300.0; #ifdef _WIN32 // loop while(true) engine_step(); #else while (true) adapter_step(); #endif }
static void adapter_step() { fd_set set[1]; int fd_max; int val; // process buffered lines while (io_line_ready(XBoard->io)) xboard_step(); // process available xboard lines while (io_line_ready(Engine->io)) engine_step(); // process available engine lines // init FD_ZERO(set); fd_max = -1; // HACK // add xboard input ASSERT(XBoard->io->in_fd>=0); FD_SET(XBoard->io->in_fd,set); if (XBoard->io->in_fd > fd_max) fd_max = XBoard->io->in_fd; // add engine input ASSERT(Engine->io->in_fd>=0); FD_SET(Engine->io->in_fd,set); if (Engine->io->in_fd > fd_max) fd_max = Engine->io->in_fd; // wait for something to read (no timeout) ASSERT(fd_max>=0); val = select(fd_max+1,set,NULL,NULL,NULL); if (val == -1 && errno != EINTR) my_fatal("adapter_step(): select(): %s\n",strerror(errno)); if (val > 0) { if (FD_ISSET(XBoard->io->in_fd,set)) io_get_update(XBoard->io); // read some xboard input if (FD_ISSET(Engine->io->in_fd,set)) io_get_update(Engine->io); // read some engine input } }
static void epd_test_file(const char file_name[]) { FILE * file; int hit, tot; char epd[StringSize]; char am[StringSize], bm[StringSize], id[StringSize]; board_t board[1]; char string[StringSize]; int move; char pv_string[StringSize]; bool correct; double depth_tot, time_tot, node_tot; ASSERT(file_name!=NULL); // init file = fopen(file_name,"r"); if (file == NULL) my_fatal("epd_test_file(): can't open file \"%s\": %s\n",file_name,strerror(errno)); hit = 0; tot = 0; depth_tot = 0.0; time_tot = 0.0; node_tot = 0.0; // loop while (my_file_read_line(file,epd,StringSize)) { if (UseTrace) printf("%s\n",epd); if (!epd_get_op(epd,"am",am,StringSize)) strcpy(am,""); if (!epd_get_op(epd,"bm",bm,StringSize)) strcpy(bm,""); if (!epd_get_op(epd,"id",id,StringSize)) strcpy(id,""); if (my_string_empty(am) && my_string_empty(bm)) { my_fatal("epd_test(): no am or bm field in EPD\n"); } // init uci_send_ucinewgame(Uci); uci_send_isready_sync(Uci); ASSERT(!Uci->searching); // position if (!board_from_fen(board,epd)) ASSERT(false); if (!board_to_fen(board,string,StringSize)) ASSERT(false); engine_send(Engine,"position fen %s",string); // search engine_send(Engine,"go movetime %.0f depth %d",MaxTime*1000.0,MaxDepth); // engine_send(Engine,"go infinite"); // engine data board_copy(Uci->board,board); uci_clear(Uci); Uci->searching = true; Uci->pending_nb++; FirstMove = MoveNone; FirstDepth = 0; FirstSelDepth = 0; FirstScore = 0; FirstTime = 0.0; FirstNodeNb = 0; line_clear(FirstPV); LastMove = MoveNone; LastDepth = 0; LastSelDepth = 0; LastScore = 0; LastTime = 0.0; LastNodeNb = 0; line_clear(LastPV); // parse engine output while (engine_step()) { // stop search? if (Uci->depth > MaxDepth || Uci->time >= MaxTime || (Uci->depth - FirstDepth >= DepthDelta && Uci->depth > MinDepth && Uci->time >= MinTime && is_solution(FirstMove,board,bm,am))) { engine_send(Engine,"stop"); } } move = FirstMove; correct = is_solution(move,board,bm,am); if (correct) hit++; tot++; if (correct) { depth_tot += double(FirstDepth); time_tot += FirstTime; node_tot += double(FirstNodeNb); } printf("%s %d %4d %4d",id,correct,hit,tot); if (!line_to_san(LastPV,Uci->board,pv_string,StringSize)) ASSERT(false); printf(" - %2d %6.2f %9lld %+6.2f %s\n",FirstDepth,FirstTime,FirstNodeNb,double(LastScore)/100.0,pv_string); } printf("%d/%d",hit,tot); if (hit != 0) { depth_tot /= double(hit); time_tot /= double(hit); node_tot /= double(hit); printf(" - %.1f %.2f %.0f",depth_tot,time_tot,node_tot); } printf("\n"); fclose(file); }