2 * UCI support thru Polyglot
4 * Author: Alessandro Scotti (Jan 2006)
6 * ------------------------------------------------------------------------
8 * GNU XBoard is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or (at
11 * your option) any later version.
13 * GNU XBoard is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see http://www.gnu.org/licenses/.
21 * ------------------------------------------------------------------------
28 // [HGM] this was probably a Windows-specific constant. Needs to be defined here now I
29 // threw out the Windows-specific includes (winboard.h etc.). 100 seems enough.
31 #define SLASH_CHAR "\\"
34 #define SLASH_CHAR "/"
40 #define INIFILE_PREFIX "polyglot_"
41 #define INIFILE_SUFFIX_1ST "1st"
42 #define INIFILE_SUFFIX_2ND "2nd"
43 #define INIFILE_EXT ".ini"
46 static const char * GetIniFilename( ChessProgramState * cps )
48 return cps == &first ? INIFILE_PREFIX INIFILE_SUFFIX_1ST INIFILE_EXT : INIFILE_PREFIX INIFILE_SUFFIX_2ND INIFILE_EXT;
51 void InitEngineUCI( const char * iniDir, ChessProgramState * cps )
54 const char * iniFileName = GetIniFilename( cps );
55 char polyglotIniFile[ MAX_PATH ];
58 /* Build name of initialization file */
59 if( strchr( iniDir, ' ' ) != NULL ) {
60 char iniDirShort[ MAX_PATH ];
62 GetShortPathName( iniDir, iniDirShort, sizeof(iniDirShort) );
64 strcpy( polyglotIniFile, iniDirShort );
66 // [HGM] UCI: not sure if this works, but GetShortPathName seems Windows pecific
67 // and names with spaces in it do not work in xboard in many places, so ignore
68 strcpy( polyglotIniFile, iniDir );
72 strcpy( polyglotIniFile, iniDir );
75 strcat( polyglotIniFile, SLASH_CHAR );
76 strcat( polyglotIniFile, iniFileName );
78 /* Create initialization file */
79 f = fopen( polyglotIniFile, "w" );
82 fprintf( f, "[Polyglot]\n" );
84 if( cps->dir != 0 && strlen(cps->dir) > 0 ) {
85 fprintf( f, "EngineDir = %s\n", cps->dir );
88 if( cps->program != 0 && strlen(cps->program) > 0 ) {
89 fprintf( f, "EngineCommand = %s\n", cps->program );
92 fprintf( f, "Book = %s\n", appData.usePolyglotBook ? "true" : "false" );
93 fprintf( f, "BookFile = %s\n", appData.polyglotBook );
95 fprintf( f, "[Engine]\n" );
96 fprintf( f, "Hash = %d\n", appData.defaultHashSize );
98 fprintf( f, "NalimovPath = %s\n", appData.defaultPathEGTB );
99 fprintf( f, "NalimovCache = %d\n", appData.defaultCacheSizeEGTB );
101 fprintf( f, "OwnBook = %s\n", cps->hasOwnBookUCI ? "true" : "false" );
105 /* Replace program with properly configured Polyglot */
106 cps->dir = appData.polyglotDir;
107 cps->program = (char *) malloc( strlen(polyglotIniFile) + 32 );
108 strcpy( cps->program, "polyglot " );
109 strcat( cps->program, polyglotIniFile );