Subversion Repositories Games.Chess Giants

Rev

Rev 39 | Rev 44 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 39 Rev 40
Line 4... Line 4...
4
 
4
 
5
 
5
 
6
// useful macros
6
// useful macros
7
#define READ_WIDESTRING(dest,inifile,section,key,default_value) wcscpy_s ((dest), sizeof (dest) / sizeof (wchar_t), INIFile_ReadEntryAsString ((inifile), (section), (key), (default_value)))
7
#define READ_WIDESTRING(dest,inifile,section,key,default_value) wcscpy_s ((dest), sizeof (dest) / sizeof (wchar_t), INIFile_ReadEntryAsString ((inifile), (section), (key), (default_value)))
8
#define WRITE_WIDESTRING(section,key,value) INIFile_WriteEntryAsString (inifile, (section), (key), (value))
8
#define WRITE_WIDESTRING(section,key,value) INIFile_WriteEntryAsString (inifile, (section), (key), (value))
-
 
9
 
-
 
10
 
-
 
11
// global variables used in this module only
-
 
12
static wchar_t filename[MAX_PATH];
9
 
13
 
10
 
14
 
11
void Config_Load (void)
15
void Config_Load (void)
12
{
16
{
13
   // this function opens and parses the INI configuration file for the program
17
   // this function opens and parses the INI configuration file for the program
14
   // WARNING: it does also build the smilies list !
18
   // WARNING: it does also build the smilies list !
15
 
19
 
16
   wchar_t filename[MAX_PATH];
-
 
17
   void *inifile;
20
   void *inifile;
18
   void *engine_inifile;
-
 
19
   smiley_t *smiley;
21
   smiley_t *smiley;
20
   char *file_buffer;
22
   char *file_buffer;
21
   wchar_t smiley_pathname[MAX_PATH];
23
   wchar_t smiley_pathname[MAX_PATH];
22
   wchar_t *smiley_name;
24
   wchar_t *smiley_name;
23
   wchar_t *ptr;
-
 
24
   int smiley_index;
25
   int smiley_index;
25
   int file_length;
26
   int file_length;
26
   FILE *fp;
27
   FILE *fp;
27
 
28
 
28
   // open the INI file
29
   // open the INI file
Line 70... Line 71...
70
   options.engine.depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"allowed depth", 4);
71
   options.engine.depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"allowed depth", 4);
71
   options.engine.max_depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"maximum depth", 100);
72
   options.engine.max_depth = INIFile_ReadEntryAsLong (inifile, L"engine", L"maximum depth", 100);
72
   options.engine.blunder_chances = INIFile_ReadEntryAsLong (inifile, L"engine", L"blunder chances", 0);
73
   options.engine.blunder_chances = INIFile_ReadEntryAsLong (inifile, L"engine", L"blunder chances", 0);
73
   options.engine.obstinacy_level = INIFile_ReadEntryAsLong (inifile, L"engine", L"obstinacy", 0);
74
   options.engine.obstinacy_level = INIFile_ReadEntryAsLong (inifile, L"engine", L"obstinacy", 0);
74
   options.engine.is_expert_mode = (INIFile_ReadEntryAsBool (inifile, L"engine", L"expert mode", false) > 0);
75
   options.engine.is_expert_mode = (INIFile_ReadEntryAsBool (inifile, L"engine", L"expert mode", false) > 0);
75
 
-
 
76
   // given the selected engine program, load and interpret the right engine config file
-
 
77
   swprintf_s (filename, WCHAR_SIZEOF (filename), L"%s/engines/%s/engine.ini", app_path, options.engine.program);
-
 
78
   engine_inifile = INIFile_LoadINIFile (filename);
-
 
79
   if (engine_inifile != NULL)
-
 
80
   {
-
 
81
      READ_WIDESTRING (options.engine.name, engine_inifile, L"program", L"name", L"Crafty v24.0");
-
 
82
      READ_WIDESTRING (options.engine.cmdline, engine_inifile, L"program", L"executable", L"crafty.exe");
-
 
83
 
-
 
84
      READ_WIDESTRING (options.engine.replystring_move, engine_inifile, L"reply strings", L"move", L"): ");
-
 
85
      READ_WIDESTRING (options.engine.replystring_hint, engine_inifile, L"reply strings", L"hint", L"Hint: ");
-
 
86
 
-
 
87
      READ_WIDESTRING (options.engine.command_new, engine_inifile, L"commands", L"new game", L"new");
-
 
88
      for (ptr = options.engine.command_new; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
89
      READ_WIDESTRING (options.engine.command_setboard, engine_inifile, L"commands", L"setup table from FEN", L"setboard %s");
-
 
90
      for (ptr = options.engine.command_setboard; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
91
      READ_WIDESTRING (options.engine.command_sd, engine_inifile, L"commands", L"search depth set", L"sd %d");
-
 
92
      for (ptr = options.engine.command_sd; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
93
      READ_WIDESTRING (options.engine.command_go, engine_inifile, L"commands", L"play", L"go");
-
 
94
      for (ptr = options.engine.command_go; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
95
      READ_WIDESTRING (options.engine.command_hint, engine_inifile, L"commands", L"hint", L"hint");
-
 
96
      for (ptr = options.engine.command_hint; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
97
      READ_WIDESTRING (options.engine.command_force, engine_inifile, L"commands", L"force move", L"force %s");
-
 
98
      for (ptr = options.engine.command_force; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
99
      READ_WIDESTRING (options.engine.command_quit, engine_inifile, L"commands", L"quit", L"quit");
-
 
100
      for (ptr = options.engine.command_quit; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
101
 
-
 
102
      INIFile_FreeINIFile (engine_inifile); // close the engine config file
-
 
103
   }
-
 
104
 
76
 
105
   // [network]
77
   // [network]
106
   READ_WIDESTRING (options.network.server_address, inifile, L"network", L"server address", L"freechess.org");
78
   READ_WIDESTRING (options.network.server_address, inifile, L"network", L"server address", L"freechess.org");
107
   options.network.server_port = INIFile_ReadEntryAsLong (inifile, L"network", L"server port", 5000);
79
   options.network.server_port = INIFile_ReadEntryAsLong (inifile, L"network", L"server port", 5000);
108
   READ_WIDESTRING (options.network.login, inifile, L"network", L"login", L"guest");
80
   READ_WIDESTRING (options.network.login, inifile, L"network", L"login", L"guest");
Line 122... Line 94...
122
   {
94
   {
123
      // for each smiley we can read, reallocate smilies array to hold one smiley more
95
      // for each smiley we can read, reallocate smilies array to hold one smiley more
124
      smilies = (smiley_t *) SAFE_realloc (smilies, smiley_count, smiley_count + 1, sizeof (smiley_t), false);
96
      smilies = (smiley_t *) SAFE_realloc (smilies, smiley_count, smiley_count + 1, sizeof (smiley_t), false);
125
 
97
 
126
      smiley = &smilies[smiley_count]; // quick access to smiley
98
      smiley = &smilies[smiley_count]; // quick access to smiley
127
 
99
 
128
      // read the smiley name and convert quotes to spaces
100
      // read the smiley name and convert quotes to spaces
129
      wcscpy_s (smiley->name, WCHAR_SIZEOF (smiley->name), smiley_name);
101
      wcscpy_s (smiley->name, WCHAR_SIZEOF (smiley->name), smiley_name);
130
      smiley->name[0] = L' '; // convert leading quote to a space
102
      smiley->name[0] = L' '; // convert leading quote to a space
131
      smiley->name[wcslen (smiley->name) - 1] = L' '; // convert ending quote to a space
103
      smiley->name[wcslen (smiley->name) - 1] = L' '; // convert ending quote to a space
132
 
104
 
Line 179... Line 151...
179
   }
151
   }
180
 
152
 
181
   // close the INI file
153
   // close the INI file
182
   INIFile_FreeINIFile (inifile);
154
   INIFile_FreeINIFile (inifile);
183
   return; // finished loading config
155
   return; // finished loading config
-
 
156
}
-
 
157
 
-
 
158
 
-
 
159
void Config_LoadEngine (const wchar_t *engine_name)
-
 
160
{
-
 
161
   // this function loads the engine-specific parameters. The best place to call it is at the beginning
-
 
162
   // of a game versus the computer, just before the engine executable process is started.
-
 
163
 
-
 
164
   void *engine_inifile;
-
 
165
   wchar_t *ptr;
-
 
166
 
-
 
167
   // reset values first
-
 
168
   memset (&options.engine.program_options, 0, sizeof (options.engine.program_options));
-
 
169
 
-
 
170
   // given the selected engine program, load and interpret the right engine config file
-
 
171
   swprintf_s (filename, WCHAR_SIZEOF (filename), L"%s/engines/%s/engine.ini", app_path, engine_name);
-
 
172
   engine_inifile = INIFile_LoadINIFile (filename);
-
 
173
   if (engine_inifile == NULL)
-
 
174
      return; // engine file not found
-
 
175
 
-
 
176
   // basic program information
-
 
177
   READ_WIDESTRING (options.engine.program_options.name, engine_inifile, L"program", L"name", L"Crafty v24.0");
-
 
178
   READ_WIDESTRING (options.engine.program_options.cmdline, engine_inifile, L"program", L"executable", L"crafty.exe");
-
 
179
 
-
 
180
   // reply string patterns
-
 
181
   READ_WIDESTRING (options.engine.program_options.replystring_move, engine_inifile, L"reply strings", L"move", L"): ");
-
 
182
   READ_WIDESTRING (options.engine.program_options.replystring_hint, engine_inifile, L"reply strings", L"hint", L"Hint: ");
-
 
183
 
-
 
184
   // engine commands
-
 
185
   READ_WIDESTRING (options.engine.program_options.command_new, engine_inifile, L"commands", L"new game", L"new");
-
 
186
   for (ptr = options.engine.program_options.command_new; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
187
   READ_WIDESTRING (options.engine.program_options.command_setboard, engine_inifile, L"commands", L"setup table from FEN", L"setboard %s");
-
 
188
   for (ptr = options.engine.program_options.command_setboard; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
189
   READ_WIDESTRING (options.engine.program_options.command_sd, engine_inifile, L"commands", L"search depth set", L"sd %d");
-
 
190
   for (ptr = options.engine.program_options.command_sd; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
191
   READ_WIDESTRING (options.engine.program_options.command_go, engine_inifile, L"commands", L"play", L"go");
-
 
192
   for (ptr = options.engine.program_options.command_go; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
193
   READ_WIDESTRING (options.engine.program_options.command_hint, engine_inifile, L"commands", L"hint", L"hint");
-
 
194
   for (ptr = options.engine.program_options.command_hint; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
195
   READ_WIDESTRING (options.engine.program_options.command_force, engine_inifile, L"commands", L"force move", L"force %s");
-
 
196
   for (ptr = options.engine.program_options.command_force; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
197
   READ_WIDESTRING (options.engine.program_options.command_quit, engine_inifile, L"commands", L"quit", L"quit");
-
 
198
   for (ptr = options.engine.program_options.command_quit; *ptr != 0; ptr++) if (*ptr == L';') *ptr = L'\n';
-
 
199
 
-
 
200
   INIFile_FreeINIFile (engine_inifile); // close the engine config file
-
 
201
   return; // engine parameters loaded successfully
184
}
202
}
185
 
203
 
186
 
204
 
187
void Config_Save (void)
205
void Config_Save (void)
188
{
206
{
189
   // this function saves the software configuration into an INI file.
207
   // this function saves the software configuration into an INI file.
190
   // WARNING: it does also free the smilies list !
208
   // WARNING: it does also free the smilies list !
191
 
209
 
192
   wchar_t filename[MAX_PATH];
-
 
193
   wchar_t smiley_name[32];
210
   wchar_t smiley_name[32];
194
   smiley_t *smiley;
211
   smiley_t *smiley;
195
   void *inifile;
212
   void *inifile;
196
   int smiley_index;
213
   int smiley_index;
197
   int smiley_index2;
214
   int smiley_index2;