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
static void parse_util_args (int argc, char *argv[], FileList *f){
  char  c;

  if (argc == 0) {
    fputs (usage, stderr);
    exit  (1);
  }

  iparam_set("Dump", 0);

  while (--argc && (*++argv)[0] == '-') {
    while (c = *++argv[0])                  /* more to parse... */
      switch (c) {

      case 'c':
  option_set("CONCATENATEDFILE",1);
  break;

      case 'd':
  if (*++argv[0])
    iparam_set("Dump", atoi(*argv));
  else {
    iparam_set("Dump", atoi(*++argv));
    argc--;
  }
  (*argv)[1] = '\0';
  break;
      case 'p':
  if (*++argv[0])
    option_set("Nfiles", atoi(*argv));
  else {
    option_set("Nfiles", atoi(*++argv));
    argc--;
  }
  (*argv)[1] = '\0';
  break;
      case 't':
  option_set("Totheader",1);
  break;
      default:
  fprintf(stderr, "%s: unknown option -- %c\n", prog, c);
  break;
      }
  }
  f->in.name = strdup(*argv);
  /* open input file */

  if (option("verbose")) {
    fprintf (stderr, "%s: in = %s, rea = %s, out = %s\n", prog,
       f->in.name   ? f->in.name   : "<stdin>",  f->rea.name,
       f->out.name  ? f->out.name  : "<stdout>");
  }

  return;
}
Esempio n. 3
0
static void parse_setoption(char string[]) {

   const char * name;
   char * value;

   // init

   name = strstr(string,"name ");
   value = strstr(string,"value ");

   if (name == NULL || value == NULL || name >= value) return; // ignore buttons

   value[-1] = '\0'; // HACK
   name += 5;
   value += 6;

   // update

   option_set(name,value);

   // update transposition-table size if needed

   if (Init && my_string_equal(name,"Hash")) { // Init => already allocated

      ASSERT(!Searching);

      if (option_get_int("Hash") >= 4) {
         trans_free(Trans);
         trans_alloc(Trans);
      }
   }
}
Esempio n. 4
0
void option_init_pg() {

    int i;
    option_t *p=DefaultOptions;
    char *home_dir;
    char SettingsDir[StringSize];
    
    option_init(Option);
    while(p){
        if(p->name){
            option_insert(Option,p);
            p++;
        }else{
            break;
        }
    }
    for(i=0;i<Option->option_nb;i++){
        Option->options[i].value=my_strdup(Option->options[i].default_);
    }
#ifndef _WIN32
    home_dir=getenv("HOME");
    if(!home_dir){
        home_dir=".";
    }
    snprintf(SettingsDir,sizeof(SettingsDir),"%s/.polyglot",home_dir);
    SettingsDir[sizeof(SettingsDir)-1]='\0';
#else
    sprintf(SettingsDir,".\\_PG");
#endif
    option_set(Option,"SettingsDir",SettingsDir);
    option_set_default(Option,"SettingsDir",SettingsDir);
}
Esempio n. 5
0
void option_init() {

   option_t * opt;

   for (opt = &Option[0]; opt->var != NULL; opt++) {
      option_set(opt->var,opt->init);
   }
}
Esempio n. 6
0
/* Menu command: toggle birth_keep_randarts option. */
static void death_randarts(const char *title, int row)
{
	if (p_ptr->randarts)
		option_set(option_name(OPT_birth_keep_randarts),
			get_check("Keep randarts for next game? "));
	else
		msg("You are not playing with randarts!");
}
Esempio n. 7
0
void option_from_ini(option_list_t *option,
                     ini_t *ini,
                     const char *section){
    ini_entry_t *entry;
    ini_start_iter(ini);
    while((entry=ini_next(ini))){
        option_set(option,entry->name,entry->value);
        option_set_default(option,entry->name,entry->value);
    }
}
Esempio n. 8
0
static enum parser_error parse_prefs_y(struct parser *p)
{
	struct prefs_data *d = parser_priv(p);
	assert(d != NULL);
	if (d->bypass) return PARSE_ERROR_NONE;

	option_set(parser_getstr(p, "option"), TRUE);

	return PARSE_ERROR_NONE;
}
Esempio n. 9
0
static enum parser_error parse_prefs_x(struct parser *p)
{
	struct prefs_data *d = parser_priv(p);
	assert(d != NULL);
	if (d->bypass) return PARSE_ERROR_NONE;

	/* XXX check for valid option */
	option_set(parser_getstr(p, "option"), FALSE);

	return PARSE_ERROR_NONE;
}
Esempio n. 10
0
/**
 * Handle keypresses for an option entry.
 */
static bool option_toggle_handle(struct menu *m, const ui_event *event,
		int oid)
{
	bool next = false;

	if (event->type == EVT_SELECT) {
		/* Hack -- birth options can not be toggled after birth */
		/* At birth, m->flags == MN_DBL_TAP. */
		/* After birth, m->flags == MN_NO_TAGS */
		if (!((option_type(oid) == OP_BIRTH) && (m->flags == MN_NO_TAGS))) {
			option_set(option_name(oid), !op_ptr->opt[oid]);
		}
	} else if (event->type == EVT_KBRD) {
		if (event->key.code == 'y' || event->key.code == 'Y') {
			option_set(option_name(oid), true);
			next = true;
		} else if (event->key.code == 'n' || event->key.code == 'N') {
			option_set(option_name(oid), false);
			next = true;
		} else if (event->key.code == 't' || event->key.code == 'T') {
			option_set(option_name(oid), !op_ptr->opt[oid]);
		} else if (event->key.code == '?') {
			screen_save();
			show_file(format("option.txt#%s", option_name(oid)), NULL, 0, 0);
			screen_load();
		} else {
			return false;
		}
	} else {
		return false;
	}

	if (next) {
		m->cursor++;
		m->cursor = (m->cursor + m->filter_count) % m->filter_count;
	}

	return true;
}
Esempio n. 11
0
/**
 * Handle keypresses for an option entry.
 */
static bool option_toggle_handle(menu_type *m, const ui_event *event,
		int oid)
{
	bool next = false;

	if (event.type == EVT_SELECT) {
		/* Hack -- birth options can not be toggled after birth */
		/* At birth, m.flags == MN_DBL_TAP. After birth, m.flags == MN_NO_TAGS */
		if (!(OPT_BIRTH <= oid && oid <= OPT_BIRTH + N_OPTS_BIRTH - 1 && m.flags == MN_NO_TAGS)) {
			option_set(option_name(oid), !op_ptr.opt[oid]);
		}
	} else if (event.type == EVT_KBRD) {
		if (event.key.code == 'y' || event.key.code == 'Y') {
			option_set(option_name(oid), true);
			next = true;
		} else if (event.key.code == 'n' || event.key.code == 'N') {
			option_set(option_name(oid), false);
			next = true;
		} else if (event.key.code == '?') {
			screen_save();
			show_file(format("option.txt#%s", option_name(oid)), null, 0, 0);
			screen_load();
		} else {
			return false;
		}
	} else {
		return false;
	}

	if (next) {
		m.cursor++;
		m.cursor = (m.cursor + m.filter_count) % m.filter_count;
	}

	return true;
}
Esempio n. 12
0
/**
 * Handle keypresses for an option entry.
 */
static bool option_toggle_handle(menu_type *m, const ui_event *event,
		int oid)
{
	bool next = FALSE;

	if (event->type == EVT_SELECT) {
		/* Hack -- birth options can not be toggled after birth */
		/* At birth, m->flags == MN_DBL_TAP. After birth, m->flags == MN_NO_TAGS */
		if (!(OPT_BIRTH <= oid && oid <= OPT_BIRTH + N_OPTS_BIRTH - 1 && m->flags == MN_NO_TAGS)) {
			option_set(option_name(oid), !op_ptr->opt[oid]);
		}
	} else if (event->type == EVT_KBRD) {
		if (event->key.code == 'y' || event->key.code == 'Y') {
			option_set(option_name(oid), TRUE);
			next = TRUE;
		} else if (event->key.code == 'n' || event->key.code == 'N') {
			option_set(option_name(oid), FALSE);
			next = TRUE;
		} else if (event->key.code == '?') {
			screen_save();
			show_file(format("option.txt#%s", option_name(oid)), NULL, 0, 0);
			screen_load();
		} else {
			return FALSE;
		}
	} else {
		return FALSE;
	}

	if (next) {
		m->cursor++;
		m->cursor = (m->cursor + m->filter_count) % m->filter_count;
	}

	return TRUE;
}
Esempio n. 13
0
void
add_run(struct text *txt0, unsigned int i0,
	struct text *txt1, unsigned int i1,
	unsigned int size
) {
	/*	Adds the run of given size to our collection.
	*/
	register struct run *r = (struct run *)malloc(sizeof (struct run));

	if (!r) fatal("out of memory");
	set_chunk(&r->rn_cn0, txt0, i0 - txt0->tx_start, size);
	set_chunk(&r->rn_cn1, txt1, i1 - txt1->tx_start, size);
	r->rn_size = size;

	if (option_set('p') ? add_to_percentages(r) : add_to_runs(r)) {
		/* OK */
	}
	else	fatal("out of memory");
}
Esempio n. 14
0
/** \brief
 *
 *  \param ctx
 *  \param fp
 *
 *  \return Number of options set
 */
int iniread_file(configctx_t *ctx, FILE *fp)
{
    char        buffer[LIBINI_LINE_MAX];
    char       *start,*ptr;
    int         ret = 0;
    
    while (fgets(buffer,sizeof(buffer),fp) != NULL ) {
        start = skpws(buffer);
        if ( *start == ';' || *start =='#' || *start ==0)
            continue;
        if ( *start == '[' ) {
            get_section(ctx, start);
        } else {        /* Must be an option! */
            ptr = start;
            while ( isoptionchar(*ptr) )
                ptr++;
            if ( *ptr == '=' ) {
                *ptr++ = 0;
            } else {
                *ptr++ = 0;
                /* Search for the '=' now */
                if ( (ptr = strchr(ptr,'=') ) == NULL ) {
                    continue;
                }
                ptr++;
            }

            ptr = skpws(ptr); /* Skip over any white space */
            if ( *ptr == ';' || *ptr =='#' || *ptr ==0 ) {
                continue;
            }
            if ( strlen(start) ) {
                if ( option_set(ctx, start,ptr) >= 0 ) {
                    ret++;
                }
            }
        }
    }
    return ret;
}
Esempio n. 15
0
unsigned int
CheckRun(const TOKEN *str, unsigned int size) {
	/*	Checks the run starting at str with length size for
		acceptability in the language.  Cuts from the end if
		necessary and returns the accepted length, which may
		be zero.
	*/

	if (option_set('f')) {
		/* reduce to a function-like form first */
		size = largest_function(str, size);
	}

	while (	/* there is trailing garbage */
		size != 0 && non_finals[TOKEN2int(str[size-1])]
	) {
		/* remove it */
		size--;
	}

	return size;
}
Esempio n. 16
0
static void parse_util_args (int argc, char *argv[]){
  char  c;
  int   i;
  char  fname[FILENAME_MAX];

  if (argc == 0) {
    fputs (usage, stderr);
    exit  (1);
  }

  while (--argc && (*++argv)[0] == '-') {
    while (c = *++argv[0])
      switch (c) {
      case 'r': /* use rea files as input */
  option_set("REAFILE",1);
  break;
      default:
  fprintf(stderr, "%s: unknown option -- %c\n", prog, c);
  break;
      }
  }

  return;
}
Esempio n. 17
0
/**
 * Read options.
 */
int rd_options(void)
{
	byte b;

	u16b tmp16u;

	/*** Special info */

	/* Read "delay_factor" */
	rd_byte(&b);
	player->opts.delay_factor = b;

	/* Read "hitpoint_warn" */
	rd_byte(&b);
	player->opts.hitpoint_warn = b;

	/* Read lazy movement delay */
	rd_u16b(&tmp16u);
	player->opts.lazymove_delay = (tmp16u < 1000) ? tmp16u : 0;


	/* Read options */
	while (1) {
		byte value;
		char name[40];
		rd_string(name, sizeof name);

		if (!name[0])
			break;

		rd_byte(&value);
		option_set(name, !!value);
	}

	return 0;
}
Esempio n. 18
0
int
cook_auto_required(void)
{
    int             retval;
    graph_ty        *gp;
    graph_build_status_ty gb_status;
    graph_walk_status_ty gw_status;
    size_t          j;

    /*
     * This may have been explicitly forbidden on the command line.
     */
    if (!option_test(OPTION_INCLUDE_COOKED))
        return 0;

    retval = 0;

    option_set(OPTION_ACTION, OPTION_LEVEL_AUTO, 1);
    option_set(OPTION_TOUCH, OPTION_LEVEL_AUTO, 0);
    option_set(OPTION_REASON, OPTION_LEVEL_COOKBOOK, 0);

    /*
     * Build the dependency graph.
     */
    gp = graph_new();
    if
    (
        !option_test(OPTION_SILENT)
    &&
        option_test(OPTION_INCLUDE_COOKED_WARNING)
    )
        gp->file_pair = graph_file_pair_new(&cook_auto_list);
    gb_status =
        graph_build_list
        (
            gp,
            &cook_auto_list,
            graph_build_preference_error,
            0   /* not primary, no up-to-date commentary */
        );
    if (option_test(OPTION_REASON))
        graph_print_statistics(gp);
    switch (gb_status)
    {
    case graph_build_status_error:
        retval = -1;
        break;

    case graph_build_status_backtrack:
        /* assert(0); */
        retval = -1;
        break;

    case graph_build_status_success:
        break;
    }

    /*
     * Build a list of non-leaf cook-auto files.
     */
    string_list_destructor(&cook_auto_list_nonleaf);
    for (j = 0; j < cook_auto_list.nstrings; ++j)
    {
        string_ty       *fn;

        fn = cook_auto_list.string[j];
        if (!graph_file_leaf_p(gp, fn))
            string_list_append(&cook_auto_list_nonleaf, fn);
    }

    /*
     * Walk the dependency graph.
     */
    if (retval == 0)
    {
        gw_status = graph_walk(gp);
        switch (gw_status)
        {
        case graph_walk_status_uptodate:
        case graph_walk_status_uptodate_done:
            break;

        case graph_walk_status_done:
            retval = 1;
            break;

        case graph_walk_status_done_stop:
        case graph_walk_status_wait:
            assert(0);
            /* fall through... */

        case graph_walk_status_error:
            retval = -1;
            break;
        }
    }

    /*
     * Release any resources held by the graph.
     */
    graph_delete(gp);

    option_undo(OPTION_REASON, OPTION_LEVEL_COOKBOOK);
    option_undo(OPTION_ACTION, OPTION_LEVEL_AUTO);
    option_undo(OPTION_TOUCH, OPTION_LEVEL_AUTO);

    return retval;
}
Esempio n. 19
0
int main(int argc, char * argv[]) {

	//   board_t board[1];

	// init

	Init = false;
#ifdef _WIN32
	signal(SIGINT,SIG_IGN);
	signal(SIGTERM,SIG_IGN);
#ifdef SIGPIPE
	signal(SIGPIPE,SIG_IGN);
#endif
#endif

	util_init();
	printf("PolyGlot %s by Fabien Letouzey\n",Version);

	option_init();
	uci_options_init();
	square_init();
	piece_init();
	attack_init();

	hash_init();

	my_random_init();

	// build book

	if (argc >= 2 && my_string_equal(argv[1],"make-book")) {
		book_make(argc,argv);
		return EXIT_SUCCESS;
	}

	if (argc >= 2 && my_string_equal(argv[1],"merge-book")) {
		book_merge(argc,argv);
		return EXIT_SUCCESS;
	}

	// read options

	if (argc == 2) option_set("OptionFile",argv[1]); // HACK for compatibility

	parse_option(); // HACK: also launches the engine

	// EPD test

	if (argc >= 2 && my_string_equal(argv[1],"epd-test")) {
		epd_test(argc,argv);
		return EXIT_SUCCESS;
	}

	// opening book

	book_clear();
	if (option_get_bool("Book")){
		if (book_open(option_get_string("BookFile")))
			option_set("Book","false");//some error,set to false
	}
	//adapter_loop();
#ifdef _WIN32
	Engine_ready_ok=CreateEvent(NULL,FALSE,FALSE,NULL);
	Engine_sync_stop = CreateEvent(NULL,FALSE,FALSE,NULL);
	// all set and done.lets open a thread for fun
	DWORD dwThreadID;
	HANDLE hThread;
	hThread= CreateThread(
		NULL,	//default security attributes
		0,	//default stacksize
		ThreadFunc,	//The thread function!
		&sCommand,	//the commands for the thread function
		0,			//default creation flags
		&dwThreadID);	//the thread identifier
	Idle500msecs();//
	if(hThread==NULL){
		my_log("CreateThread failed\n");
	}

#endif
	adapter_loop();
	engine_send(Engine,"quit");
	engine_close(Engine);
#ifdef _WIN32
	CloseHandle(hThread); //close the thread;
#endif
	return EXIT_SUCCESS;
}
Esempio n. 20
0
void xboard2uci_gui_step(char string[]) {

	int move;
	char move_string[256];
	board_t board[1];

		if (FALSE) {
         
		} else if (match(string,"accepted *")) {

			// ignore

		} else if (match(string,"analyze")) {

			State->computer[White] = FALSE;
			State->computer[Black] = FALSE;

			XB->analyse = TRUE;
			XB->new_hack = FALSE;
			ASSERT(!XB->result);
			XB->result = FALSE;

			mess();

		} else if (match(string,"bk")) {

			if (option_get_bool(Option,"Book")) {
				game_get_board(Game,board);
				book_disp(board);
			}

		} else if (match(string,"black")) {

			if (colour_is_black(game_turn(Game))) {

				State->computer[White] = TRUE;
				State->computer[Black] = FALSE;

				XB->new_hack = TRUE;
				XB->result = FALSE;

				mess();
			}

		} else if (match(string,"computer")) {

			XB->computer = TRUE;

		} else if (match(string,"draw")) {
			if(option_find(Uci->option,"UCI_DrawOffers")){
			    my_log("POLYGLOT draw from XB received");
				uci_send_option(Uci,"DrawOffer","%s","draw");}
		} else if (match(string,"easy")) {

			XB->ponder = FALSE;

			mess();

		} else if (match(string,"edit")) {

			// refuse

			gui_send(GUI,"Error (unknown command): %s",string);

		} else if (match(string,"exit")) {

			State->computer[White] = FALSE;
			State->computer[Black] = FALSE;

			XB->analyse = FALSE;

			mess();

		} else if (match(string,"force")) {

			State->computer[White] = FALSE;
			State->computer[Black] = FALSE;

			mess();

		} else if (match(string,"go")) {

			State->computer[game_turn(Game)] = TRUE;
			State->computer[colour_opp(game_turn(Game))] = FALSE;

			XB->new_hack = FALSE;
			ASSERT(!XB->result);
			XB->result = FALSE;

			mess();

		} else if (match(string,"hard")) {

			XB->ponder = TRUE;

			mess();

		} else if (match(string,"hint")) {
		    
		        move=MoveNone;
			game_get_board(Game,board);
			if (option_get_bool(Option,"Book")) {

				move = book_move(board,FALSE);
			}
			if(move==MoveNone && State->hint_move!=MoveNone){
			    move=State->hint_move;
			    
			}
			if (move != MoveNone && move_is_legal(move,board)) {
			    move_to_san(move,board,move_string,256);
			    gui_send(GUI,"Hint: %s",move_string);
			}

		} else if (match(string,"ics *")) {

			XB->ics = TRUE;

		} else if (match(string,"level * *:* *")) {

			XB->mps  = atoi(Star[0]);
			XB->base = ((double)atoi(Star[1])) * 60.0 + ((double)atoi(Star[2]));
			XB->inc  = ((double)atoi(Star[3]));

		} else if (match(string,"level * * *")) {

			XB->mps  = atoi(Star[0]);
			XB->base = ((double)atoi(Star[1])) * 60.0;
			XB->inc  = ((double)atoi(Star[2]));

		} else if (match(string,"name *")) {

			my_string_set(&XB->name,Star[0]);

		} else if (match(string,"new")) {

		    uci_send_isready_sync(Uci);
			my_log("POLYGLOT NEW GAME\n");

			option_set(Option,"3Check","false");
			option_set(Option,"Chess960","false");
			option_set(Option,"Atomic","false");
			option_set(Option,"Horde","false");

			game_clear(Game);

			if (XB->analyse) {
				State->computer[White] = FALSE;
				State->computer[Black] = FALSE;
			} else {
				State->computer[White] = FALSE;
				State->computer[Black] = TRUE;
			}

			XB->new_hack = TRUE;
			XB->result = FALSE;

			XB->depth_limit = FALSE;
            XB->node_rate=-1;

			XB->computer = FALSE;
			my_string_set(&XB->name,"<empty>");

			board_update();
			mess();

			uci_send_ucinewgame(Uci);

		} else if (match(string,"nopost")) {

			XB->post = FALSE;

		} else if (match(string,"otim *")) {

			XB->opp_time = ((double)atoi(Star[0])) / 100.0;
			if (XB->opp_time < 0.0) XB->opp_time = 0.0;

		} else if (match(string,"pause")) {

			// refuse

			gui_send(GUI,"Error (unknown command): %s",string);

		} else if (match(string,"ping *")) {

			// HACK; TODO: answer only after an engine move

			if (DelayPong) {
				if (XB->ping >= 0) gui_send(GUI,"pong %d",XB->ping); // HACK: get rid of old ping
				XB->ping = atoi(Star[0]);
				uci_send_isready_sync(Uci);
			} else {
				ASSERT(XB->ping==-1);
				gui_send(GUI,"pong %s",Star[0]);
			}
        } else if (match(string,"nps *")) {
            
                // fake WB play-by-nodes mode
            XB->node_rate = atoi(Star[0]);
		} else if (match(string,"playother")) {

			State->computer[game_turn(Game)] = FALSE;
			State->computer[colour_opp(game_turn(Game))] = TRUE;

			XB->new_hack = FALSE;
			ASSERT(!XB->result);
			XB->result = FALSE;

			mess();

		} else if (match(string,"post")) {

			XB->post = TRUE;

		} else if (match(string,"protover *")) {
            XB->proto_ver = atoi(Star[0]);
            ASSERT(XB->proto_ver>=2);
            send_xboard_options();

		} else if (match(string,"quit")) {
			my_log("POLYGLOT *** \"quit\" from GUI ***\n");
			quit();
		} else if (match(string,"random")) {

			// ignore

		} else if (match(string,"rating * *")) {

			// ignore

		} else if (match(string,"remove")) {

			if (game_pos(Game) >= 2) {

				game_goto(Game,game_pos(Game)-2);

				ASSERT(!XB->new_hack);
				XB->new_hack = FALSE; // HACK?
				XB->result = FALSE;

				board_update();
				mess();
			}

		} else if (match(string,"rejected *")) {

			// ignore

		} else if (match(string,"reset")) { // protover 3?

			// refuse

			gui_send(GUI,"Error (unknown command): %s",string);

		} else if (FALSE
			|| match(string,"result * {*}")
			|| match(string,"result * {* }")
			|| match(string,"result * { *}")
			|| match(string,"result * { * }")) {

				my_log("POLYGLOT GAME END\n");

				XB->result = TRUE;

				mess();

				// book learning

				if (FALSE && option_get_bool(Option,"Book") &&
                    option_get_bool(Option,"BookLearn")) {

					if (FALSE) {
					} else if (my_string_equal(Star[0],"1-0")) {
						learn(+1);
					} else if (my_string_equal(Star[0],"0-1")) {
						learn(-1);
					} else if (my_string_equal(Star[0],"1/2-1/2")) {
						learn(0);
					}
				}
		} else if (match(string,"resume")) {

			// refuse

			gui_send(GUI,"Error (unknown command): %s",string);

        } else if (match(string,"option *=*")   ||
                   match(string,"option * =*") ||
                   match(string,"option *= *") ||
                   match(string,"option * = *")
                   ){
            char *name=Star[0];
            char *value=Star[1];
            if(match(name, "Polyglot *")){
                char *pg_name=Star[0];
                polyglot_set_option(pg_name,value);
            }else{
                option_t *opt=option_find(Uci->option,name);
                if(opt){
                    if(my_string_case_equal(opt->type,"check")){
                       value=my_string_equal(value,"1")?"true":"false";
                    }
                    start_protected_command();
                    uci_send_option(Uci, name, "%s", value);
                    end_protected_command();
                }else{
                    gui_send(GUI,"Error (unknown option): %s",name); 
                }
            }
        } else if (match(string,"option *")){
            char *name=Star[0];
             if(match(name, "Polyglot *")){
                char *pg_name=Star[0];
                polyglot_set_option(pg_name,"<empty>");
	     }else{           
	       start_protected_command();
                // value is ignored
	       if(!uci_send_option(Uci, name, "%s", "<empty>")){
		 gui_send(GUI,"Error (unknown option): %s",name); 
	       }; 
	       end_protected_command();
	     }
        } else if (XB->has_feature_smp && match(string,"cores *")){
                int cores=atoi(Star[0]);
                if(cores>=1){
                    // updating the number of cores
                    my_log("POLYGLOT setting the number of cores to %d\n",cores);
                    start_protected_command();
                    uci_set_threads(Uci,cores); 
                    end_protected_command();
                } else{
                   // refuse
                    gui_send(GUI,"Error (unknown command): %s",string);
                }
        } else if (match(string,"egtpath * *")){
                char *type=Star[0];
                char *path=Star[1];
                if(my_string_empty(path)){
                    // refuse
                    gui_send(GUI,"Error (unknown command): %s",string);
                }else{
		    if(my_string_case_equal(type,"nalimov") && XB->has_feature_egt_nalimov){
			// updating NalimovPath
			my_log("POLYGLOT setting the Nalimov path to %s\n",path);
			start_protected_command();
			uci_send_option(Uci,"NalimovPath","%s",path);
			end_protected_command();
		    }else if(my_string_case_equal(type,"gaviota") && XB->has_feature_egt_gaviota){
			// updating GaviotaPath
			my_log("POLYGLOT setting the Gaviota path to %s\n",path);
			start_protected_command();
			uci_send_option(Uci,"GaviotaTbPath","%s",path);
			end_protected_command();
		    }else{
			// refuse
			gui_send(GUI,"Error (unsupported table base format): %s",string);
		    }
                }
        } else if (XB->has_feature_memory && match(string,"memory *")){
            int memory = atoi(Star[0]);
            int egt_cache;
            int real_memory;
            if(memory>=1){
                // updating the available memory
                option_t *opt;
                my_log("POLYGLOT setting the amount of memory to %dMb\n",memory);
                if(XB->has_feature_egt_nalimov && (opt=option_find(Uci->option,"NalimovCache"))){
                    egt_cache=atoi(opt->value);
                }else if(XB->has_feature_egt_gaviota && 
			 (opt=option_find(Uci->option,"GaviotaTbCache"))){
		    egt_cache=atoi(opt->value);
		}else{
                    egt_cache=0;
                }
                my_log("POLYGLOT EGTB Cache is %dMb\n",egt_cache);
                real_memory=memory-egt_cache;
                if(real_memory>0){
                    start_protected_command();
                    uci_send_option(Uci,"Hash", "%d", real_memory);
                    end_protected_command();
                }
            }else{
                // refuse
                gui_send(GUI,"Error (unknown command): %s",string);
            }

		} else if (match(string,"sd *")) {

			XB->depth_limit = TRUE;
			XB->depth_max = atoi(Star[0]);

		} else if (match(string,"setboard *")) {

			my_log("POLYGLOT FEN %s\n",Star[0]);

			if (!game_init(Game,Star[0])) my_fatal("xboard_step(): bad FEN \"%s\"\n",Star[0]);

			State->computer[White] = FALSE;
			State->computer[Black] = FALSE;

			XB->new_hack = TRUE; // HACK?
			XB->result = FALSE;

			board_update();
			mess();

		} else if (match(string,"st *")) {

			XB->time_limit = TRUE;
			XB->time_max = ((double)atoi(Star[0]));

		} else if (match(string,"time *")) {

			XB->my_time = ((double)atoi(Star[0])) / 100.0;
			if (XB->my_time < 0.0) XB->my_time = 0.0;

		} else if (match(string,"undo")) {

			if (game_pos(Game) >= 1) {

				game_goto(Game,game_pos(Game)-1);

				ASSERT(!XB->new_hack);
				XB->new_hack = FALSE; // HACK?
				XB->result = FALSE;

				board_update();
				mess();
			}

		} else if (match(string,"usermove *")) {

			game_get_board(Game,board);
			move = move_from_san(Star[0],board);

			if (move != MoveNone && move_is_legal(move,board)) {

				XB->new_hack = FALSE;
				ASSERT(!XB->result);
				XB->result = FALSE;

				move_step(move);
				no_mess(move);

			} else {

				gui_send(GUI,"Illegal move: %s",Star[0]);
			}

		} else if (match(string,"variant *")) {

			if (my_string_equal(Star[0],"3check")) {
				option_set(Option,"3Check","true");
			} else {
				option_set(Option,"3Check","false");
			}
			if (my_string_equal(Star[0],"fischerandom")) {
				option_set(Option,"Chess960","true");
			} else {
				option_set(Option,"Chess960","false");
			}
			if (my_string_equal(Star[0],"atomic")) {
				option_set(Option,"Atomic","true");
			} else {
				option_set(Option,"Atomic","false");
			}
			if (my_string_equal(Star[0],"horde")) {
				option_set(Option,"Horde","true");
				game_init(Game,StartFenHorde);
				//gui_send(GUI,"setup %s",StartFenHorde);
			} else {
				option_set(Option,"Horde","false");
			}

		} else if (match(string,"white")) {

			if (colour_is_white(game_turn(Game))) {

				State->computer[White] = FALSE;
				State->computer[Black] = TRUE;

				XB->new_hack = TRUE;
				XB->result = FALSE;

				mess();
			}

		} else if (match(string,"xboard")) {

			// ignore

		} else if (match(string,".")) { // analyse info

			if (State->state == ANALYSE) {
				int depth=Uci->best_depth;//HACK: don't clear engine-output window...

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

				if (Uci->root_move != MoveNone && move_is_legal(Uci->root_move,Uci->board)) {
					move_to_san(Uci->root_move,Uci->board,move_string,256);
					gui_send(GUI,"stat01: %.0f "S64_FORMAT" %d %d %d %s",Uci->time*100.0,Uci->node_nb,/*Uci->*/depth,Uci->root_move_nb-(Uci->root_move_pos+1),Uci->root_move_nb,move_string);
				} else {
					gui_send(GUI,"stat01: %.0f "S64_FORMAT" %d %d %d",Uci->time*100.0,Uci->node_nb,/*Uci->*/depth,0,0); // HACK
				}
			}

		} else if (match(string,"?")) { // move now

			if (State->state == THINK) {

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

				// HACK: just send "stop" to the engine

				if (Uci->searching) {
					my_log("POLYGLOT STOP SEARCH\n");
					engine_send(Engine,"stop");
				}
			}

		} else { // unknown command, maybe a move?

			game_get_board(Game,board);
			move = move_from_san(string,board);

			if (move != MoveNone && move_is_legal(move,board)) {

				XB->new_hack = FALSE;
				ASSERT(!XB->result);
				XB->result = FALSE;

				move_step(move);
				no_mess(move);

			} else if (move != MoveNone) {

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

			} else {

				gui_send(GUI,"Error (unknown command): %s",string);
			}
		}
	return;
}
Esempio n. 21
0
int main (int argc, char* const argv[])
{
	int i,j;
	char c;
	nodummy = 0;
    program_name = argv[0];
	double u1, u2, total = 0;
	struct timeval tv;
    
    /* Get the input arguments */
    option_set(argc,argv);
    
    /* Handle the input files */
    handle_files (circuit_name,vectors_name);
    
    
    gettimeofday(&tv,NULL);
   	u1 = tv.tv_sec*1.0e6 + tv.tv_usec;


	/* Read the circuit file and make the structures */
    if (read_circuit (circuit_fd) < 0)
        system_error ("read_circuit");
    fclose (circuit_fd);
    
    if (nog<=0 || nopi<=0 || nopo<=0) {
		fprintf(stderr,"Error in circuit file: #PI=%d, #PO=%d, #GATES=%d\n",nopi,nopo,nog);
		abort();
	}
    
    /* Add a gate for the output stage as you did for the input stage */
    nodummy = add_PO();
    
    /* Compute the levels of the circuit */
    allocate_stacks();
    maxlevel = compute_level();
	place_PO();

	
    printf("the max level = %d\n",maxlevel);
    
    /* Computes the level of each gate */
    allocate_event_list();
    levelize();
    //xfree(event_list); 
    
    gettimeofday(&tv,NULL);
    u2 = tv.tv_sec*1.0e6 + tv.tv_usec;
    
    total=(u2-u1);
    
    printf("Time for construction of data structures: %f usec\n", total);
    total= 0;
    
	printf("opening vectors file= %s\n",vectors_name);
    vectors_fd = fopen (vectors_name, "r");
	if (vectors_fd == NULL)
		system_error ("fopen");
		
	gettimeofday(&tv,NULL);
   	u1 = tv.tv_sec*1.0e6 + tv.tv_usec;
		
	/* Read the vector file and put the input values to the INPUT GATES */
	if (read_vectors (vectors_fd,vectors_name) != 0)
		system_error ("read_vectors");
	//fclose (vectors_fd);  //valgrind mistake
	
	
	
	//logic simulation here
	LUT = create_lut (LUT);
	logic_sim();

	i=0; j=0;
	if(test_name[0]=='\0') {
		while((c=circuit_name[i++])!='\0') {
			if(c=='/') j=0;
			else if(c=='.') break;
			else test_name[j++]=c;
		}
		test_name[j]='\0';
		strcat(test_name,".test");
	}

	gettimeofday(&tv,NULL);
    u2 = tv.tv_sec*1.0e6 + tv.tv_usec;
    
    total=(u2-u1);
    
    printf("Time for logic simulation: %f usec\n", total);
    total= 0;

    //print_logic_sim();
	

	//<----------------------------------------------------------------
	//fault simulation here
	gettimeofday(&tv,NULL);
   	u1 = tv.tv_sec*1.0e6 + tv.tv_usec;	
	
	create_fault_list ();
	//print_fault_list();
	fault_sim();
	
	gettimeofday(&tv,NULL);
    u2 = tv.tv_sec*1.0e6 + tv.tv_usec;
    
    total=(u2-u1);
    
    printf("Time for fault simulation: %f usec\n", total);
    total= 0;
	
	
	
	/*if ( fault_name == NULL ) {
		printf("\nWe are done\n");
		return 0;
	}
	
	printf("opening fault file= %s\n",fault_name);
    vectors_fd = fopen (vectors_name, "r");
	if (vectors_fd == NULL)
		system_error ("fopen"); */
	
	
		
	//	synexeia simulation<-----------------------------------
    
    
    
    printf("\nWe are done\n");
    return 0;
}
Esempio n. 22
0
int
main(int argc, char *argv[]) {
	progname = argv[0];		/* save program name */
	argv++, argc--;			/* and skip it */

	/* Set the default output and debug streams */
	OutputFile = stdout;
	DebugFile = stdout;

	/* Get command line options */
	{	int nop = do_options(progname, optlist, argc, argv);
		argc -= nop, argv += nop;	/* skip them */
	}

	/* Treat the value options */
	if (minrunstring) {
		MinRunSize = strtoul(minrunstring, NULL, 10);
		if (MinRunSize == 0) fatal("bad or zero run size; form is: -r N");
	}
	if (pagewidthstring) {
		PageWidth = atoi(pagewidthstring);
		if (PageWidth == 0) fatal("bad or zero page width; form is: -w N");
	}
	if (outputname) {
		OutputFile = fopen(outputname, "w");
		if (OutputFile == 0) {
			char msg[500];

			sprintf(msg, "cannot open output file %s", outputname);
			fatal(msg);
			/*NOTREACHED*/
		}
	}

	if (option_set('-')) {
		/* it is the lexical scan only */
		while (argv[0]) {
			print_stream(argv[0]);
			argv++;
		}
		return 0;
	}

	/* Start processing */
	InitLanguage();

	/* Read the input files */
	Pass1(argc, argv);

	/* Set up the forward reference table */
	MakeForwardReferences();

	/* Compare the input files to find runs */
	Compare();

	/* Delete forward reference table */
	FreeForwardReferences();

	/* Find positions of the runs found */
	Pass2();

	/* Print the similarities */
	Pass3();

	return 0;
}
Esempio n. 23
0
static void parse_setoption(char string[]) {

   const char * name;
   char * value;

   // init

   name = strstr(string,"name ");
   value = strstr(string,"value ");

   if (name == NULL || value == NULL || name >= value) return; // ignore buttons

   value[-1] = '\0'; // HACK
   name += 5;
   value += 6;

   // update

   option_set(name,value);

   // update transposition-table size if needed

   if (Init && my_string_equal(name,"Hash")) { // Init => already allocated

      ASSERT(!Searching);

      if (option_get_int("Hash") >= 4) {
         trans_free();
         trans_alloc();
      }
   }

   // update endgame tablebases if needed

   if (my_string_equal(name,"NalimovPath")) {

      ASSERT(!Searching);
      tb_path(option_get_string("NalimovPath"));
   }

   if (my_string_equal(name,"NalimovCache")) {

      ASSERT(!Searching);
      tb_cache(option_get_int("NalimovCache"));
   }

   if (my_string_equal(name,"EgbbPath")) {

      ASSERT(!Searching);
      egbb_path(option_get_string("EgbbPath"));
   }

   if (my_string_equal(name,"EgbbCache")) {

      ASSERT(!Searching);
      egbb_cache(option_get_int("EgbbCache"));
   }

   // update pawn structure if needed

   if (my_string_equal(name,"Pawn Structure")) {

      ASSERT(!Searching);
      pawn_structure_set_option(option_get_int("Pawn Structure"));
      pst_init();
   }

   // update piece activity if needed

   if (my_string_equal(name,"Piece Activity")) {

      ASSERT(!Searching);
      trans_clear();
      pst_init();
   }

   // update king safty if needed

   if (my_string_equal(name,"King Safety")) {

      ASSERT(!Searching);
      trans_clear();
      pst_init();
   }

   // update pawn activity if needed

   if (my_string_equal(name,"Pawn Activity")) {

      ASSERT(!Searching);
      trans_clear();
      pst_init();
   }

   // update material if needed

   if (my_string_equal(name,"Material")) {

      ASSERT(!Searching);
      material_set_option(option_get_int("Material"));
   }

   // update piece value if needed

   if (my_string_equal(name,"Pawn")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Pawn"),MAT_PAWN);
   }

   if (my_string_equal(name,"Knight")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Knight"),MAT_KNIGHT);
   }

   if (my_string_equal(name,"Bishop")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Bishop"),MAT_BISHOP);
   }

   if (my_string_equal(name,"Rook")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Rook"),MAT_ROOK);
   }

   if (my_string_equal(name,"Queen")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Queen"),MAT_QUEEN);
   }

   if (my_string_equal(name,"Bishop Pair")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Bishop Pair"),MAT_BISHOP_PAIR);
   }
}
Esempio n. 24
0
static void
argparse(option_level_ty level)
{
    option_number_ty type;
    string_ty       *s;
    sub_context_ty  *scp;
    int             fingerprint_update;

    type = -1;
    fingerprint_update = 0;
    switch (arglex())
    {
    case arglex_token_help:
        if (level != OPTION_LEVEL_COMMAND_LINE)
        {
          not_in_env:
            scp = sub_context_new();
            sub_var_set(scp, "Name", "%s", arglex_value.alv_string);
            fatal_intl(scp, i18n("may not use $name in environment variable"));
            /* NOTREACHED */
        }
        help((char *)0, usage);
        quit(0);

    case arglex_token_version:
        if (level != OPTION_LEVEL_COMMAND_LINE)
            goto not_in_env;
        version();
        quit(0);

    default:
        break;
    }
    while (arglex_token != arglex_token_eoln)
    {
        switch (arglex_token)
        {
        default:
            generic_argument(usage);
            continue;

        case arglex_token_include:
            if (arglex() != arglex_token_string)
            {
                arg_needs_string(arglex_token_include, usage);
                /* NOTREACHED */
            }
            s = str_from_c(arglex_value.alv_string);
            string_list_append_unique(&option.o_search_path, s);
            str_free(s);
            break;

        case arglex_token_reason:
            type = OPTION_REASON;
          normal_on:
            if (option_already(type, level))
            {
              too_many:
                arg_duplicate_cur(usage);
                /* NOTREACHED */
            }
            option_set(type, level, 1);
            break;

        case arglex_token_reason_not:
            type = OPTION_REASON;
          normal_off:
            if (option_already(type, level))
                goto too_many;
            option_set(type, level, 0);
            break;

        case arglex_token_cascade:
            type = OPTION_CASCADE;
            goto normal_on;

        case arglex_token_cascade_not:
            type = OPTION_CASCADE;
            goto normal_off;

        case arglex_token_disassemble:
            type = OPTION_DISASSEMBLE;
            goto normal_on;

        case arglex_token_disassemble_not:
            type = OPTION_DISASSEMBLE;
            goto normal_off;

        case arglex_token_tty:
            type = OPTION_TERMINAL;
            goto normal_on;

        case arglex_token_tty_not:
            type = OPTION_TERMINAL;
            goto normal_off;

        case arglex_token_precious:
            type = OPTION_PRECIOUS;
            goto normal_on;

        case arglex_token_precious_not:
            type = OPTION_PRECIOUS;
            goto normal_off;

        case arglex_token_log:
            if (option_already(OPTION_LOGGING, level))
                goto too_many;
            option_set(OPTION_LOGGING, level, 1);
            if (arglex() != arglex_token_string)
                continue;
            if (option.o_logfile)
                str_free(option.o_logfile);
            option.o_logfile = str_from_c(arglex_value.alv_string);
            break;

        case arglex_token_log_not:
            type = OPTION_LOGGING;
            goto normal_off;

        case arglex_token_book:
            if (option_already(OPTION_BOOK, level))
                goto too_many;
            option_set(OPTION_BOOK, level, 1);
            if (arglex() != arglex_token_string)
                continue;
            if (option.o_book)
                str_free(option.o_book);
            option.o_book = str_from_c(arglex_value.alv_string);
            break;

        case arglex_token_book_not:
            type = OPTION_BOOK;
            goto normal_off;

        case arglex_token_include_cooked:
            type = OPTION_INCLUDE_COOKED;
            goto normal_on;

        case arglex_token_include_cooked_not:
            type = OPTION_INCLUDE_COOKED;
            goto normal_off;

        case arglex_token_include_cooked_warning:
            type = OPTION_INCLUDE_COOKED_WARNING;
            goto normal_on;

        case arglex_token_include_cooked_warning_not:
            type = OPTION_INCLUDE_COOKED_WARNING;
            goto normal_off;

        case arglex_token_silent:
            type = OPTION_SILENT;
            goto normal_on;

        case arglex_token_silent_not:
            type = OPTION_SILENT;
            goto normal_off;

        case arglex_token_tell_position:
            type = OPTION_TELL_POSITION;
            goto normal_on;

        case arglex_token_tell_position_not:
            type = OPTION_TELL_POSITION;
            goto normal_off;

        case arglex_token_metering:
            type = OPTION_METER;
            goto normal_on;

        case arglex_token_metering_not:
            type = OPTION_METER;
            goto normal_off;

        case arglex_token_touch:
            type = OPTION_TOUCH;
            goto normal_on;

        case arglex_token_touch_not:
            type = OPTION_TOUCH;
            goto normal_off;

        case arglex_token_action:
            type = OPTION_ACTION;
            goto normal_on;

        case arglex_token_action_not:
            type = OPTION_ACTION;
            goto normal_off;

        case arglex_token_persevere:
            type = OPTION_PERSEVERE;
            goto normal_on;

        case arglex_token_persevere_not:
            type = OPTION_PERSEVERE;
            goto normal_off;

        case arglex_token_errok:
            type = OPTION_ERROK;
            goto normal_on;

        case arglex_token_errok_not:
            type = OPTION_ERROK;
            goto normal_off;

        case arglex_token_force:
            type = OPTION_FORCE;
            goto normal_on;

        case arglex_token_force_not:
            type = OPTION_FORCE;
            goto normal_off;

        case arglex_token_fingerprint:
            type = OPTION_FINGERPRINT;
            goto normal_on;

        case arglex_token_fingerprint_not:
            type = OPTION_FINGERPRINT;
            goto normal_off;

        case arglex_token_fingerprint_update:
            if (level != OPTION_LEVEL_COMMAND_LINE)
                goto not_in_env;
            if (option.fingerprint_update)
                goto too_many;
            option.fingerprint_update++;
            break;

        case arglex_token_pairs:
            if (level != OPTION_LEVEL_COMMAND_LINE)
                goto not_in_env;
            if (option.pairs)
                goto too_many;
            option.pairs++;
            break;

        case arglex_token_script:
            if (level != OPTION_LEVEL_COMMAND_LINE)
                goto not_in_env;
            if (option.script)
                goto too_many;
            option.script++;
            break;

        case arglex_token_web:
            if (level != OPTION_LEVEL_COMMAND_LINE)
                goto not_in_env;
            if (option.web)
                goto too_many;
            option.web++;
            break;

        case arglex_token_string:
            if (level != OPTION_LEVEL_COMMAND_LINE)
            {
                if (strchr(arglex_value.alv_string, '='))
                {
                    fatal_intl
                    (
                        0,
                        i18n("may not assign variables in environment variable")
                    );
                }
                else
                {
                    fatal_intl
                    (
                        0,
                        i18n("may not name targets in environment variable")
                    );
                }
            }
            else
            {
                char            *cp;

                cp = strchr(arglex_value.alv_string, '=');
                if (!cp)
                {
                    s = str_from_c(arglex_value.alv_string);
                    string_list_append(&option.o_target, s);
                    str_free(s);
                }
                else
                {
                    s = str_from_c(arglex_value.alv_string);
                    string_list_append(&option.o_vardef, s);
                    str_free(s);
                }
            }
            break;

        case arglex_token_star:
            type = OPTION_STAR;
            goto normal_on;

        case arglex_token_star_not:
            type = OPTION_STAR;
            goto normal_off;

        case arglex_token_strip_dot:
            type = OPTION_STRIP_DOT;
            goto normal_on;

        case arglex_token_strip_dot_not:
            type = OPTION_STRIP_DOT;
            goto normal_off;

        case arglex_token_update:
            type = OPTION_UPDATE;
            goto normal_on;

        case arglex_token_update_not:
            type = OPTION_UPDATE;
            goto normal_off;

        case arglex_token_parallel:
            if (arglex() != arglex_token_number)
            {
                s = str_from_c("parallel_jobs=4");
                string_list_append(&option.o_vardef, s);
                str_free(s);
                continue;
            }
            s = str_format("parallel_jobs=%d", (int)arglex_value.alv_number);
            string_list_append(&option.o_vardef, s);
            str_free(s);
            break;

        case arglex_token_parallel_not:
            s = str_from_c("parallel_jobs=1");
            string_list_append(&option.o_vardef, s);
            str_free(s);
            break;

        case arglex_token_shallow:
            type = OPTION_SHALLOW;
            goto normal_on;

        case arglex_token_shallow_not:
            type = OPTION_SHALLOW;
            goto normal_off;
        }
        arglex();
    }
}
Esempio n. 25
0
static void xboard_step() {

   char string[StringSize];
   int move;
   char move_string[256];
   board_t board[1];

   xboard_get(XBoard,string,StringSize);

   if (false) {

   } else if (match(string,"accepted *")) {

      // ignore

   } else if (match(string,"analyze")) {

      State->computer[White] = false;
      State->computer[Black] = false;

      XB->analyse = true;
      XB->new_hack = false;
      ASSERT(!XB->result);
      XB->result = false;

      mess();

   } else if (match(string,"bk")) {

      if (option_get_bool("Book")) {
         game_get_board(Game,board);
         book_disp(board);
      }

   } else if (match(string,"black")) {

      if (colour_is_black(game_turn(Game))) {

         State->computer[White] = true;
         State->computer[Black] = false;

         XB->new_hack = true;
         XB->result = false;

         mess();
      }

   } else if (match(string,"computer")) {

      XB->computer = true;

   } else if (match(string,"draw")) {

      // ignore

   } else if (match(string,"easy")) {

      XB->ponder = false;

      mess();

   } else if (match(string,"edit")) {

      // refuse

      xboard_send(XBoard,"Error (unknown command): %s",string);

   } else if (match(string,"exit")) {

      State->computer[White] = false;
      State->computer[Black] = false;

      XB->analyse = false;

      mess();

   } else if (match(string,"force")) {

      State->computer[White] = false;
      State->computer[Black] = false;

      mess();

   } else if (match(string,"go")) {

      State->computer[game_turn(Game)] = true;
      State->computer[colour_opp(game_turn(Game))] = false;

      XB->new_hack = false;
      ASSERT(!XB->result);
      XB->result = false;

      mess();

   } else if (match(string,"hard")) {

      XB->ponder = true;

      mess();

   } else if (match(string,"hint")) {

      if (option_get_bool("Book")) {

         game_get_board(Game,board);
         move = book_move(board,false);

         if (move != MoveNone && move_is_legal(move,board)) {
            move_to_san(move,board,move_string,256);
            xboard_send(XBoard,"Hint: %s",move_string);
         }
      }

   } else if (match(string,"ics *")) {

      XB->ics = true;

   } else if (match(string,"level * *:* *")) {

      XB->mps  = atoi(Star[0]);
      XB->base = double(atoi(Star[1])) * 60.0 + double(atoi(Star[2]));
      XB->inc  = double(atoi(Star[3]));

   } else if (match(string,"level * * *")) {

      XB->mps  = atoi(Star[0]);
      XB->base = double(atoi(Star[1])) * 60.0;
      XB->inc  = double(atoi(Star[2]));

   } else if (match(string,"name *")) {

      my_string_set(&XB->name,Star[0]);

   } else if (match(string,"new")) {

      my_log("POLYGLOT NEW GAME\n");

      option_set("Chess960","false");

      game_clear(Game);

      if (XB->analyse) {
         State->computer[White] = false;
         State->computer[Black] = false;
      } else {
         State->computer[White] = false;
         State->computer[Black] = true;
      }

      XB->new_hack = true;
      XB->result = false;

      XB->depth_limit = false;

      XB->computer = false;
      my_string_set(&XB->name,"<empty>");

      board_update();
      mess();

      uci_send_ucinewgame(Uci);

   } else if (match(string,"nopost")) {

      XB->post = false;

   } else if (match(string,"otim *")) {

      XB->opp_time = double(atoi(Star[0])) / 100.0;
      if (XB->opp_time < 0.0) XB->opp_time = 0.0;

   } else if (match(string,"pause")) {

      // refuse

      xboard_send(XBoard,"Error (unknown command): %s",string);

   } else if (match(string,"ping *")) {

      // HACK; TODO: answer only after an engine move

      if (DelayPong) {
         if (XB->ping >= 0) xboard_send(XBoard,"pong %d",XB->ping); // HACK: get rid of old ping
         XB->ping = atoi(Star[0]);
         uci_send_isready(Uci);
      } else {
         ASSERT(XB->ping==-1);
         xboard_send(XBoard,"pong %s",Star[0]);
      }

   } else if (match(string,"playother")) {

      State->computer[game_turn(Game)] = false;
      State->computer[colour_opp(game_turn(Game))] = true;

      XB->new_hack = false;
      ASSERT(!XB->result);
      XB->result = false;

      mess();

   } else if (match(string,"post")) {

      XB->post = true;

   } else if (match(string,"protover *")) {

      XB->proto_ver = atoi(Star[0]);
      ASSERT(XB->proto_ver>=2);

      xboard_send(XBoard,"feature done=0");

      xboard_send(XBoard,"feature analyze=1");
      xboard_send(XBoard,"feature colors=0");
      xboard_send(XBoard,"feature draw=1");
      xboard_send(XBoard,"feature ics=1");
      xboard_send(XBoard,"feature myname=\"%s\"",option_get_string("EngineName"));
      xboard_send(XBoard,"feature name=1");
      xboard_send(XBoard,"feature pause=0");
      xboard_send(XBoard,"feature ping=1");
      xboard_send(XBoard,"feature playother=1");
      xboard_send(XBoard,"feature reuse=1");
      xboard_send(XBoard,"feature san=0");
      xboard_send(XBoard,"feature setboard=1");
      xboard_send(XBoard,"feature sigint=0");
      xboard_send(XBoard,"feature sigterm=0");
      xboard_send(XBoard,"feature time=1");
      xboard_send(XBoard,"feature usermove=1");

      if (uci_option_exist(Uci,"UCI_Chess960")) {
         xboard_send(XBoard,"feature variants=\"normal,fischerandom\"");
      } else {
         xboard_send(XBoard,"feature variants=\"normal\"");
      }

      if (Uci->ready) xboard_send(XBoard,"feature done=1");

      // otherwise "feature done=1" will be sent when the engine is ready

   } else if (match(string,"quit")) {

      my_log("POLYGLOT *** \"quit\" from XBoard ***\n");
      quit();

   } else if (match(string,"random")) {

      // ignore

   } else if (match(string,"rating * *")) {

      // ignore

   } else if (match(string,"remove")) {

      if (game_pos(Game) >= 2) {

         game_goto(Game,game_pos(Game)-2);

         ASSERT(!XB->new_hack);
         XB->new_hack = false; // HACK?
         XB->result = false;

         board_update();
         mess();
      }

   } else if (match(string,"rejected *")) {

      // ignore

   } else if (match(string,"reset")) { // protover 3?

      // refuse

      xboard_send(XBoard,"Error (unknown command): %s",string);

   } else if (false
           || match(string,"result * {*}")
           || match(string,"result * {* }")
           || match(string,"result * { *}")
           || match(string,"result * { * }")) {

      my_log("POLYGLOT GAME END\n");

      XB->result = true;

      mess();

      // book learning

      if (option_get_bool("Book") && option_get_bool("BookLearn")) {

         if (false) {
         } else if (my_string_equal(Star[0],"1-0")) {
            learn(+1);
         } else if (my_string_equal(Star[0],"0-1")) {
            learn(-1);
         } else if (my_string_equal(Star[0],"1/2-1/2")) {
            learn(0);
         }
      }

   } else if (match(string,"resume")) {

      // refuse

      xboard_send(XBoard,"Error (unknown command): %s",string);

   } else if (match(string,"sd *")) {

      XB->depth_limit = true;
      XB->depth_max = atoi(Star[0]);

   } else if (match(string,"setboard *")) {

      my_log("POLYGLOT FEN %s\n",Star[0]);

      if (!game_init(Game,Star[0])) my_fatal("xboard_step(): bad FEN \"%s\"\n",Star[0]);

      State->computer[White] = false;
      State->computer[Black] = false;

      XB->new_hack = true; // HACK?
      XB->result = false;

      board_update();
      mess();

   } else if (match(string,"st *")) {

      XB->time_limit = true;
      XB->time_max = double(atoi(Star[0]));

   } else if (match(string,"time *")) {

      XB->my_time = double(atoi(Star[0])) / 100.0;
      if (XB->my_time < 0.0) XB->my_time = 0.0;

   } else if (match(string,"undo")) {

      if (game_pos(Game) >= 1) {

         game_goto(Game,game_pos(Game)-1);

         ASSERT(!XB->new_hack);
         XB->new_hack = false; // HACK?
         XB->result = false;

         board_update();
         mess();
      }

   } else if (match(string,"usermove *")) {

      game_get_board(Game,board);
      move = move_from_san(Star[0],board);

      if (move != MoveNone && move_is_legal(move,board)) {

         XB->new_hack = false;
         ASSERT(!XB->result);
         XB->result = false;

         move_step(move);
         no_mess(move);

      } else {

         xboard_send(XBoard,"Illegal move: %s",Star[0]);
      }

   } else if (match(string,"variant *")) {

      if (my_string_equal(Star[0],"fischerandom")) {
         option_set("Chess960","true");
      } else {
         option_set("Chess960","false");
      }

   } else if (match(string,"white")) {

      if (colour_is_white(game_turn(Game))) {

         State->computer[White] = false;
         State->computer[Black] = true;

         XB->new_hack = true;
         XB->result = false;

         mess();
      }

   } else if (match(string,"xboard")) {

      // ignore

   } else if (match(string,".")) { // analyse info

      if (State->state == ANALYSE) {

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

         if (Uci->root_move != MoveNone && move_is_legal(Uci->root_move,Uci->board)) {
            move_to_san(Uci->root_move,Uci->board,move_string,256);
            xboard_send(XBoard,"stat01: %.0f %lld %d %d %d %s",Uci->time*100.0,Uci->node_nb,Uci->depth,Uci->root_move_nb-(Uci->root_move_pos+1),Uci->root_move_nb,move_string);
         } else {
            xboard_send(XBoard,"stat01: %.0f %lld %d %d %d",Uci->time*100.0,Uci->node_nb,Uci->depth,0,0); // HACK
         }
      }

   } else if (match(string,"?")) { // move now

      if (State->state == THINK) {

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

         // HACK: just send "stop" to the engine

         if (Uci->searching) {
            my_log("POLYGLOT STOP SEARCH\n");
            engine_send(Engine,"stop");
         }
      }

   } else { // unknown command, maybe a move?

      game_get_board(Game,board);
      move = move_from_san(string,board);

      if (move != MoveNone && move_is_legal(move,board)) {

         XB->new_hack = false;
         ASSERT(!XB->result);
         XB->result = false;

         move_step(move);
         no_mess(move);

      } else if (move != MoveNone) {

         xboard_send(XBoard,"Illegal move: %s",string);

      } else {

         xboard_send(XBoard,"Error (unknown command): %s",string);
      }
   }
}
Esempio n. 26
0
void config_parse(char *filename) {
	int fd
	  , nameStart
	  , nameStop
	  , valueStart
	  , valueStop
	  , lineR	// Counting \r's
	  , lineN	// Counting \n's
	  , lineT	// Highest of \r's and \n's
	  , lineC	// Character in line
	  , pos;	// Byte position in file
	char *name
	   , *value
	   , *config;
	state state;
	letter l;
	size_t filesize;

	filesize = getFilesize(filename);

	/* Open file */
	fd = open(filename, O_RDONLY, 0);
	if (fd == -1) {
		/* Do not throw an error on EACCES, to allow blindly reading
		 * the 'global' followed by the 'root only' configurations to
		 * simplify overall code.
		 */
		if (errno != EACCES) {
			parser_error("readable file", "unreadable file", -1, -1);
		}

		return;
	}

	/* Execute mmap */
	config = mmap(NULL, filesize, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0);
	if (config == MAP_FAILED) {
		parser_error("mmapable file", "error mmapping file", -1, -1);
		goto abort_mmap;
	}

	name = value = NULL;
	nameStart = nameStop = valueStart = valueStop = pos = 0;
	lineR = lineN = lineC = lineT = 1;
	state = STATE_START_OF_LINE;
	do {
		switch(config[pos]) {
			case '\r':
				lineR++;
				lineT = max(lineR, lineN);
				lineC = 1;
				l = LETTER_END_OF_LINE;
				break;
			case '\n':
				lineN++;
				lineT = max(lineR, lineN);
				lineC = 1;
				l = LETTER_END_OF_LINE;
				break;
			case ' ':
			case '\t':
				l = LETTER_WHITESPACE;
				break;
			case '=':
				l = LETTER_EQUAL;
				break;
			case '#':
				l = LETTER_COMMENT;
				break;
			default:
				if ((config[pos] < ' ')
				 || (config[pos] > '~')) {
					l = LETTER_INVALID;
					parser_error("valid character", "invalid character", lineT, lineC);
					state = STATE_COMMENT_OR_ERROR;
					break;
				}
				l = LETTER_LETTER;
				break;
		}

		switch(state) {
		case STATE_COMMENT_OR_ERROR: switch(l) {
			case LETTER_END_OF_LINE:
				state = STATE_START_OF_LINE;
				break;
			default:
				break;
			} break;
		case STATE_START_OF_LINE: switch(l) {
			case LETTER_END_OF_LINE:
			case LETTER_WHITESPACE:
				break;
			case LETTER_EQUAL:
				parser_error("option name", "=", lineT, lineC);
				state = STATE_COMMENT_OR_ERROR;
				break;
			case LETTER_COMMENT:
				state = STATE_COMMENT_OR_ERROR;
				break;
			case LETTER_LETTER:
			default:
				nameStart = pos;
				nameStop = pos;
				state = STATE_NAME;
				break;
			} break;
		case STATE_NAME: switch(l) {
			case LETTER_END_OF_LINE:
				parser_error("=", "end of line", lineT, lineC);
				state = STATE_COMMENT_OR_ERROR;
				break;
			case LETTER_WHITESPACE:
				state = STATE_PRE_EQUAL;
				break;
			case LETTER_EQUAL:
				state = STATE_POST_EQUAL;
				break;
			case LETTER_COMMENT:
				parser_error("=", "comment", lineT, lineC);
				state = STATE_COMMENT_OR_ERROR;
				break;
			case LETTER_LETTER:
			default:
				nameStop = pos;
				break;
			} break;
		case STATE_PRE_EQUAL: switch(l) {
			case LETTER_WHITESPACE:
				break;
			case LETTER_EQUAL:
				state = STATE_POST_EQUAL;
				break;
			default:
				parser_error("= or more whitespace", "gibberish", lineT, lineC);
				state = STATE_COMMENT_OR_ERROR;
				break;
			} break;
		case STATE_POST_EQUAL: switch(l) {
			case LETTER_END_OF_LINE:
				parser_error("option value or more whitespace", "end of line", lineT, lineC);
				state = STATE_COMMENT_OR_ERROR;
				break;
			case LETTER_WHITESPACE:
				break;
			case LETTER_EQUAL:
			case LETTER_COMMENT:
			case LETTER_LETTER:
			default:
				valueStart = pos;
				valueStop = pos;
				state = STATE_VALUE;
				break;
			} break;
		case STATE_VALUE: switch(l) {
			case LETTER_END_OF_LINE:
				name = strndup((char *)config + nameStart, nameStop - nameStart + 1);
				value = strndup((char *)config + valueStart, valueStop - valueStart + 1);
				option_set(name, value);
				free(name);
				free(value);
				state = STATE_START_OF_LINE;
				break;
			case LETTER_WHITESPACE:
			case LETTER_EQUAL:
			case LETTER_COMMENT:
			case LETTER_LETTER:
			default:
				valueStop = pos;
				break;
			} break;
		}
		pos++;
		lineC++;
	} while (pos < filesize);

	/* End-of-File handling. */
	switch(state) {
	case STATE_NAME:
	case STATE_PRE_EQUAL:
		parser_error("=", "end of file", lineT, lineC);
		break;
	case STATE_POST_EQUAL:
		parser_error("option value", "end of file", lineT, lineC);
		break;
	case STATE_START_OF_LINE:
	case STATE_COMMENT_OR_ERROR:
	case STATE_VALUE:
	default:
		/* Valid end of file location, no issue. */
		break;
	}

	/* Cleanup */

	munmap(config, filesize);

abort_mmap:
	close(fd);
}
Esempio n. 27
0
static void parse_util_args (int argc, char *argv[], FileList *f)
{
  char  c;
  int   i;
  char  fname[FILENAME_MAX];

  if (argc == 0) {
    fputs (usage, stderr);
    exit  (1);
  }

  option_set("SingMesh",0);

  while (--argc && (*++argv)[0] == '-') {
    while (c = *++argv[0])                  /* more to parse... */
      switch (c) {
      case 'b':
  option_set("Body",1);
  break;
      case 'e':
  if (*++argv[0])
    option_set("ELMTID", atoi(*argv));
  else {
    option_set("ELMTID", atoi(*++argv));
    argc--;
  }
  while(*++argv[0]); /* skip over whole number */

      case 'R':
  option_set("Range",1);
  break;
      case 'g':
  option_set("SingMesh",1);
  break;
      case 's':
  option_set("Spre",1);
  break;
      case 'q':
  option_set("Qpts",1);
  break;
      case 'f':
  option_set("FEstorage",1);
  break;
      case 'S':
  option_set("SMformat",1);
  break;
      default:
  fprintf(stderr, "%s: unknown option -- %c\n", prog, c);
  break;
      }
  }
#if DIM ==2
  if(iparam("NORDER-req") == UNSET) iparam_set("NORDER-req",8);
#endif

  /* open the .rea file */

  if ((*argv)[0] == '-') {
    f->rea.fp = stdin;
  } else {
    strcpy (fname, *argv);
    if ((f->rea.fp = fopen(fname, "r")) == (FILE*) NULL) {
      sprintf(fname, "%s.rea", *argv);
      if ((f->rea.fp = fopen(fname, "r")) == (FILE*) NULL) {
  fprintf(stderr, "%s: unable to open the input file -- %s or %s\n",
    prog, *argv, fname);
  exit(1);
      }
    }
    f->rea.name = strdup(fname);
  }

  if (option("verbose")) {
    fprintf (stderr, "%s: in = %s, rea = %s, out = %s\n", prog,
       f->in.name   ? f->in.name   : "<stdin>",  f->rea.name,
       f->out.name  ? f->out.name  : "<stdout>");
  }

  return;
}
Esempio n. 28
0
/**
 * This is the function called from wiz-debug.c.
 */
void stats_collect(void)
{
	static int simtype;
	static bool auto_flag;
	char buf[1024];

	/* Prompt the user for sim params */
	simtype = stats_prompt();

	/* Make sure the results are good! */
	if (!((simtype == 1) || (simtype == 2)))
		return; 

	/* Are we in diving or clearing mode */
	if (simtype == 2)
		clearing = TRUE;
	else
		clearing = FALSE;

	/* Open log file */
	path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "stats.log");
	stats_log = file_open(buf, MODE_WRITE, FTYPE_TEXT);

	/* Logging didn't work */
	if (!stats_log) {
		msg("Error - can't open stats.log for writing.");
		exit(1);
	}

	/* Turn on auto-more.  This will clear prompts for items
	 * that drop under the player, or that can't fit on the 
	 * floor due to too many items.  This is a very small amount
	 * of items, even on deeper levels, so it's not worth worrying
	 * too much about.
	 */
	 auto_flag = FALSE;
	 
	 if (!OPT(auto_more)) {
		/* Remember that we turned off auto_more */
		auto_flag = TRUE;

		/* Turn on auto-more */
		option_set(option_name(OPT_auto_more),TRUE);
	}

	/* Print heading for the file */
	print_heading();

	/* Make sure all stats are 0 */
	init_stat_vals();

	/* Select diving option */
	if (!clearing) diving_stats();

	/* Select clearing option */
	if (clearing) clearing_stats();

	/* Turn auto-more back off */
	if (auto_flag) option_set(option_name(OPT_auto_more), FALSE);

	/* Close log file */
	if (!file_close(stats_log)) {
		msg("Error - can't close randart.log file.");
		exit(1);
	}
}
Esempio n. 29
0
void option_init() {

   option_set("OptionFile","polyglot.ini");

   // options

   option_set("EngineName","<empty>");
   option_set("EngineDir",".");
   option_set("EngineCommand","<empty>");

   option_set("Log","false");
   option_set("LogFile","polyglot.log");

   option_set("Chess960","false");

   option_set("Resign","false");
   option_set("ResignMoves","3");
   option_set("ResignScore","600");

   option_set("MateScore","10000");

   option_set("Book","false");
   option_set("BookFile","book.bin");

   option_set("BookRandom","true");
   option_set("BookLearn","false");

   option_set("KibitzMove","false");
   option_set("KibitzPV","false");

   option_set("KibitzCommand","tellall");
   option_set("KibitzDelay","5");

   option_set("ShowPonder","true");

   // work-arounds

   option_set("UCIVersion","2");
   option_set("CanPonder","false");
   option_set("SyncStop","false");
   option_set("PromoteWorkAround","false");

   // option_set("","");
}
Esempio n. 30
0
Element_List *Grid::gen_aux_field(){
  int     L, qa, qb, qc=0, k;
  char    buf[BUFSIZ];
  char    buf_a[BUFSIZ];
  Element **new_E;
  register int i;

  option_set("NZ",1);
  option_set("NZTOT",1);

  /* set up modes and quadrature points */

  if(!( L = iparam("MODES")))
    {fputs("ReadMesh: Number of modes not specified\n",stderr);exit(-1);}

  /* note quadrature order reset for variable order runs */
  if(qa = iparam("LQUAD"));
  else qa = L + 1;

  if(qb = iparam("MQUAD"));
  else qb = L;

  if(qc = iparam("NQUAD"));
  else qc = L;

  iparam_set("ELEMENTS", nel);
  /* Set up a new element vector */
  QGmax = max(max(qa,qb),qc);
  LGmax = L;

  new_E = (Element**) malloc(nel*sizeof(Element*));

  Coord X;
  X.x = dvector(0,Max_Nverts-1);
  X.y = dvector(0,Max_Nverts-1);
  X.z = dvector(0,Max_Nverts-1);

  /* Read in mesh information */
  for(k = 0; k < nel; k++) {
    for(i=0;i<nverts[k];++i){
      X.x[i] = xcoords[vertids[k][vertexmap[k][i]]];
      X.y[i] = ycoords[vertids[k][vertexmap[k][i]]];
      X.z[i] = zcoords[vertids[k][vertexmap[k][i]]];
    }

    switch(nverts[k]){
    case 4:
      new_E[k]   = new       Tet(k,'u', L, qa, qb, qb, &X);
      break;
    case 8:
      new_E[k]   = new       Hex(k,'u', L, qa, qa, qa, &X);
      break;
    case 6:
      new_E[k]   = new       Prism(k,'u', L, qa, qa, qb, &X);
      break;
    case 5:
      new_E[k]   = new       Pyr(k,'u', L, qa, qa, qb, &X);
      break;
    }
  }

  for(k = 0; k < nel-1; ++k)     new_E[k]->next = new_E[k+1];
  new_E[k]->next = (Element*) NULL;

  Element_List* E_List = (Element_List*) new Element_List(new_E, nel);

  E_List->Cat_mem();
  Tri_work();
  Quad_work();

  for(k = 0; k < nel; ++k)
    new_E[k]->set_curved_elmt(E_List);
  for(k = 0; k < nel; ++k)
    new_E[k]->set_geofac();

  return E_List;
}