/* of which you should have received a copy together with this file. */\r
/****************************************************************************/\r
\r
-#define VERSION "2.2"\r
+#define VERSION "2.3"\r
\r
#include <stdio.h>\r
#include <stdlib.h>\r
#include <string.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 VARIANTS "normal,xiangqi"\r
+#define STDVARS "chess,chess960,crazyhouse,threecheck,giveaway,atomic,seirawan,shogi,xiangqi"\r
\r
#define DPRINT if(debug) printf\r
\r
\r
char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, pondering, suspended, ponder, post, hasHash, c, sc='c', suffix[81], *variants, varOpt;\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;\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];\r
char 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 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
+\r
WinPipe(HANDLE *hRd, HANDLE *hWr)\r
{\r
SECURITY_ATTRIBUTES saAttr;\r
}\r
else if(!strcmp(command, "info")) {\r
int d=0, s=0, t=(GetTickCount() - startTime)/10, n=1;\r
- char *pv;\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
+ continue;\r
+ }\r
if(collect && (pv = strstr(line+5, "currmove "))) {\r
if(p = strstr(line+5, "currmovenumber ")) {\r
n = atoi(p+15);\r
if(!(p = strstr(line+6, " name "))) p = line+1; sscanf(p+6, "%[^\n]", name); // 'name' is omitted in UCCI\r
if(!strcasecmp(name, "UCI_Chess960")) { frc=2; continue; }\r
if(!strcasecmp(name, "UCI_Variant")) { if(p = strstr(line+6, " var ")) strcpy(varList, p); varOpt = 1; continue; }\r
+ if(!strcasecmp(name, "UCI_Opponent")) { namOpt = 1; continue; }\r
if(frc< 0 && (strstr(name, "960") || strcasestr(name, "frc")) && !strcmp(type, "check")) {\r
fprintf(toE, "setoption name %s value true\n", name); strcpy(val, "true"); // set non-standard suspected FRC options\r
}\r
void\r
GUI2Engine()\r
{\r
- char line[256], command[256], *p, *q, *r, mySide;\r
+ char line[256], command[256], *p, *q, *r, mySide, searching = 0;\r
\r
while(1) {\r
int i, x;\r
\r
- if((computer == stm || computer == ANALYZE) && !suspended) {\r
+ if((computer == stm || computer == ANALYZE && !searching) && !suspended) {\r
DPRINT("# start search\n");\r
LoadPos(moveNr); fflush(stdout); // load position\r
// and set engine thinking (note USI swaps colors!)\r
fprintf(toE, " searchmoves"); DPRINT(" searchmoves");\r
for(i=1; i<nr; i++) if(on[i]) { fprintf(toE, " %s", moveMap[i]); DPRINT(" %s", moveMap[i]); }\r
}\r
- fprintf(toE, "\n"); DPRINT("\n");\r
- // code for searchmoves goes here\r
+ fprintf(toE, "\n"); DPRINT("\n"); searching = 1; // suppresses spurious commands during analysis starting new searches\r
} else { pause = 2; StartSearch(""); fflush(stdout); fflush(toE); Sync(PAUSE); } // block input during thinking\r
}\r
nomove:\r
Sync(PAUSE); // block input during thinking\r
goto nomove;\r
}\r
- StopPonder(1);\r
+ StopPonder(1); searching = 0;\r
}\r
strcpy(move[moveNr++], command); // possibly overwrites ponder move\r
}\r
}\r
else if(!strcmp(command, "option")) {\r
char name[80], *p;\r
+ if(searching) StopPonder(1), searching = 0; // force new search if settings change during analysis (multi-PV!)\r
if(sscanf(line+7, "UCI2WB debug output=%d", &debug) == 1) ; else\r
if(sscanf(line+7, "Floating Byoyomi=%d", &flob) == 1) ; else\r
if(sscanf(line+7, "Byoyomi=%d", &byo) == 1) ; else\r
}\r
else if(!strcmp(command, "protover")) {\r
if(!variants) variants = sc=='s' ? "shogi,5x5+5_shogi" : VARIANTS;\r
- printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 reuse=0 exclude=1 pause=1 sigint=0 sigterm=0 done=0\n", variants);\r
+ printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 name=1 reuse=0 exclude=1 pause=1 sigint=0 sigterm=0 done=0\n", variants);\r
printf("feature option=\"UCI2WB debug output -check %d\"\n", debug);\r
if(sc == 's') printf("feature option=\"Floating Byoyomi -check %d\"\nfeature option=\"Byoyomi -spin %d -1 1000\"\n", flob, byo);\r
fprintf(toE, sc == 'x' ? "ucci\n" : "u%ci\n", sc); fflush(toE); // prompt UCI engine for options\r
}\r
else if(!strcmp(command, "setboard")) {\r
stm = (strstr(line+9, " b ") ? BLACK : WHITE);\r
- if(p = strchr(line+9, '[')) { char c;\r
+ if((p = strchr(line+9, '[')) && !varOpt) { char c;\r
*p++ = 0; q = strchr(p, ']'); *q = 0; r = q + 4; \r
if(sc == 's') q[2] = 'w' + 'b' - q[2], strcpy(r=q+3, " 1\n"); // Shogi: reverse color\r
else r = strchr(strchr(q+4, ' ') + 1, ' '); // skip to second space (after e.p. square)\r
iniPos[strlen(iniPos)-1] = sm = 0; collect = (computer == ANALYZE);\r
}\r
else if(!strcmp(command, "variant")) {\r
- if(varOpt) fprintf(toE, "setoption name UCI_Variant value %sucinewgame\n", strcmp(line+8, "3check\n") ? line+8 : "threecheck\n");\r
+ if(varOpt) {\r
+ fprintf(toE, "setoption name UCI_Variant value %sucinewgame\nisready\n", strcmp(line+8, "3check\n") ? line+8 : "threecheck\n");\r
+ fflush(toE); Sync(PAUSE);\r
+ }\r
if(!strcmp(line+8, "shogi\n")) size = 9, strcpy(iniPos, "position startpos");\r
if(!strcmp(line+8, "5x5+5_shogi\n")) size = 5, strcpy(iniPos, "position startpos");\r
if(!strcmp(line+8, "xiangqi\n")) strcpy(iniPos, "fen rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR r");\r
if(!strcmp(line+8, "fischerandom\n")) { frc |= 1; if(frc > 0) fprintf(toE, "setoption name UCI_Chess960 value true\n"); }\r
}\r
else if(!strcmp(command, "undo") && (i=1) || !strcmp(command, "remove") && (i=2)) {\r
- if(pondering || computer == ANALYZE) StopPonder(1);\r
+ if(pondering || computer == ANALYZE) StopPonder(1), searching = 0;\r
moveNr = moveNr > i ? moveNr - i : 0; collect = (computer == ANALYZE); sm = 0;\r
}\r
else if(!strcmp(command, ".")) {\r
inex = 1; line[strlen(line)-1] = sm = 0; // strip LF and clear sm flag\r
for(i=1; i<nr; i++) { if(!strcmp(line+8, moveMap[i]) || all) on[i] = in; sm |= on[i]+1; } // sm: 2 = enabled, 1 = disabled\r
if(!(sm & 2)) goto nomove; // no moves enabled; continue current search\r
- if(computer == ANALYZE) StopPonder(1); // abort old analysis\r
+ if(computer == ANALYZE) StopPonder(1), searching = 0; // abort old analysis\r
}\r
else if(!strcmp(command, "pause")) {\r
if(computer == stm) myTime -= GetTickCount() - startTime;\r
}\r
else if(!strcmp(command, "xboard")) ;\r
else if(!strcmp(command, "analyze"))computer = ANALYZE, collect = 1, sm = 0;\r
- else if(!strcmp(command, "exit")) computer = NONE, StopPonder(1);\r
+ else if(!strcmp(command, "exit")) computer = NONE, StopPonder(1), searching = 0;\r
else if(!strcmp(command, "force")) computer = NONE, StopPonder(pondering);\r
else if(!strcmp(command, "go")) computer = stm;\r
else if(!strcmp(command, "time")) sscanf(line+4, "%d", &myTime), myTime = (10*myTime)/unit;\r
else if(!strcmp(command, "cores")&& !!*threadOpt) sscanf(line, "cores %d", &cores), fprintf(toE, "setoption %s%s %s%d\n", nameWord, threadOpt, valueWord, cores);\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) fprintf(toE, "setoption name UCI_Opponent value none none %s %s", comp ? "computer" : "human", line+5); }\r
+ else if(!strcmp(command, "computer")) comp = 1;\r
else if(!strcmp(command, "offer")) drawOffer = 1;\r
else if(!strcmp(command, "result")) { if(sc == 's') fprintf(toE, "gameover %s\n", line[8] == '/' ? "draw" : (line[7] == '0') == mySide ? "win" : "lose"); }\r
else if(!strcmp(command, "quit")) fprintf(toE, "quit\n"), fflush(toE), exit(0);\r