/* of which you should have received a copy together with this file. */\r
/****************************************************************************/\r
\r
-#define VERSION "2.3"\r
+#define VERSION "3.0"\r
\r
#include <stdio.h>\r
#include <stdlib.h>\r
\r
// Set VARIANTS for in WinBoard variant feature. (With -s option this will always be reset to use "shogi".)\r
#define VARIANTS ",normal,xiangqi"\r
-#define STDVARS "chess,chess960,crazyhouse,threecheck,giveaway,atomic,seirawan,shogi,xiangqi"\r
+#define STDVARS "chess,chess960,crazyhouse,3check,giveaway,suicide,losers,atomic,seirawan,shogi,xiangqi"\r
+#define EGT ",gaviotaTbPath,syzygyPath,nalimovPath,robbotripleBaseDirectory,robbototalBaseDirectory,bitbases path,"\r
\r
#define DPRINT if(debug) printf\r
#define EPRINT(X) { char f[999]; sprintf X; DPRINT("%s", f); fprintf(toE, "%s", f + 2*(*f == '#')); /* strip optional # prefix */ }\r
int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime, debug, flob;\r
int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500], frc, byo = -1, namOpt, comp;\r
char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20], varList[8000], anaOpt[20], backLog[10000], checkOptions[8192] = "Ponder";\r
-char board[100]; // XQ board for UCCI\r
+char pvs[99][999], board[100]; // XQ board for UCCI\r
char *nameWord = "name ", *valueWord = "value ", *wTime = "w", *bTime = "b", *wInc = "winc", *bInc = "binc", newGame; // keywords that differ in UCCI\r
-int unit = 1, drawOffer;\r
+int unit = 1, drawOffer, scores[99], mpvSP, maxDepth, ponderAlways;\r
volatile int logLen, sentLen;\r
\r
FILE *toE, *fromE, *fromF;\r
int pid;\r
\r
-#ifdef WIN32\r
-char *strcasestr (char *p, char *q) { char *r = p; while(*r) *r = tolower(*r), r++; return strstr(p, q); }\r
+char *strcasestr (char *p, char *q) { while(*p) { char *r=p++, *s=q; while(tolower(*r++) == tolower(*s) && *s) s++; if(!*s) return p-1; } return NULL; }\r
\r
+#ifdef WIN32\r
WinPipe(HANDLE *hRd, HANDLE *hWr)\r
{\r
SECURITY_ATTRIBUTES saAttr;\r
if(inc && !*suffix) EPRINT((f, " %s %d %s %d", wInc, inc, bInc, inc))\r
if(depth > 0) EPRINT((f, " depth %d", depth))\r
if(*suffix) EPRINT((f, suffix, inc))\r
- EPRINT((f, "\n"))\r
+ EPRINT((f, "\n")); maxDepth = mpvSP = 0;\r
}\r
\r
void\r
}\r
\r
void\r
-StartPonder()\r
+StartPonder(int moveNr)\r
{\r
if(!move[moveNr][0]) return; // no ponder move\r
LoadPos(moveNr+1);\r
if(len <= 0) return 0;\r
StopPonder(pondering | searching); pondering = searching = 0; // force new search if settings change during analysis (multi-PV!)\r
fwrite(backLog + sentLen, 1, len, toE); sentLen += len; DPRINT("# release %d\n", len);\r
- if(ponder && computer == 1 - stm) StartPonder(); // (re)start ponder search\r
+ if(ponder && computer == 1 - stm) StartPonder(moveNr); // (re)start ponder search\r
return analyse; // return 1 if analysis search should be restarted\r
}\r
\r
void *\r
Engine2GUI()\r
{\r
- char line[1024], command[256];\r
+ char line[1024], command[256]; static char egts[999];\r
\r
if(fromF = fopen("DefectiveEngineOptions.ini", "r")) printf("# fake engine input\n");\r
while(1) {\r
sscanf(p+7, "%s", move[moveNr]);\r
if(computer != NONE && ponder) {\r
DPRINT("# ponder on %s\n", move[moveNr]);\r
- StartPonder();\r
+ StartPonder(moveNr);\r
}\r
p[-1] = '\n'; *p = 0; // strip off ponder move\r
} else move[moveNr][0] = 0;\r
char *pv, varName[80];\r
if(sscanf(line+5, "string times @ %c", &dummy) == 1) { printf("# %s", line+12); continue; }\r
if(sscanf(line+5, "string variant %s", varName) == 1) {\r
- if(!strstr(STDVARS, varName) && (p = strstr(line+18, " startpos "))) printf("setup (-) 8x8+0_fairy %s", p+10);\r
+ if(!strstr(STDVARS, varName)) {\r
+ int files = 8, ranks = 8, hand = 0; char parent[80];\r
+ if(p = strstr(line+18, " files ")) sscanf(p+7, "%d", &files);\r
+ if(p = strstr(line+18, " ranks ")) sscanf(p+7, "%d", &ranks);\r
+ if(p = strstr(line+18, " pocket ")) sscanf(p+8, "%d", &hand);\r
+ if(p = strstr(line+18, " template ")) sscanf(p+10, "%s", parent); else strcpy(parent, "fairy");\r
+ if(p = strstr(line+18, " startpos "))\r
+ printf("setup (-) %dx%d+%d_%s %s", files, ranks, hand, parent, p+10);\r
+ }\r
continue;\r
}\r
if(collect && (pv = strstr(line+5, "currmove "))) {\r
if(p = strstr(line+4, " time ")) sscanf(p+6, "%d", &t), t /= 10, statTime = t;\r
if(p = strstr(line+4, " currmove ")) sscanf(p+10,"%s", currMove);\r
if(p = strstr(line+4, " currmovenumber ")) sscanf(p+16,"%d", &currNr);\r
- if(pv = strstr(line+4, " pv ")) // convert PV info to WB thinking output\r
+ if(pv = strstr(line+4, " pv ")) { // convert PV info to WB thinking output\r
+ if(d > maxDepth) maxDepth = d, mpvSP = 0; else if(d < maxDepth) continue; // ignore depth regressions\r
+ if(p = strstr(line+4, " upperbound ")) strcat(p, "?\n"); else\r
+ if(p = strstr(line+4, " lowerbound ")) strcat(p, "!\n");\r
+ for(i=0; i<mpvSP; i++) if(s == scores[i] && !strcmp(pvs[i], pv+4)) break; // check if duplicat\r
+ if(i >= mpvSP) strncpy(pvs[mpvSP], pv+4, 998), scores[mpvSP++] = s, // emit as thinking output if not\r
printf("%3d %6d %6d %10d %s", lastDepth=d, lastScore=s, t, n, Convert(pv+4));\r
- else if(s == -100000) lastScore = s; // when checkmated score is valid even without PV (which might not come)\r
+ } else if(s == -100000) lastScore = s; // when checkmated score is valid even without PV (which might not come)\r
}\r
}\r
else if(!strcmp(command, "option")) { // USI option: extract data fields\r
}\r
if(!strcasecmp(name, "newgame") && !strcmp(type, "button")) { newGame++; continue; }\r
if(!strcasecmp(name, "usemillisec")) { unit = (!strcmp(val, "false") ? 2 : 1); continue; }\r
+ sprintf(buf, ",%s,", name); if(p = strcasestr(EGT, buf)) { // collect EGT formats\r
+ strcpy(buf, p); for(p=buf; *++p >='a';){} if(*p == ' ') strcpy(buf, ",scorpio"); *p = 0; strcat(egts, buf); continue; // clip at first non-lower-case\r
+ }\r
// pass on engine-defined option as WB option feature\r
if(!strcmp(type, "filename")) type[4] = 0;\r
+ else if(sc == 'c' && !strcmp(type, "string")) { // in UCI try to guess which strings are file or directory names\r
+ if(strcasestr(name, "file")) strcpy(type, "file"); else\r
+ if(strcasestr(name, "path") || strcasestr(name, "directory") || strcasestr(name, "folder")) strcpy(type, "path");\r
+ }\r
sprintf(buf, "feature option=\"%s -%s", name, type); q = buf + strlen(buf);\r
if( !strcmp(type, "file")\r
|| !strcmp(type, "string")) sprintf(q, " %s\"\n", val);\r
char *p = varList, *q = varList;\r
while(*q && *q != '\n') if(!strncmp(q, " var ", 5)) *p++ = ',', q +=5; // replace var keywords by commas\r
else if(!strncmp(q-1, " chess ", 7)) strcpy(p, "normal"), p += 6, q += 5; // 'chess' is called 'normal' in CECP\r
- else if(!strncmp(q-1, " threecheck", 11)) *p++ = '3', q += 5; // 'threecheck' is written '3check' in CECP\r
else *p++ = *q++; // copy other variant names unmodified\r
if(frc) sprintf(p, ",normal,fischerandom"), printf("feature oocastle=%d\n", frc<0); // unannounced FRC uses O-O castling\r
if(*varList) printf("feature variants=\"%s\"\n", varList+1); // from UCI_Variant combo and/or UCI_Chess960 check options\r
+ if(*egts) printf("feature egt=\"%s\"\n", egts+1);\r
printf("feature smp=1 memory=%d done=1\n", hasHash);\r
if(unit == 2) { unit = 1; EPRINT((f, "# setoption usemillisec true\n")) }\r
Sync(WAKEUP); // done with options\r
// and set engine thinking (note USI swaps colors!)\r
startTime = GetTickCount(); mySide = stm; // remember side we last played for\r
if(computer == ANALYZE) {\r
- EPRINT((f, "# go infinite"))\r
+ EPRINT((f, "# go infinite")); maxDepth = mpvSP = 0;\r
if(sm & 1) { // some moves are disabled\r
EPRINT((f, " searchmoves"))\r
for(i=1; i<nr; i++) if(on[i]) EPRINT((f, " %s", moveMap[i]))\r
}\r
EPRINT((f, "\n")) searching = 1; // suppresses spurious commands during analysis starting new searches\r
} else pause = think = 2, StartSearch(""); // request suspending of input processing while thinking\r
- }\r
+ } else if(ponderAlways && computer == NONE) move[moveNr][0] = 0, StartPonder(moveNr-1);\r
nomove:\r
for(difficult=0; !difficult; ) { // read and handle commands that can (or must) be handled during thinking\r
fflush(toE); fflush(stdout);\r
char *p;\r
if(logLen == sentLen) logLen = 0, sentLen = 0; // engine is up to date; reset buffer\r
if(sscanf(line+7, "UCI2WB debug output=%d", &debug) == 1) ; else\r
+ if(sscanf(line+7, "ponder always=%d", &ponderAlways) == 1) ; else\r
if(sscanf(line+7, "Floating Byoyomi=%d", &flob) == 1) ; else\r
if(sscanf(line+7, "Byoyomi=%d", &byo) == 1) ; else\r
if(p = strchr(line, '=')) {\r
continue;\r
}\r
if(!strcmp(command, "resume")) {\r
- if(suspended == 2) StartPonder(); // restart interrupted ponder search\r
+ if(suspended == 2) StartPonder(moveNr); // restart interrupted ponder search\r
suspended = think = 0; continue; // causes thinking to start in normal way if on move or analyzing\r
}\r
if(think) { // command arrived during thinking; order abort for 'instant commands'\r
if(!varList[0]) strcpy(varList, sc=='s' ? ",shogi,5x5+5_shogi" : VARIANTS);\r
printf("feature setboard=1 usermove=1 debug=1 ping=1 name=1 reuse=0 exclude=1 pause=1 sigint=0 sigterm=0 done=0\n");\r
printf("feature option=\"UCI2WB debug output -check %d\"\n", debug);\r
+ printf("feature option=\"ponder always -check %d\"\n", ponderAlways);\r
if(sc == 's') printf("feature option=\"Floating Byoyomi -check %d\"\nfeature option=\"Byoyomi -spin %d -1 1000\"\n", flob, byo);\r
- EPRINT((f, sc == 'x' ? "# ucci\n" : "u%ci\n", sc)) fflush(toE); // prompt UCI engine for options\r
+ EPRINT((f, sc == 'x' ? "# ucci\n" : "# u%ci\n", sc)) fflush(toE); // prompt UCI engine for options\r
Sync(PAUSE); // wait for uciok\r
}\r
else if(!strcmp(command, "setboard")) {\r
}\r
else if(!strcmp(command, "variant")) {\r
if(varOpt) {\r
- EPRINT((f, "# setoption name UCI_Variant value %sucinewgame\nisready\n", strcmp(line+8, "3check\n") ? line+8 : "threecheck\n"))\r
+ EPRINT((f, "# setoption name UCI_Variant value %sucinewgame\nisready\n", line+8))\r
fflush(toE); Sync(PAUSE);\r
}\r
if(!strcmp(line+8, "shogi\n")) size = 9, strcpy(iniPos, "position startpos");\r
else if(!strcmp(command, "ping")) { /* static int done; if(!done) pause = 1, fprintf(toE, "isready\n"), fflush(toE), printf("# send isready\n"), fflush(stdout), Sync(PAUSE); done = 1;*/ printf("po%s", line+2); }\r
else if(!strcmp(command, "memory")) sscanf(line, "memory %d", &memory);\r
else if(!strcmp(command, "cores")&& !!*threadOpt) { sscanf(line, "cores %d", &cores); EPRINT((f, "# setoption %s%s %s%d\n", nameWord, threadOpt, valueWord, cores)) }\r
- else if(!strcmp(command, "egtpath")){ sscanf(line, "egtpath %s %[^\n]", type, command); EPRINT((f, "# setoption name %sPath value %s\n", type,command)); }\r
+ else if(!strcmp(command, "egtpath")){\r
+ sscanf(line+8, "%s %[^\n]", type, command);\r
+ if(p = strstr(EGT, type)) strcpy(type, p), p = strchr(type, ','), *p = 0; else strcpy(type, "bitbases path");\r
+ EPRINT((f, "# setoption name %s value %s\n", type, command));\r
+ }\r
else if(!strcmp(command, "sd")) sscanf(line, "sd %d", &depth);\r
else if(!strcmp(command, "st")) sscanf(line, "st %d", &sTime), sTime = 1000*sTime - 30, inc = 0, sTime /= unit;\r
else if(!strcmp(command, "name")) { if(namOpt) EPRINT((f, "# setoption name UCI_Opponent value none none %s %s", comp ? "computer" : "human", line+5)) }\r
{\r
char *dir = NULL, *p, *q; int e;\r
\r
+\r
if(argc == 2 && !strcmp(argv[1], "-v")) { printf("UCI2WB " VERSION " by H.G.Muller\n"); exit(0); }\r
if(argc > 1 && !strcmp(argv[1], "debug")) { debug = 1; argc--; argv++; }\r
if(argc > 1 && !strcmp(argv[1], "-var")) { strcpy(varList+1, argv[2]); *varList = ','; argc-=2; argv+=2; }\r