コード例 #1
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();
   }
}
コード例 #2
0
ファイル: xboard2uci.c プロジェクト: niklasf/polyglot
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;
       }
   }
}
コード例 #3
0
/* function called by children after netvm setup. It reads packets
 * from the queue in the shared memory and writes them to the netvm */
void read_queue_loop(int child_id, nvmAppInterface *nvm_interface)
{
int fd, batch_counter = 0;
int index = 0;					/* index of ready data */
const struct pcap_pkthdr *pkthdr;
const u_char *packet;
struct shmstruct *ptr;
pkt_handle *handle;
my_timer _timer;
char errbuf[1500];
	
	log("child %d starting read_queue", child_id);
	/* first open shared memeory */
	fd = shm_open(TMP_FNAME, O_RDWR , S_IRWXU); /* open */
	if( (ptr = mmap(NULL, sizeof(struct shmstruct), PROT_READ | PROT_WRITE,
					MAP_SHARED, fd, 0)) == MAP_FAILED){
		log("child[%d] cannot open shared mem", child_id);
		exit(-1);
	};
	ftruncate(fd, sizeof(struct shmstruct)); /* resize */
	close(fd);								 /* close fd */

	log("Child %d finished setting up shared mem: ptr %lx", child_id, (long unsigned int) ptr);

	my_timer_start(&_timer);
	/* consumer */
	for ( ; ; ){

		handle = &ptr->queues[index];
		
		if(handle->cap_len <= 0){
			break;
		}
//		ptr->sdatas[child_id].bytes += handle->cap_len;
		if( nvmWriteAppInterface(nvm_interface, (u_int8_t *) handle->pkt_data,
								 handle->cap_len, NULL, errbuf) != nvmSUCCESS)
		{
			fprintf(stderr, "error writing packets to the NetVM application interface\n");
			exit(1);
		}
		index++;
	}
	my_timer_stop(&_timer);
	log("Child[%d] received termination packet", child_id);
	log("Processed %d packets in %f seconds, %f pps", index, my_timer_elapsed(&_timer),
		index/my_timer_elapsed(&_timer));

	exit (0);
}
コード例 #4
0
ファイル: search.cpp プロジェクト: michaeaj/ChessDetection
void search_perft(const board_t * board, int depth_max) {

   int depth;
   my_timer_t timer[1];
   double time, speed;

   ASSERT(board_is_ok(board));
   ASSERT(depth_max>=1&&depth_max<DepthMax);

   // init

   board_disp(board);

   // iterative deepening

   for (depth = 1; depth <= depth_max; depth++) {

      // init

      NodeNb = 0;
      LeafNb = 0;

      my_timer_reset(timer);

      my_timer_start(timer);
      perft(board,depth);
      my_timer_stop(timer);

      time = my_timer_elapsed_cpu(timer);
      speed = (time < 0.01) ? 0.0 : double(NodeNb) / time;

      printf("%2d %10lld %10lld %7.2f %7.0f\n",depth,NodeNb,LeafNb,time,speed);
   }

   printf("\n");
}
コード例 #5
0
ファイル: xboard2uci.c プロジェクト: niklasf/polyglot
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 ;
}