3 Copyright (c) Scott Gasch
11 This is code that implements variables in the engine. Some of
12 these variables are read only but others can be set by the engine
13 user to affect certain aspects of engine operation.
21 $Id: vars.c 345 2007-12-02 22:56:42Z scott $
27 extern ULONG g_uNumInputEvents;
29 typedef void(PUSERVARFUN)(void);
32 // Here's how we expose engine variables to the user.
34 typedef struct _USER_VARIABLE
36 char *szName; // variable name
37 char *szType; // variable type:
38 // * - char *, strdup/free
46 void *pValue; // pointer to value
47 PUSERVARFUN *pFunction; // funct to call when it changes
50 extern ULONG g_uBookProbeFailures;
52 USER_VARIABLE g_UserVarList[] =
56 (void *)&(g_Options.fShouldAnnounceOpening),
60 (void *)&(g_Options.fNoInputThread),
64 (void *)&(g_GameData.sHeader.sPlayer[BLACK].szName),
68 (void *)&(g_GameData.sHeader.sPlayer[BLACK].uRating),
72 (void *)&(g_GameData.sHeader.sPlayer[BLACK].szDescription),
76 (void *)&(g_GameData.sHeader.sPlayer[BLACK].fIsComputer),
80 (void *)&(g_Options.szBookName),
82 { "BookProbeFailures",
84 (void *)&(g_uBookProbeFailures),
86 { "ComputerTimeRemainingSec",
88 (void *)&(g_Options.uOpponentsClock),
89 NULL }, //&DoVerifyClocks },
92 (void *)&(g_Options.szEGTBPath),
96 (void *)&(g_Options.fFastScript),
100 (void *)&(g_GameData.sHeader.szGameDescription),
104 (void *)&(g_GameData.sHeader.szLocation),
108 (void *)&(g_GameData.sHeader.fGameIsRated),
110 { "GameResultComment",
112 (void *)&(g_GameData.sHeader.szResultComment),
116 (void *)&(g_Options.iLastEvalScore),
120 (void *)&(g_Options.szLogfile),
124 (void *)&(g_Options.mvPonder),
126 { "MovesPerTimePeriod",
128 (void *)&(g_Options.uMovesPerTimePeriod),
130 { "OpponentTimeRemainingSec",
132 (void *)&(g_Options.uMyClock),
133 NULL }, //&DoVerifyClocks },
134 { "PendingInputEvents",
136 (void *)&(g_uNumInputEvents),
140 (void *)&(g_Options.fPondering),
144 (void *)&(g_Options.fShouldPost),
148 (void *)&(g_Options.fShouldResign),
150 { "SearchDepthLimit",
152 (void *)&(g_Options.uMaxDepth),
153 NULL }, //&DoVerifySearchDepth },
156 (void *)&(g_Options.uMyIncrement),
157 NULL }, //&DoVerifySearchTime },
158 { "SearchStartedTime",
160 (void *)&(g_MoveTimer.dStartTime),
162 { "SearchSoftTimeLimit",
164 (void *)&(g_MoveTimer.dSoftTimeLimit),
166 { "SearchHardTimeLimit",
168 (void *)&(g_MoveTimer.dHardTimeLimit),
170 { "SearchNodesBetweenTimeCheck",
172 (void *)&(g_MoveTimer.uNodeCheckMask),
176 (void *)&(g_Options.fStatusLine),
178 { "ThinkOnOpponentsTime",
180 (void *)&(g_Options.fShouldPonder),
184 (void *)&(g_Options.fThinking),
188 (void *)&(g_fTournamentMode),
192 (void *)&(g_Options.fVerbosePosting),
196 (void *)&(g_GameData.sHeader.sPlayer[WHITE].szName),
200 (void *)&(g_GameData.sHeader.sPlayer[WHITE].uRating),
202 { "WhiteDescription",
204 (void *)&(g_GameData.sHeader.sPlayer[WHITE].szDescription),
208 (void *)&(g_GameData.sHeader.sPlayer[WHITE].fIsComputer),
212 (void *)&(g_Options.fRunningUnderXboard),
224 This function implements the 'set' engine command.
228 set [variable name [value]]
230 With no arguments, set dumps a list of all variables and their
233 With one argument, set displays the specified variable's value.
235 With two arguments, set changes the value of the specified
236 variable to the given value.
240 The COMMAND macro hides four arguments from the input parser:
242 CHAR *szInput : the full line of input
243 ULONG argc : number of argument chunks
244 CHAR *argv[] : array of ptrs to each argument chunk
245 POSITION *pos : a POSITION pointer to operate on
259 x < ARRAY_SIZE(g_UserVarList);
262 switch(toupper(g_UserVarList[x].szType[0]))
266 Trace("%-28s => %u\n",
267 g_UserVarList[x].szName,
268 *((unsigned int *)g_UserVarList[x].pValue));
271 Trace("%-28s => %d\n",
272 g_UserVarList[x].szName,
273 *((int *)g_UserVarList[x].pValue));
276 Trace("%-28s => \"%s\"\n",
277 g_UserVarList[x].szName,
278 (char *)g_UserVarList[x].pValue);
281 Trace("%-28s => \"%s\"\n",
282 g_UserVarList[x].szName,
283 MoveToIcs(*((MOVE *)g_UserVarList[x].pValue)));
286 Trace("%-28s => \"%s\"\n",
287 g_UserVarList[x].szName,
288 (*((FLAG *)g_UserVarList[x].pValue) == TRUE) ?
292 Trace("%-28s => %f\n",
293 g_UserVarList[x].szName,
294 *((double *)g_UserVarList[x].pValue));
297 Trace("%-28s => \"%s\"\n",
298 g_UserVarList[x].szName,
299 *((char **)g_UserVarList[x].pValue));
302 Trace("%-28s => ???\n",
303 g_UserVarList[x].szName);
314 x < ARRAY_SIZE(g_UserVarList);
317 if (!STRNCMPI(argv[1],
318 g_UserVarList[x].szName,
322 switch(toupper(g_UserVarList[x].szType[0]))
326 Trace("%-28s => %u\n",
327 g_UserVarList[x].szName,
328 *((unsigned int *)g_UserVarList[x].pValue));
331 Trace("%-28s => %d\n",
332 g_UserVarList[x].szName,
333 *((int *)g_UserVarList[x].pValue));
336 Trace("%-28s => \"%s\"\n",
337 g_UserVarList[x].szName,
338 (char *)g_UserVarList[x].pValue);
341 Trace("%-28s => \"%s\"\n",
342 g_UserVarList[x].szName,
343 MoveToIcs(*((MOVE *)g_UserVarList[x].pValue)));
346 Trace("%-28s => \"%s\"\n",
347 g_UserVarList[x].szName,
348 (*((FLAG *)g_UserVarList[x].pValue) == TRUE) ?
352 Trace("%-28s => %f\n",
353 g_UserVarList[x].szName,
354 *((double *)g_UserVarList[x].pValue));
357 Trace("%-28s => \"%s\"\n",
358 g_UserVarList[x].szName,
359 *((char **)g_UserVarList[x].pValue));
362 Trace("%-28s => ???\n",
363 g_UserVarList[x].szName);
372 Trace("Error (invalid variable): %s\n", argv[1]);
383 x < ARRAY_SIZE(g_UserVarList);
386 if (!STRNCMPI(argv[1],
387 g_UserVarList[x].szName,
392 if (islower(g_UserVarList[x].szType[0]))
394 Trace("Error (variable is read only): %s\n",
398 switch(g_UserVarList[x].szType[0])
402 if ((y < 0) || (y & (y - 1)))
404 Trace("Error (invalid size): %d\n", y);
408 *((int *)g_UserVarList[x].pValue) = y;
413 if (NULL != *((char **)g_UserVarList[x].pValue))
415 SystemFreeMemory( *((char **)g_UserVarList[x].pValue ) );
417 *((char **)g_UserVarList[x].pValue) = STRDUP(argv[2]);
418 if (NULL == *((char **)g_UserVarList[x].pValue))
420 Trace("Error (out of memory)\n");
426 strncpy(((char *)g_UserVarList[x].pValue),
435 Trace("Error (invalid value): %d\n", y);
438 *((unsigned *)g_UserVarList[x].pValue) = y;
443 *((int *)g_UserVarList[x].pValue) = y;
447 if (toupper(*(argv[2])) == 'T')
449 *((FLAG *)g_UserVarList[x].pValue) = TRUE;
451 else if (toupper(*(argv[2])) == 'F')
453 *((FLAG *)g_UserVarList[x].pValue) = FALSE;
457 Trace("Error (invalid value, must be TRUE or "
458 "FALSE): %s\n", argv[2]);
467 if (NULL != g_UserVarList[x].pFunction)
469 (void)(g_UserVarList[x].pFunction)();
476 Trace("Error (invalid variable): %s\n", argv[1]);