2 * UCI support thru Polyglot
4 * Author: Alessandro Scotti (Jan 2006)
6 * Copyright 2006 Alessandro Scotti
8 * ------------------------------------------------------------------------
10 * GNU XBoard is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or (at
13 * your option) any later version.
15 * GNU XBoard is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see http://www.gnu.org/licenses/.
23 * ------------------------------------------------------------------------
33 // [HGM] this was probably a Windows-specific constant. Needs to be defined here now I
34 // threw out the Windows-specific includes (winboard.h etc.). 100 seems enough.
36 #define SLASH_CHAR "\\"
39 #define SLASH_CHAR "/"
45 #define INIFILE_PREFIX "polyglot_"
46 #define INIFILE_SUFFIX_1ST "1st"
47 #define INIFILE_SUFFIX_2ND "2nd"
48 #define INIFILE_EXT ".ini"
51 static const char * GetIniFilename( ChessProgramState * cps )
53 return cps == &first ? INIFILE_PREFIX INIFILE_SUFFIX_1ST INIFILE_EXT : INIFILE_PREFIX INIFILE_SUFFIX_2ND INIFILE_EXT;
56 void InitEngineUCI( const char * iniDir, ChessProgramState * cps )
59 const char * iniFileName = GetIniFilename( cps );
60 char polyglotIniFile[ MAX_PATH ];
63 /* Build name of initialization file */
64 if( strchr( iniDir, ' ' ) != NULL ) {
65 char iniDirShort[ MAX_PATH ];
67 GetShortPathName( iniDir, iniDirShort, sizeof(iniDirShort) );
69 strcpy( polyglotIniFile, iniDirShort );
71 // [HGM] UCI: not sure if this works, but GetShortPathName seems Windows pecific
72 // and names with spaces in it do not work in xboard in many places, so ignore
73 strcpy( polyglotIniFile, iniDir );
77 strcpy( polyglotIniFile, iniDir );
80 strcat( polyglotIniFile, SLASH_CHAR );
81 strcat( polyglotIniFile, iniFileName );
83 /* Create initialization file */
84 f = fopen( polyglotIniFile, "w" );
87 fprintf( f, "[Polyglot]\n" );
89 if( cps->dir != 0 && strlen(cps->dir) > 0 ) {
90 fprintf( f, "EngineDir = %s\n", cps->dir );
93 if( cps->program != 0 && strlen(cps->program) > 0 ) {
94 fprintf( f, "EngineCommand = %s\n", cps->program );
97 fprintf( f, "Book = %s\n", appData.usePolyglotBook ? "true" : "false" );
98 fprintf( f, "BookFile = %s\n", appData.polyglotBook );
100 fprintf( f, "[Engine]\n" );
101 fprintf( f, "Hash = %d\n", appData.defaultHashSize );
103 fprintf( f, "NalimovPath = %s\n", appData.defaultPathEGTB );
104 fprintf( f, "NalimovCache = %d\n", appData.defaultCacheSizeEGTB );
106 fprintf( f, "OwnBook = %s\n", cps->hasOwnBookUCI ? "true" : "false" );
110 /* Replace program with properly configured Polyglot */
111 cps->dir = appData.polyglotDir;
112 cps->program = (char *) malloc( strlen(polyglotIniFile) + 32 );
113 strcpy( cps->program, "polyglot " );
114 strcat( cps->program, polyglotIniFile );