Esempio n. 1
0
static void parse_option() {

	const char * file_name;
	FILE * file;
	char line[256];
	char * name, * value;

	file_name = option_get_string("OptionFile");

	file = fopen(file_name,"r");
	if (file == NULL) my_fatal("Can't open file \"%s\": %s\n",file_name,strerror(errno));

	// PolyGlot options (assumed first)

	while (true) {

		if (!my_file_read_line(file,line,256)) {
			my_fatal("parse_option(): missing [Engine] section\n");
		}

		if (my_string_case_equal(line,"[engine]")) break;

		if (parse_line(line,&name,&value)) option_set(name,value);
	}

	if (option_get_bool("Log")) {
		my_log_open(option_get_string("LogFile"));
	}

	my_log("POLYGLOT %s *** START ***\n",Version);
	my_log("POLYGLOT INI file \"%s\"\n",file_name);
	engine_open(Engine);

	Init = true; 
	uci_open(Uci,Engine);

	while (my_file_read_line(file,line,256)) {

		if (line[0] == '[') my_fatal("parse_option(): unknown section %s\n",line);

		if (parse_line(line,&name,&value)) {

			uci_send_option(Uci,name,"%s",value);
			//to get a decent display in winboard_x we need to now if an engine really is doing multipv analysis
			// "multipv 1" in the pv is meaningless,f.i. toga sends that all the time
			//therefore check if MultiPV is set to a decent value in the polyglot ini file
			if(my_string_case_equal(name,"MultiPV") && atoi(value)>1)  Uci->multipv_mode=true;
		}
	}

	uci_send_isready(Uci);

	fclose(file);

	if (my_string_equal(option_get_string("EngineName"),"<empty>")) {
		option_set("EngineName",Uci->name);
	}
}
Esempio n. 2
0
void get(char string[], int size) {

   ASSERT(string!=NULL);
   ASSERT(size>=65536);

   if (!my_file_read_line(stdin,string,size)) { // EOF
      exit(EXIT_SUCCESS);
   }
}
Esempio n. 3
0
static void get_stdin(char string[], int size) {

   FILE * file;

   ASSERT(string!=NULL);
   ASSERT(size>=65536);

   if (!my_file_read_line(stdin,string,size)) { // EOF
      exit(EXIT_SUCCESS);
   }

   // log

   if (option_get_bool("Log")) {
      file = fopen("fruit.log","a");
      if (file != NULL) {
         fprintf(file,"< %s\n",string);
         fclose(file);
      }
   }
}
Esempio n. 4
0
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);
}
Esempio n. 5
0
static void parse_option() {

	const char * file_name;
	FILE * file;
	char line[256];
	char * name, * value;

	file_name = option_get_string("OptionFile");

	file = fopen(file_name,"r");
	if (file == NULL)
		my_fatal("Can't open file \"%s\": %s\n",file_name,strerror(errno));

	// PolyGlot options (assumed first)

	//read the ini file,and store the name/value pairs
	while (true) {

		if (!my_file_read_line(file,line,sizeof(line))) {
			my_fatal("parse_option(): missing [Engine] section\n");
		}

		if (my_string_case_equal(line,"[engine]")) break;

		if (parse_line(line,&name,&value)) option_set(name,value);

	}
	if (option_get_bool("Log")) { my_log_open(option_get_string("LogFile"));}

	while (my_file_read_line(file,line,sizeof(line))) {

		if (line[0] == '[') my_fatal("parse_option(): unknown section %s\n",line);

		if (parse_line(line,&name,&value)) {
			uci_option_store(name,value);
		}
	}
	fclose(file);
	//read the optional global.ini file
	if(!option_get_bool("NoGlobals")){
		file=fopen("globals.ini","r");
		//override settings,if any
		if(file!=NULL){
			while (true) {
				if (!my_file_read_line(file,line,sizeof(line))) {
					my_fatal("parse_option(): missing [Engine] section\n");
				}

				if (my_string_case_equal(line,"[engine]")) break;

				if (parse_line(line,&name,&value)){
					if(!my_string_case_equal(name,"LogFile"))
						option_set(name,value);
				}
			}

			if (option_get_bool("Log")) {
				my_log_open(option_get_string("LogFile"));
			}
			else my_log_close(); //close it 

			while (my_file_read_line(file,line,sizeof(line))) {

				if (line[0] == '[') my_fatal("parse_option(): unknown section %s\n",line);

				if (parse_line(line,&name,&value)) {
					uci_option_store(name,value);
				}
			}
			fclose(file);
		}
	}
	my_log("POLYGLOT %s *** START ***\n",Version);
	my_log("POLYGLOT INI file \"%s\"\n",file_name);
	//do the dump:
	engine_open(Engine);
	Init = true; 
	uci_open(Uci,Engine);
	uci_option_t *next;
	init_uci_list(&next);
	while(next!=NULL){
		if(next->var==NULL) break;
		uci_send_option(Uci,next->var,"%s",next->val);
		if(my_string_case_equal(next->var,"MultiPV") && atoi(next->val)>1)  Uci->multipv_mode=true;
		next=next->next;
	}
	uci_send_isready(Uci);

	if (my_string_equal(option_get_string("EngineName"),"<empty>")) {
		option_set("EngineName",Uci->name);
	}
}