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 * ------------------------------------------------------------------------
30 // [HGM] this was probably a Windows-specific constant. Needs to be defined here now I
31 // threw out the Windows-specific includes (winboard.h etc.). 100 seems enough.
33 #define SLASH_CHAR "\\"
36 #define SLASH_CHAR "/"
42 #define INIFILE_PREFIX "polyglot_"
43 #define INIFILE_SUFFIX_1ST "1st"
44 #define INIFILE_SUFFIX_2ND "2nd"
45 #define INIFILE_EXT ".ini"
48 static const char * GetIniFilename( ChessProgramState * cps )
50 return cps == &first ? INIFILE_PREFIX INIFILE_SUFFIX_1ST INIFILE_EXT : INIFILE_PREFIX INIFILE_SUFFIX_2ND INIFILE_EXT;
53 void InitEngineUCI( const char * iniDir, ChessProgramState * cps )
56 const char * iniFileName = GetIniFilename( cps );
57 char polyglotIniFile[ MAX_PATH ];
60 /* Build name of initialization file */
61 if( strchr( iniDir, ' ' ) != NULL ) {
62 char iniDirShort[ MAX_PATH ];
64 GetShortPathName( iniDir, iniDirShort, sizeof(iniDirShort) );
66 strcpy( polyglotIniFile, iniDirShort );
68 // [HGM] UCI: not sure if this works, but GetShortPathName seems Windows pecific
69 // and names with spaces in it do not work in xboard in many places, so ignore
70 strcpy( polyglotIniFile, iniDir );
74 strcpy( polyglotIniFile, iniDir );
77 strcat( polyglotIniFile, SLASH_CHAR );
78 strcat( polyglotIniFile, iniFileName );
80 /* Create initialization file */
81 f = fopen( polyglotIniFile, "w" );
84 fprintf( f, "[Polyglot]\n" );
86 if( cps->dir != 0 && strlen(cps->dir) > 0 ) {
87 fprintf( f, "EngineDir = %s\n", cps->dir );
90 if( cps->program != 0 && strlen(cps->program) > 0 ) {
91 fprintf( f, "EngineCommand = %s\n", cps->program );
94 fprintf( f, "Book = %s\n", appData.usePolyglotBook ? "true" : "false" );
95 fprintf( f, "BookFile = %s\n", appData.polyglotBook );
97 fprintf( f, "[Engine]\n" );
98 fprintf( f, "Hash = %d\n", appData.defaultHashSize );
100 fprintf( f, "NalimovPath = %s\n", appData.defaultPathEGTB );
101 fprintf( f, "NalimovCache = %d\n", appData.defaultCacheSizeEGTB );
103 fprintf( f, "OwnBook = %s\n", cps->hasOwnBookUCI ? "true" : "false" );
107 /* Replace program with properly configured Polyglot */
108 cps->dir = appData.polyglotDir;
109 cps->program = (char *) malloc( strlen(polyglotIniFile) + 32 );
110 strcpy( cps->program, "polyglot " );
111 strcat( cps->program, polyglotIniFile );