示例#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
static void comp_move(int move) {

   board_t board[1];
   char string[256];

   ASSERT(move_is_ok(move));

   ASSERT(State->state==THINK);
   ASSERT(!XB->analyse);

   if(option_get_bool(Option,"RepeatPV"))
	   send_pv(); // to update time and nodes

   // send the move

   game_get_board(Game,board);

   if (move_is_castle(move,board) && option_get_bool(Option,"Chess960")) {
      if (!move_to_san(move,board,string,256)) my_fatal("comp_move(): move_to_san() failed\n"); // O-O/O-O-O
   } else {
      if (!move_to_can(move,board,string,256)) my_fatal("comp_move(): move_to_can() failed\n");
   }

   gui_send(GUI,"move %s",string);

   // resign?

   if (option_get_bool(Option,"Resign") && Uci->root_move_nb > 1) {

       if (Uci->best_score <= -abs(option_get_int(Option,"ResignScore"))) {

         State->resign_nb++;
         my_log("POLYGLOT %d move%s with resign score\n",State->resign_nb,(State->resign_nb>1)?"s":"");

         if (State->resign_nb >= option_get_int(Option,"ResignMoves")) {
            my_log("POLYGLOT *** RESIGN ***\n");
            gui_send(GUI,"resign");
         }

      } else {

         if (State->resign_nb > 0) my_log("POLYGLOT resign reset (State->resign_nb=%d)\n",State->resign_nb);
         State->resign_nb = 0;
      }
   }

   // play the move

   move_step(move);
   no_mess(move);
}
示例#3
0
static void no_mess(int move) {

   ASSERT(move_is_ok(move));

   // just received a move, calculate the new state

   if (false) {

   } else if (!active()) {

      stop_search(); // abort a possible search

      State->state = WAIT;
      State->exp_move = MoveNone;

      my_log("POLYGLOT WAIT\n");

   } else if (State->state == WAIT) {

      ASSERT(State->computer[game_turn(Game)]);
      ASSERT(!State->computer[colour_opp(game_turn(Game))]);
      ASSERT(!XB->analyse);

      my_log("POLYGLOT WAIT -> THINK\n");

      State->state = THINK;
      State->exp_move = MoveNone;

   } else if (State->state == THINK) {

      ASSERT(!State->computer[game_turn(Game)]);
      ASSERT(State->computer[colour_opp(game_turn(Game))]);
      ASSERT(!XB->analyse);

      if (ponder() && ponder_move_is_ok(Uci->ponder_move)) {

         my_log("POLYGLOT THINK -> PONDER\n");

         State->state = PONDER;
         State->exp_move = Uci->ponder_move;

      } else {

         my_log("POLYGLOT THINK -> WAIT\n");

         State->state = WAIT;
         State->exp_move = MoveNone;
      }

   } else if (State->state == PONDER) {

      ASSERT(State->computer[game_turn(Game)]);
      ASSERT(!State->computer[colour_opp(game_turn(Game))]);
      ASSERT(!XB->analyse);

      if (move == State->exp_move && Uci->searching) {

         ASSERT(Uci->searching);
         ASSERT(Uci->pending_nb>=1);

         my_timer_reset(State->timer);
         my_timer_start(State->timer);

         my_log("POLYGLOT PONDER -> THINK (*** HIT ***)\n");
         engine_send(Engine,"ponderhit");

         State->state = THINK;
         State->exp_move = MoveNone;

         send_pv(); // update display

         return; // do not launch a new search

      } else {

         my_log("POLYGLOT PONDER -> THINK (miss)\n");

         stop_search();

         State->state = THINK;
         State->exp_move = MoveNone;
      }

   } else if (State->state == ANALYSE) {

      ASSERT(XB->analyse);

      my_log("POLYGLOT ANALYSE -> ANALYSE\n");

      stop_search();

   } else {

      ASSERT(false);
   }

   search_update();
}
示例#4
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();
		}
}
示例#5
0
static void comp_move(int move) {

	board_t board[1];
	char string[256];

	ASSERT(move_is_ok(move));

	ASSERT(State->state==THINK);
	ASSERT(!XB->analyse);

	if(option_get_bool("RepeatPV")==true)
		send_pv(); // to update time and nodes

	// send the move

	game_get_board(Game,board);

	if (move_is_castle(move,board) && option_get_bool("Chess960")) {
		if (!move_to_san(move,board,string,sizeof(string))) my_fatal("comp_move(): move_to_san() failed\n"); // O-O/O-O-O
	} else {
		if (!move_to_can(move,board,string,sizeof(string))) my_fatal("comp_move(): move_to_can() failed\n");
	}

	move_step(move);
	//game ended?
	if(game_status(Game)!= PLAYING){
		//handle ics drawing stuff
		if(XB->ics){
			switch (game_status(Game)){
			case DRAW_MATERIAL:
			case DRAW_FIFTY:
			case DRAW_REPETITION:
				xboard_send(XBoard,"offer draw");
				break;
			default:
				break;
			}
		}
		xboard_send(XBoard,"move %s",string);
		board_update();
		no_mess(move);
		return;
	}

	// engine sended a move while in ponder mode? 
	if(State->state==PONDER){
		if(board->turn==White)
			xboard_send(XBoard,"0-1 {polyglot : engine moves while pondering}\n");
		else
			xboard_send(XBoard,"1-0 {polyglot : engine moves while pondering}\n");
	}
	// resign?
	if (option_get_bool("Resign") && Uci->root_move_nb > 1) {
		int best = Uci->best_score;
		if (option_get_bool("ScoreWhite") && colour_is_black(Uci->board->turn))
			best = -best;

		if (best <= -abs(option_get_int("ResignScore"))) {

			State->resign_nb++;
			my_log("POLYGLOT %d move%s with resign score\n",State->resign_nb,(State->resign_nb>1)?"s":"");

			if (State->resign_nb >= option_get_int("ResignMoves")) {
				my_log("POLYGLOT *** RESIGN ***\n");
				//send move and resign
				//xboard_send(XBoard,"move %s \nresign",string);
				//just resign
				xboard_send(XBoard,"resign",string);
				no_mess(move);
				return;
			}
		} else {
			if (State->resign_nb > 0) my_log("POLYGLOT resign reset (State->resign_nb=%d)\n",State->resign_nb);
			State->resign_nb = 0;
		}
	}
	no_mess(move);
	xboard_send(XBoard,"move %s",string);
}
示例#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 ;
}