15 #define NNB { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }
19 static const bool UseDebug = FALSE;
24 option_list_t Option[1];
26 option_t DefaultOptions[] = {
29 { "SettingsFile", "file","0","0", "polyglot.ini", NULL,0,NNB, PG|XBOARD|XBSEL},
31 { "SettingsDir", "path","0","0", "<empty>" , NULL,0,NNB, PG},
33 { "OnlyWbOptions", "check","0","0", "true" , NULL,0,NNB, PG|XBOARD},
35 { "EngineName", "string","0","0", "<empty>" , NULL,0,NNB, PG},
36 { "EngineDir", "path","0","0", "." , NULL,0,NNB, PG},
37 { "EngineCommand", "string","0","0", "<empty>" , NULL,0,NNB, PG},
39 { "Log", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
40 { "LogFile", "file","0","0", "polyglot.log", NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
42 { "UCI", "check","0","0", "false" , NULL,0,NNB, PG},
44 { "UseNice", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|UCI},
45 { "NiceValue", "spin", "0","20", "5" , NULL,0,NNB, PG|XBOARD|UCI},
47 { "Resign", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL},
48 { "ResignMoves", "spin","0","10000", "3" , NULL,0,NNB, PG|XBOARD|XBSEL},
49 { "QueenNeverResigns","check","0","0", "true" , NULL,0,NNB, PG|XBOARD|XBSEL},
50 { "ResignScore", "spin","0","10000", "600" , NULL,0,NNB, PG|XBOARD|XBSEL},
51 { "HandleDraws", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL},
52 { "ContemptScore", "spin","0","10000", "30" , NULL,0,NNB, PG|XBOARD|XBSEL},
54 { "MateScore", "spin","0","100000", "10000" , NULL,0,NNB, PG|XBOARD},
56 { "Book", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
57 { "BookFile", "file","0","0", "book.bin" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
59 { "BookRandom", "check","0","0", "true" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
60 { "BookDepth", "spin","0","256", "256" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
61 { "BookTreshold", "spin","0","1000", "5" , NULL,0,NNB, PG|XBOARD|UCI},
62 { "BookLearn", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD},
64 { "KibitzMove", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD},
65 { "KibitzPV", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD},
67 { "KibitzCommand", "string","0","0", "tellall" , NULL,0,NNB, PG|XBOARD},
68 { "KibitzDelay", "spin","0","1000", "5" , NULL,0,NNB, PG|XBOARD},
69 { "KibitzInterval", "spin","0","1000", "0" , NULL,0,NNB, PG|XBOARD},
71 { "ShowPonder", "check","0","0", "true" , NULL,0,NNB, PG|XBOARD},
72 { "ScoreWhite", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD},
74 { "STFudge", "spin","0","1000", "20" , NULL,0,NNB, PG|XBOARD|XBSEL},
78 { "UCIVersion", "spin","1","2", "2" , NULL,0,NNB, PG|XBOARD},
79 { "CanPonder", "check","1","2", "false" , NULL,0,NNB, PG|XBOARD},
80 { "SyncStop", "check","1","2", "false" , NULL,0,NNB, PG|XBOARD|XBSEL},
81 { "Affinity", "spin","-1","32", "-1" , NULL,0,NNB, PG},
82 { "RepeatPV", "check","0","0", "true" , NULL,0,NNB, PG|XBOARD},
83 { "PromoteWorkAround","check","0","0", "false" , NULL,0,NNB, PG|XBOARD},
87 { "Chess960", "check","0","0", "false" , NULL,0,NNB, PG},
89 // These options flag various hacks in the source to work around
90 // WB quirks. They will eventually all be set to false. Probably
93 { "WbWorkArounds", "check","0","0", "true" , NULL,0,NNB, PG},
94 { "WbWorkArounds2", "check","0","0", "false" , NULL,0,NNB, PG},
95 { "WbWorkArounds3", "check","0","0", "true" , NULL,0,NNB, PG},
99 { "Save", "save","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL},
103 { NULL, NULL,"0","0", NULL , NULL,0,NNB, 0},
112 bool option_is_ok(const option_list_t *option) {
113 if(option->option_nb<0 || option->option_nb>=OptionNb){
121 void option_init_pg() {
124 option_t *p=DefaultOptions;
126 char SettingsDir[StringSize];
131 option_insert(Option,p);
137 for(i=0;i<Option->option_nb;i++){
138 Option->options[i].value=my_strdup(Option->options[i].default_);
141 home_dir=getenv("HOME");
145 snprintf(SettingsDir,sizeof(SettingsDir),"%s/.polyglot",home_dir);
146 SettingsDir[sizeof(SettingsDir)-1]='\0';
148 sprintf(SettingsDir,".\\_PG");
150 option_set(Option,"SettingsDir",SettingsDir);
151 option_set_default(Option,"SettingsDir",SettingsDir);
156 void option_init(option_list_t *option){
157 ASSERT(option!=NULL);
160 memset(option->options,0,sizeof(option->options));
165 void option_insert(option_list_t *option, option_t *new_option){
168 ASSERT(option!=NULL);
169 ASSERT(new_option!=NULL);
170 ASSERT(new_option->name!=NULL);
171 opt=option_find(option,new_option->name);
173 opt=&option->options[option->option_nb];
176 if(option->option_nb>=OptionNb){
177 my_fatal("option_insert(): option list overflow\n");
179 if(new_option->name) my_string_set(&opt->name, new_option->name);
180 if(new_option->value) my_string_set(&opt->value, new_option->value);
181 if(new_option->min) my_string_set(&opt->min, new_option->min);
182 if(new_option->max) my_string_set(&opt->max, new_option->max);
183 if(new_option->default_) my_string_set(&opt->default_, new_option->default_);
184 if(new_option->type) my_string_set(&opt->type, new_option->type);
185 opt->var_nb=new_option->var_nb;
186 for(i=0;i<new_option->var_nb;i++){
187 my_string_set(&opt->var[i], new_option->var[i]);
189 opt->mode=new_option->mode;
194 bool option_set(option_list_t *option,
196 const char value[]) {
199 ASSERT(option!=NULL);
203 opt = option_find(option,name);
204 if (opt == NULL) return FALSE;
206 if(my_string_case_equal(opt->type,"check")){
207 value=(my_string_equal(value,"1")||
208 my_string_case_equal(value,"true"))?"true":"false";
211 my_string_set(&opt->value,value);
213 if (UseDebug) my_log("POLYGLOT OPTION SET \"%s\" -> \"%s\"\n",opt->name,opt->value);
218 // option_set_default()
220 bool option_set_default(option_list_t *option,
222 const char value[]) {
228 opt = option_find(option,name);
229 if (opt == NULL) return FALSE;
231 if(my_string_case_equal(opt->type,"check")){
232 value=(my_string_equal(value,"1")||
233 my_string_case_equal(value,"true"))?"true":"false";
236 my_string_set(&opt->default_,value);
238 if (UseDebug) my_log("POLYGLOT OPTION DEFAULT SET \"%s\" -> \"%s\"\n",opt->name,opt->default_);
245 const char * option_get(option_list_t *option, const char name[]) {
251 opt = option_find(option,name);
252 if (opt == NULL) my_fatal("option_get(): unknown option \"%s\"\n",name);
253 if (UseDebug) my_log("POLYGLOT OPTION GET \"%s\" -> \"%s\"\n",opt->name,opt->value);
258 // option_get_default()
260 const char * option_get_default(option_list_t *option, const char name[]) {
266 opt = option_find(option,name);
267 if (opt == NULL) my_fatal("option_get(): unknown option \"%s\"\n",name);
269 if (UseDebug) my_log("POLYGLOT OPTION GET \"%s\" -> \"%s\"\n",opt->name,opt->value);
271 return opt->default_;
276 bool option_get_bool(option_list_t *option, const char name[]) {
280 value = option_get(option,name);
283 } else if (my_string_case_equal(value,"true") || my_string_case_equal(value,"yes") || my_string_equal(value,"1")) {
285 } else if (my_string_case_equal(value,"false") || my_string_case_equal(value,"no") || my_string_equal(value,"0")) {
295 // option_get_double()
297 double option_get_double(option_list_t *option, const char name[]) {
301 value = option_get(option,name);
308 int option_get_int(option_list_t *option, const char name[]) {
312 value = option_get(option,name);
317 // option_get_string()
319 const char * option_get_string(option_list_t *option, const char name[]) {
323 value = option_get(option,name);
330 option_t * option_find(option_list_t *option, const char name[]) {
336 for (i=0; i<option->option_nb; i++){
337 opt=option->options+i;
338 if (my_string_case_equal(opt->name,name)){
346 // option_start_iter()
348 void option_start_iter(option_list_t *option){
354 option_t * option_next(option_list_t *option){
355 ASSERT(option->iter<=option->option_nb);
356 if(option->iter==option->option_nb){
359 return &option->options[option->iter++];
363 void option_free(option_t *option){
365 my_string_clear(&option->name);
366 my_string_clear(&option->type);
367 my_string_clear(&option->min);
368 my_string_clear(&option->max);
369 my_string_clear(&option->default_);
370 my_string_clear(&option->value);
371 for(i=0;i<option->var_nb;i++){
372 my_string_clear(&option->var[i]);
380 void option_clear(option_list_t *option){
382 for (i = 0; i < option->option_nb; i++) {
383 option_free(option->options+i);
390 void option_from_ini(option_list_t *option,
392 const char *section){
395 while((entry=ini_next(ini))){
396 option_set(option,entry->name,entry->value);
397 option_set_default(option,entry->name,entry->value);