-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoption.c
414 lines (294 loc) · 12.1 KB
/
option.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
// option.c
// includes
#include <stdlib.h>
#include <string.h>
#include "option.h"
#include "util.h"
// defines
#define NNB { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }
// constants
static const bool UseDebug = FALSE;
// variables
option_list_t Option[1];
option_t DefaultOptions[] = {
// options
{ "SettingsFile", "file","0","0", "polyglot.ini", NULL,0,NNB, PG|XBOARD|XBSEL},
{ "SettingsDir", "path","0","0", "<empty>" , NULL,0,NNB, PG},
{ "OnlyWbOptions", "check","0","0", "true" , NULL,0,NNB, PG|XBOARD},
{ "EngineName", "string","0","0", "<empty>" , NULL,0,NNB, PG},
{ "EngineDir", "path","0","0", "." , NULL,0,NNB, PG},
{ "EngineCommand", "string","0","0", "<empty>" , NULL,0,NNB, PG},
//UT: Added more options
{ "NodesLimit", "string","0","0", "<empty>" , NULL,0,NNB, PG|XBOARD|UCI},
{ "DepthLimit", "string","0","0", "<empty>" , NULL,0,NNB, PG|XBOARD|UCI},
{ "Movetime", "string","0","0", "<empty>" , NULL,0,NNB, PG|XBOARD|UCI},
{ "AverageMovetime", "string","0","0", "<empty>" , NULL,0,NNB, PG|XBOARD|UCI},
{ "AverageMovetimeWindow","string","0","0", "10" , NULL,0,NNB, PG|XBOARD|UCI},
{ "HostCalibration", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
{ "Hosts", "string","0","0", "<empty>" , NULL,0,NNB, PG},
{ "HostsPerformance", "string","0","0", "<empty>" , NULL,0,NNB, PG},
{ "HostPerformanceFactor", "string","0","0", "1.0" , NULL,0,NNB, PG|XBOARD|UCI},
{ "PlainGo", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
{ "Log", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
{ "LogFile", "file","0","0", "polyglot.log", NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
{ "UCI", "check","0","0", "false" , NULL,0,NNB, PG},
{ "UseNice", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|UCI},
{ "NiceValue", "spin", "0","20", "5" , NULL,0,NNB, PG|XBOARD|UCI},
{ "Resign", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL},
{ "ResignMoves", "spin","0","10000", "3" , NULL,0,NNB, PG|XBOARD|XBSEL},
{ "QueenNeverResigns","check","0","0", "true" , NULL,0,NNB, PG|XBOARD|XBSEL},
{ "ResignScore", "spin","0","10000", "600" , NULL,0,NNB, PG|XBOARD|XBSEL},
{ "HandleDraws", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL},
{ "ContemptScore", "spin","0","10000", "30" , NULL,0,NNB, PG|XBOARD|XBSEL},
{ "MateScore", "spin","0","100000", "0" , NULL,0,NNB, PG|XBOARD},
{ "Book", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
{ "BookFile", "file","0","0", "book.bin" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
{ "BookRandom", "check","0","0", "true" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
{ "BookDepth", "spin","0","256", "256" , NULL,0,NNB, PG|XBOARD|XBSEL|UCI},
{ "BookTreshold", "spin","0","1000", "5" , NULL,0,NNB, PG|XBOARD|UCI},
{ "BookLearn", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD},
{ "ShowTbHits", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL},
{ "KibitzMove", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD},
{ "KibitzPV", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD},
{ "KibitzCommand", "string","0","0", "tellall" , NULL,0,NNB, PG|XBOARD},
{ "KibitzDelay", "spin","0","1000", "5" , NULL,0,NNB, PG|XBOARD},
{ "KibitzInterval", "spin","0","1000", "0" , NULL,0,NNB, PG|XBOARD},
{ "ShowPonder", "check","0","0", "true" , NULL,0,NNB, PG|XBOARD},
{ "ScoreWhite", "check","0","0", "false" , NULL,0,NNB, PG|XBOARD},
{ "STFudge", "spin","0","1000", "20" , NULL,0,NNB, PG|XBOARD|XBSEL},
// work-arounds
{ "UCIVersion", "spin","1","2", "2" , NULL,0,NNB, PG|XBOARD},
{ "CanPonder", "check","1","2", "false" , NULL,0,NNB, PG|XBOARD},
{ "SyncStop", "check","1","2", "false" , NULL,0,NNB, PG|XBOARD|XBSEL},
{ "Affinity", "spin","0","0", "FFFFFFFF" , NULL,0,NNB, PG|XBOARD},
{ "RepeatPV", "check","0","0", "true" , NULL,0,NNB, PG|XBOARD},
{ "PromoteWorkAround","check","0","0", "false" , NULL,0,NNB, PG|XBOARD},
// internal
{ "Chess960", "check","0","0", "false" , NULL,0,NNB, PG},
// These options flag various hacks in the source to work around
// WB quirks. They will eventually all be set to false. Probably
// in 4.5.0
{ "WbWorkArounds", "check","0","0", "true" , NULL,0,NNB, PG},
{ "WbWorkArounds2", "check","0","0", "false" , NULL,0,NNB, PG},
{ "WbWorkArounds3", "check","0","0", "true" , NULL,0,NNB, PG},
// Buttons
{ "Save", "save","0","0", "false" , NULL,0,NNB, PG|XBOARD|XBSEL},
// Sentinel
{ NULL, NULL,"0","0", NULL , NULL,0,NNB, 0},
};
// functions
// option_is_ok()
bool option_is_ok(const option_list_t *option) {
if(option->option_nb<0 || option->option_nb>=OptionNb){
return FALSE;
}
return TRUE;
}
// option_init_pg()
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);
}
// option_init()
void option_init(option_list_t *option){
ASSERT(option!=NULL);
option->option_nb=0;
option->iter=0;
memset(option->options,0,sizeof(option->options));
}
// option_insert()
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;
}
// option_set()
bool option_set(option_list_t *option,
const char name[],
const char value[]) {
option_t * opt;
ASSERT(option!=NULL);
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->value,value);
if (UseDebug) my_log("POLYGLOT OPTION SET \"%s\" -> \"%s\"\n",opt->name,opt->value);
return TRUE;
}
// option_set_default()
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;
}
// option_get()
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;
}
// option_get_default()
const char * option_get_default(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->default_;
}
// option_get_bool()
bool option_get_bool(option_list_t *option, const char name[]) {
const char * value;
value = option_get(option,name);
if (FALSE) {
} else if (my_string_case_equal(value,"true") || my_string_case_equal(value,"yes") || my_string_equal(value,"1")) {
return TRUE;
} else if (my_string_case_equal(value,"false") || my_string_case_equal(value,"no") || my_string_equal(value,"0")) {
return FALSE;
}
ASSERT(FALSE);
return FALSE;
}
// option_get_double()
double option_get_double(option_list_t *option, const char name[]) {
const char * value;
value = option_get(option,name);
return atof(value);
}
// option_get_int()
int option_get_int(option_list_t *option, const char name[]) {
const char * value;
value = option_get(option,name);
return atoi(value);
}
// option_get_string()
const char * option_get_string(option_list_t *option, const char name[]) {
const char * value;
value = option_get(option,name);
return value;
}
// option_find()
option_t * option_find(option_list_t *option, const char name[]) {
option_t * opt;
int i;
ASSERT(name!=NULL);
for (i=0; i<option->option_nb; i++){
opt=option->options+i;
if (my_string_case_equal(opt->name,name)){
return opt;
}
}
return NULL;
}
// option_start_iter()
void option_start_iter(option_list_t *option){
option->iter=0;
}
// option_next()
option_t * option_next(option_list_t *option){
ASSERT(option->iter<=option->option_nb);
if(option->iter==option->option_nb){
return NULL;
}
return &option->options[option->iter++];
}
void option_free(option_t *option){
int i;
my_string_clear(&option->name);
my_string_clear(&option->type);
my_string_clear(&option->min);
my_string_clear(&option->max);
my_string_clear(&option->default_);
my_string_clear(&option->value);
for(i=0;i<option->var_nb;i++){
my_string_clear(&option->var[i]);
}
option->var_nb=0;
option->mode=0;
}
// option_clear()
void option_clear(option_list_t *option){
int i;
for (i = 0; i < option->option_nb; i++) {
option_free(option->options+i);
}
option->option_nb=0;
}
// option_from_ini()
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);
}
}
// end of option.cpp