void parse_net_options(list *options, network *net) { net->batch = option_find_int(options, "batch",1); net->learning_rate = option_find_float(options, "learning_rate", .001); net->momentum = option_find_float(options, "momentum", .9); net->decay = option_find_float(options, "decay", .0001); int subdivs = option_find_int(options, "subdivisions",1); net->time_steps = option_find_int_quiet(options, "time_steps",1); net->batch /= subdivs; net->batch *= net->time_steps; net->subdivisions = subdivs; net->h = option_find_int_quiet(options, "height",0); net->w = option_find_int_quiet(options, "width",0); net->c = option_find_int_quiet(options, "channels",0); net->inputs = option_find_int_quiet(options, "inputs", net->h * net->w * net->c); net->max_crop = option_find_int_quiet(options, "max_crop",net->w*2); net->min_crop = option_find_int_quiet(options, "min_crop",net->w); if(!net->inputs && !(net->h && net->w && net->c)) error("No input parameters supplied"); char *policy_s = option_find_str(options, "policy", "constant"); net->policy = get_policy(policy_s); if(net->policy == STEP){ net->step = option_find_int(options, "step", 1); net->scale = option_find_float(options, "scale", 1); } else if (net->policy == STEPS){ char *l = option_find(options, "steps"); char *p = option_find(options, "scales"); if(!l || !p) error("STEPS policy must have steps and scales in cfg file"); int len = strlen(l); int n = 1; int i; for(i = 0; i < len; ++i){ if (l[i] == ',') ++n; } int *steps = calloc(n, sizeof(int)); float *scales = calloc(n, sizeof(float)); for(i = 0; i < n; ++i){ int step = atoi(l); float scale = atof(p); l = strchr(l, ',')+1; p = strchr(p, ',')+1; steps[i] = step; scales[i] = scale; } net->scales = scales; net->steps = steps; net->num_steps = n; } else if (net->policy == EXP){ net->gamma = option_find_float(options, "gamma", 1); } else if (net->policy == SIG){ net->gamma = option_find_float(options, "gamma", 1); net->step = option_find_int(options, "step", 1); } else if (net->policy == POLY || net->policy == RANDOM){ net->power = option_find_float(options, "power", 1); } net->max_batches = option_find_int(options, "max_batches", 0); }
void xboard2uci_init() { // init game_clear(Game); // state State->state = WAIT; State->computer[White] = FALSE; State->computer[Black] = TRUE; State->exp_move = MoveNone; State->hint_move = MoveNone; State->resign_nb = 0; my_timer_reset(State->timer); // yes there are engines that do not have the "Hash" option.... XB->has_feature_memory= (option_find(Uci->option,"Hash")!=NULL); XB->has_feature_smp = (uci_thread_option(Uci)!=NULL); // TODO: support for other types of table bases // This is a quick hack. XB->has_feature_egt_nalimov = (option_find(Uci->option,"NalimovPath")!=NULL); XB->has_feature_egt_gaviota = (option_find(Uci->option,"GaviotaTbPath")!=NULL); XB->analyse = FALSE; XB->computer = FALSE; XB->name = NULL; my_string_set(&XB->name,"<empty>"); XB->ics = FALSE; XB->new_hack = TRUE; XB->ping = -1; XB->ponder = FALSE; XB->post = FALSE; XB->proto_ver = 1; XB->result = FALSE; XB->mps = 0; XB->base = 300.0; XB->inc = 0.0; XB->time_limit = FALSE; XB->time_max = 5.0; XB->depth_limit = FALSE; XB->depth_max = 127; XB->my_time = 300.0; XB->opp_time = 300.0; XB->node_rate = -1; }
int module_init(moduleoption *opt) { fitnessfunc *f; moduleoption *result; char *type; char fitnessname[256]; int n; resourcetype *time; time=restype_find("time"); if(time==NULL) { error(_("Resource type '%s' not found"), "time"); return -1; } n=res_get_matrix(time, &days, &periods); if(n) { error(_("Resource type %s is not a matrix"), "time"); return -1; } result=option_find(opt, "resourcetype"); if(result==NULL) { error(_("module '%s' has been loaded, but not used"), "freemorning.so"); } while(result!=NULL) { type=result->content_s; snprintf(fitnessname, 256, "freemorning-%s", type); f=fitness_new(fitnessname, option_int(opt, "weight"), option_int(opt, "mandatory"), fitness); if(f==NULL) return -1; n=fitness_request_ext(f, type, "time"); if(n) return -1; result=option_find(result->next, "resourcetype"); } n=option_int(opt, "first-period"); if(n>=0) first_period=n; return(0); }
float option_find_float(list *l, char *key, float def) { char *v = option_find(l, key); if(v) return atof(v); //fprintf(stderr, "%s: Using default '%lf'\n", key, def); return def; }
int option_find_int(list *l, char *key, int def) { char *v = option_find(l, key); if(v) return atoi(v); //fprintf(stderr, "%s: Using default '%d'\n", key, def); return def; }
char *option_find_str(list *l, char *key, char *def) { char *v = option_find(l, key); if(v) return v; //if(def) fprintf(stderr, "%s: Using default '%s'\n", key, def); return def; }
void option_insert(option_list_t *option, option_t *new_option){ int i; option_t *opt; ASSERT(option!=NULL); ASSERT(new_option!=NULL); ASSERT(new_option->name!=NULL); opt=option_find(option,new_option->name); if(!opt){ opt=&option->options[option->option_nb]; option->option_nb++; } if(option->option_nb>=OptionNb){ my_fatal("option_insert(): option list overflow\n"); } if(new_option->name) my_string_set(&opt->name, new_option->name); if(new_option->value) my_string_set(&opt->value, new_option->value); if(new_option->min) my_string_set(&opt->min, new_option->min); if(new_option->max) my_string_set(&opt->max, new_option->max); if(new_option->default_) my_string_set(&opt->default_, new_option->default_); if(new_option->type) my_string_set(&opt->type, new_option->type); opt->var_nb=new_option->var_nb; for(i=0;i<new_option->var_nb;i++){ my_string_set(&opt->var[i], new_option->var[i]); } opt->mode=new_option->mode; }
const char * option_get(const char var[]) { option_t * opt; ASSERT(var!=NULL); opt = option_find(var); if (opt == NULL) my_fatal("option_get(): unknown option \"%s\"\n",var); return opt->val; }
int pgut_getopt(int argc, char **argv, pgut_option options[]) { int c; int optindex = 0; char *optstring; struct option *longopts; pgut_option *opt; if (PROGRAM_NAME == NULL) { PROGRAM_NAME = get_progname(argv[0]); set_pglocale_pgservice(argv[0], "pgscripts"); } /* Help message and version are handled at first. */ if (argc > 1) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) { help(true); exit_or_abort(HELP); } if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) { fprintf(stderr, "%s %s\n", PROGRAM_NAME, PROGRAM_VERSION); exit_or_abort(HELP); } } /* Merge default and user options. */ longopts = option_merge(default_options, options); optstring = longopts_to_optstring(longopts); /* Assign named options */ while ((c = getopt_long(argc, argv, optstring, longopts, &optindex)) != -1) { opt = option_find(c, default_options, options); assign_option(opt, optarg, SOURCE_CMDLINE); } /* Read environment variables */ option_from_env(options); (void) (dbname || (dbname = getenv("PGDATABASE")) || (dbname = getenv("PGUSER")) || (dbname = get_username())); init_cancel_handler(); atexit(on_cleanup); return optind; }
const char * option_get(option_list_t *option, const char name[]) { option_t * opt; ASSERT(name!=NULL); opt = option_find(option,name); if (opt == NULL) my_fatal("option_get(): unknown option \"%s\"\n",name); if (UseDebug) my_log("POLYGLOT OPTION GET \"%s\" -> \"%s\"\n",opt->name,opt->value); return opt->value; }
const char * option_get(const char var[]) { option_t * opt; ASSERT(var!=NULL); opt = option_find(var); if (opt == NULL) my_fatal("option_get(): unknown option \"%s\"\n",var); if (UseDebug) my_log("POLYGLOT OPTION GET \"%s\" -> \"%s\"\n",opt->var,opt->val); return opt->val; }
int pgut_getopt(int argc, char **argv, pgut_option options[]) { int c; int optindex = 0; char *optstring; struct option *longopts; pgut_option *opt; pgut_init(argc, argv); /* Help message and version are handled at first. */ if (argc > 1) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) { help(true); exit(1); } if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) { printf("%s %s\n", PROGRAM_NAME, PROGRAM_VERSION); exit(1); } if (strcmp(argv[1], "--configuration") == 0) { printf("%s\n", PG_VERSION_STR); exit(0); } } /* Merge default and user options. */ longopts = option_merge(default_options, options); optstring = longopts_to_optstring(longopts); /* Assign named options */ while ((c = getopt_long(argc, argv, optstring, longopts, &optindex)) != -1) { opt = option_find(c, default_options, options); pgut_setopt(opt, optarg, SOURCE_CMDLINE); } /* Read environment variables */ option_from_env(options); (void) (dbname || (dbname = getenv("PGDATABASE")) || (dbname = getenv("PGUSER")) || (dbname = get_username())); return optind; }
bool option_set(const char var[], const char val[]) { option_t * opt; ASSERT(var!=NULL); ASSERT(val!=NULL); opt = option_find(var); if (opt == NULL) return false; my_string_set(&opt->val,val); return true; }
bool option_set(const char var[], const char val[]) { option_t * opt; ASSERT(var!=NULL); ASSERT(val!=NULL); opt = option_find(var); if (opt == NULL) return false; my_string_set(&opt->val,val); if (UseDebug) my_log("POLYGLOT OPTION SET \"%s\" -> \"%s\"\n",opt->var,opt->val); return true; }
layer parse_shortcut(list *options, size_params params, network net) { char *l = option_find(options, "from"); int index = atoi(l); if(index < 0) index = params.index + index; int batch = params.batch; layer from = net.layers[index]; layer s = make_shortcut_layer(batch, index, params.w, params.h, params.c, from.out_w, from.out_h, from.out_c); char *activation_s = option_find_str(options, "activation", "linear"); ACTIVATION activation = get_activation(activation_s); s.activation = activation; return s; }
route_layer parse_route(list *options, size_params params, network net) { char *l = option_find(options, "layers"); int len = strlen(l); if(!l) error("Route Layer must specify input layers"); int n = 1; int i; for(i = 0; i < len; ++i){ if (l[i] == ',') ++n; } int *layers = calloc(n, sizeof(int)); int *sizes = calloc(n, sizeof(int)); for(i = 0; i < n; ++i){ int index = atoi(l); l = strchr(l, ',')+1; if(index < 0) index = params.index + index; layers[i] = index; sizes[i] = net.layers[index].outputs; } int batch = params.batch; route_layer layer = make_route_layer(batch, n, layers, sizes); convolutional_layer first = net.layers[layers[0]]; layer.out_w = first.out_w; layer.out_h = first.out_h; layer.out_c = first.out_c; for(i = 1; i < n; ++i){ int index = layers[i]; convolutional_layer next = net.layers[index]; if(next.out_w == first.out_w && next.out_h == first.out_h){ layer.out_c += next.out_c; }else{ layer.out_h = layer.out_w = layer.out_c = 0; } } return layer; }
bool option_set_default(option_list_t *option, const char name[], const char value[]) { option_t * opt; ASSERT(name!=NULL); ASSERT(value!=NULL); opt = option_find(option,name); if (opt == NULL) return FALSE; if(my_string_case_equal(opt->type,"check")){ value=(my_string_equal(value,"1")|| my_string_case_equal(value,"true"))?"true":"false"; } my_string_set(&opt->default_,value); if (UseDebug) my_log("POLYGLOT OPTION DEFAULT SET \"%s\" -> \"%s\"\n",opt->name,opt->default_); return TRUE; }
static void send_xboard_options(){ char egtfeature[StringSize]; char variants[StringSize]; int tbs=0; gui_send(GUI,"feature done=0"); gui_send(GUI,"feature analyze=1"); gui_send(GUI,"feature colors=0"); gui_send(GUI,"feature draw=1"); gui_send(GUI,"feature ics=1"); gui_send(GUI,"feature myname=\"%s\"", option_get_string(Option,"EngineName")); gui_send(GUI,"feature name=1"); gui_send(GUI,"feature pause=0"); gui_send(GUI,"feature ping=1"); gui_send(GUI,"feature playother=1"); gui_send(GUI,"feature sigint=1"); gui_send(GUI,"feature reuse=1"); gui_send(GUI,"feature san=0"); gui_send(GUI,"feature setboard=1"); gui_send(GUI,"feature sigint=0"); gui_send(GUI,"feature sigterm=0"); gui_send(GUI,"feature time=1"); gui_send(GUI,"feature usermove=1"); gui_send(GUI,"feature nps=1"); if (XB->has_feature_memory){ gui_send(GUI,"feature memory=1"); }else{ gui_send(GUI,"feature memory=0"); } if (XB->has_feature_smp){ gui_send(GUI,"feature smp=1"); }else{ gui_send(GUI,"feature smp=0"); } egtfeature[0]='\0'; strncat(egtfeature,"feature egt=\"",StringSize); if (XB->has_feature_egt_nalimov){ tbs++; strncat(egtfeature,"nalimov",StringSize-strlen(egtfeature)); } if (XB->has_feature_egt_gaviota){ if(tbs>0){ strncat(egtfeature,",",StringSize-strlen(egtfeature)); } strncat(egtfeature,"gaviota",StringSize-strlen(egtfeature)); } strncat(egtfeature,"\"",StringSize-strlen(egtfeature)); egtfeature[StringSize-1]='\0'; gui_send(GUI,egtfeature); variants[0]='\0'; strncat(variants,"feature variants=\"normal",StringSize); if (option_find(Uci->option,"UCI_3Check")) { strncat(variants,",3check",StringSize-strlen(variants)); } if (option_find(Uci->option,"UCI_Chess960")) { strncat(variants,",fischerandom",StringSize-strlen(variants)); } if (option_find(Uci->option,"UCI_Atomic")) { strncat(variants,",atomic",StringSize-strlen(variants)); } if (option_find(Uci->option,"UCI_Horde")) { strncat(variants,",horde",StringSize-strlen(variants)); } strncat(variants,"\"",StringSize-strlen(variants)); variants[StringSize-1]='\0'; gui_send(GUI,variants); xboard2uci_send_options(); }
//! compile les shaders et construit le programme + les buffers + le vertex array. //! renvoie -1 en cas d'erreur. int init( std::vector<const char *>& options ) { widgets= create_widgets(); camera= make_orbiter(); program= 0; const char *option; option= option_find(options, ".glsl"); if(option != NULL) { program_filename= Filename(option); reload_program(); } glGenVertexArrays(1, &vao); vertex_count= 3; option= option_find(options, ".obj"); if(option != NULL) { mesh= read_mesh(option); if(mesh.positions.size() > 0) { mesh_filename= Filename(option); vao= make_mesh_vertex_format(mesh); vertex_count= (unsigned int) mesh.positions.size(); Point pmin, pmax; mesh_bounds(mesh, pmin, pmax); orbiter_lookat(camera, center(pmin, pmax), distance(pmin, pmax)); } } // charge les textures, si necessaire for(unsigned int i= 0; i < (unsigned int) options.size(); i++) { GLuint texture= read_texture(0, options[i]); if(texture > 0) { texture_filenames.push_back(Filename(options[i])); textures.push_back(texture); } } // nettoyage glUseProgram(0); glBindTexture(GL_TEXTURE_2D, 0); glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // etat openGL par defaut glClearColor(0.2f, 0.2f, 0.2f, 1.f); glClearDepth(1.f); glCullFace(GL_BACK); glFrontFace(GL_CCW); //~ glEnable(GL_CULL_FACE); // n'affiche que les faces correctement orientees... glDisable(GL_CULL_FACE); // les faces mal orientees sont affichees avec des hachures oranges... glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); return 0; }
int main(int argc, char **argv) { struct in_addr lease; struct dhcp_packet packet; unsigned char *p = packet.options; struct sockaddr_in dest; int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); ssize_t rc; if (argc < 2) { fprintf(stderr, "usage: dhcp_lease_time <address>\n"); exit(1); } if (fd == -1) { perror("cannot create socket"); exit(1); } lease.s_addr = inet_addr(argv[1]); memset(&packet, 0, sizeof(packet)); packet.hlen = 0; packet.htype = 0; packet.op = BOOTREQUEST; packet.ciaddr = lease; packet.cookie = htonl(DHCP_COOKIE); *(p++) = OPTION_MESSAGE_TYPE; *(p++) = 1; *(p++) = DHCPINFORM; /* Explicitly request the lease time, it won't be sent otherwise: this is a dnsmasq extension, not standard. */ *(p++) = OPTION_REQUESTED_OPTIONS; *(p++) = 1; *(p++) = OPTION_LEASE_TIME; *(p++) = OPTION_END; dest.sin_family = AF_INET; dest.sin_addr.s_addr = inet_addr("127.0.0.1"); dest.sin_port = ntohs(DHCP_SERVER_PORT); if (sendto(fd, &packet, sizeof(packet), 0, (struct sockaddr *)&dest, sizeof(dest)) == -1) { perror("sendto failed"); exit(1); } alarm(3); /* noddy timeout. */ rc = recv(fd, &packet, sizeof(packet), 0); if (rc < (ssize_t)(sizeof(packet) - sizeof(packet.options))) { perror("recv failed"); exit(1); } if ((p = option_find(&packet, (size_t)rc, OPTION_LEASE_TIME, 4))) { unsigned int t = option_uint(p, 4); if (t == 0xffffffff) printf("infinite"); else { unsigned int x; if ((x = t/86400)) printf("%ud", x); if ((x = (t/3600)%24)) printf("%uh", x); if ((x = (t/60)%60)) printf("%um", x); if ((x = t%60)) printf("%us", x); } return 0; } return 1; /* no lease */ }
int option_find_int_quiet(list *l, char *key, int def) { char *v = option_find(l, key); if(v) return atoi(v); return def; }
float option_find_float_quiet(list *l, char *key, float def) { char *v = option_find(l, key); if(v) return atof(v); return def; }
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; }
static int cmd_status(struct client *client) { const char *export_options[] = { "aaa_mode", "continue", "play_library", "play_sorted", "replaygain", "replaygain_limit", "replaygain_preamp", "repeat", "repeat_current", "shuffle", "softvol", NULL }; const struct track_info *ti; struct cmus_opt *opt; char optbuf[OPTION_MAX_SIZE]; GBUF(buf); int vol_left, vol_right; int i, ret; enum player_status status; player_info_lock(); gbuf_addf(&buf, "status %s\n", player_status_names[player_info.status]); ti = player_info.ti; if (ti) { gbuf_addf(&buf, "file %s\n", escape(ti->filename)); gbuf_addf(&buf, "duration %d\n", ti->duration); gbuf_addf(&buf, "position %d\n", player_info.pos); for (i = 0; ti->comments[i].key; i++) gbuf_addf(&buf, "tag %s %s\n", ti->comments[i].key, escape(ti->comments[i].val)); } /* add track metadata to cmus-status */ status = player_info.status; if (status == PLAYER_STATUS_PLAYING && ti && is_http_url(player_info.ti->filename)) { const char *title = get_stream_title(); if (title != NULL) { free(title_buf); title_buf = to_utf8(title, icecast_default_charset); // we have a stream title (probably artist/track/album info) gbuf_addf(&buf, "stream %s\n", escape(title_buf)); } else if (ti->comment != NULL) { // fallback to the radio station name gbuf_addf(&buf, "stream %s\n", escape(ti->comment)); } } /* output options */ for (i = 0; export_options[i]; i++) { opt = option_find(export_options[i]); if (opt) { opt->get(opt->id, optbuf); gbuf_addf(&buf, "set %s %s\n", opt->name, optbuf); } } /* get volume (copied from ui_curses.c) */ if (soft_vol) { vol_left = soft_vol_l; vol_right = soft_vol_r; } else if (!volume_max) { vol_left = vol_right = -1; } else { vol_left = scale_to_percentage(volume_l, volume_max); vol_right = scale_to_percentage(volume_r, volume_max); } /* output volume */ gbuf_addf(&buf, "set vol_left %d\n", vol_left); gbuf_addf(&buf, "set vol_right %d\n", vol_right); gbuf_add_str(&buf, "\n"); player_info_unlock(); ret = write_all(client->fd, buf.buffer, buf.len); gbuf_free(&buf); return ret; }
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(); } }
static bool ponder() { return XB->ponder && (option_get_bool(Option,"CanPonder") || option_find(Uci->option,"Ponder")); }
int pgut_getopt(int argc, char **argv, pgut_option options[]) { int c; int optindex = 0; char *optstring; struct option *longopts; pgut_option *opt; pgut_init(argc, argv); /* Help message and version are handled at first. */ if (argc > 1) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) { help(true); exit(1); } if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) { fprintf(stderr, "%s %s\n", PROGRAM_NAME, PROGRAM_VERSION); exit(1); } } /* Merge default and user options. */ longopts = option_merge(default_options, options); optstring = longopts_to_optstring(longopts); /* Assign named options */ while ((c = getopt_long(argc, argv, optstring, longopts, &optindex)) != -1) { /* Show help message if are specified '-?, --help' */ if (c == '?') { /* Actual help option given */ if (strcmp(argv[optind - 1], "-?") == 0 || strcmp(argv[optind - 1], "--help") == 0) { help(true); exit(1); } /* unknown option reported by getopt */ else { fprintf(stderr, "Try \"%s --help\" for more information.\n", PROGRAM_NAME); exit(EINVAL); } } /* Show version information if are specified '-V, --version' */ if (c == 'V') { fprintf(stderr, "%s %s\n", PROGRAM_NAME, PROGRAM_VERSION); exit(1); } opt = option_find(c, default_options, options); pgut_setopt(opt, optarg, SOURCE_CMDLINE); } /* Read environment variables */ option_from_env(options); return optind; }