Пример #1
0
void search_update_current() {

	my_timer_t *timer = SearchCurrent->timer;
	S64 node_nb = SearchCurrent->node_nb;
	const double time = (UseCpuTime) ? my_timer_elapsed_cpu(timer) : my_timer_elapsed_real(timer),
		speed = (time >= 1.0) ? double(node_nb) / time : 0.0, cpu = my_timer_cpu_usage(timer);

	SearchCurrent->time = time;
	SearchCurrent->speed = speed;
	SearchCurrent->cpu = cpu;
}
Пример #2
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();
   }
}
Пример #3
0
static void update_remaining_time(){
   double reduce;
   if(State->timer->running){
       my_timer_stop(State->timer);
       reduce = my_timer_elapsed_real(State->timer);
       my_log("POLYGLOT reducing remaing time by %f seconds\n",reduce);
       XB->my_time -= reduce;
       if(XB->my_time<0.0){
           XB->my_time=0.0;
       }
   }
}
Пример #4
0
double my_timer_cpu_usage(const my_timer_t * timer) {

   double real, cpu;
   double usage;

   ASSERT(timer!=NULL);

   real = my_timer_elapsed_real(timer);
   cpu = my_timer_elapsed_cpu(timer);

   if (real <= 0.0 || cpu <= 0.0) return 0.0;

   usage = cpu / real;
   if (usage >= 1.0) usage = 1.0;

   return usage;
}
Пример #5
0
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();
		}
}
Пример #6
0
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 ;
}