\r
char move[2000][10], iniPos[256], hashOpt[20], suspended, ponder, post, hasHash, c, sc=' ', sc2, suffix[81], varOpt, searching, *binary;\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
+int statDepth, statScore, statNodes, statTime, currNr, hsize=9, size=9, 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], checkOptions[8192] = "Ponder";\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
if(sTime > 0) EPRINT((f, " movetime %d", sTime)) else\r
if(mps) EPRINT((f, " movestogo %d", mps*(nr/(2*mps)+1)-nr/2))\r
if(flob || byo >= 0) sprintf(suffix, " byoyomi %d", t); // for engines running purely on byoyomi\r
- if(inc && !*suffix) EPRINT((f, " %s %d %s %d", wInc, inc, bInc, inc))\r
+ if((inc || !mps && !sTime && sc == 'x') && !*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")); maxDepth = mpvSP = 0;\r
if(sc != 's') return pv;\r
p = pv; q = buf;\r
while(c = *p++) {\r
- if(c >= '0' && c <= '9' || c >= 'a' && c <= 'z') *q++ = 'a'+'0'+size - c; else *q++ = c;\r
+ if(c >= '0' && c <= '9' || c >= 'a' && c <= 'z') *q++ = 'a'+'0' + (c >= 'a' ? size : hsize) - c; else *q++ = c;\r
}\r
*q++ = 0;\r
return buf;\r
{\r
if(sc == 's') {\r
// convert USI move to WB format\r
- m[2] = 'a'+'0'+size - m[2];\r
+ m[2] = 'a'+'0'+hsize - m[2];\r
m[3] = 'a'+'0'+size - m[3];\r
if(m[1] == '*') { // drop\r
m[1] = '@';\r
} else {\r
- m[0] = 'a'+'0'+size - m[0];\r
+ m[0] = 'a'+'0'+hsize - m[0];\r
m[1] = 'a'+'0'+size - m[1];\r
if((stm == WHITE ? (m[1]>'0'+size-size/3 || m[3]>'0'+size-size/3)\r
: (m[1] <= '0'+size/3 || m[3] <= '0'+size/3)) && m[4] != '+')\r
} else move[moveNr][0] = 0;\r
Move4GUI(line+9);\r
printf("move %s\n", line+9); // send move to GUI\r
- if(move[moveNr][0]) printf("Hint: %s\n", move[moveNr]);\r
+ if(p) Move4GUI(p+7), printf("Hint: %s\n", p+7);\r
if(lastScore == 100001 && iniPos[0] != 'f') { printf("%s {mate}\n", stm == BLACK ? "1-0" : "0-1"); computer = NONE; }\r
fflush(stdout); return;\r
}\r
if(!strcasecmp(name, "Threads")) { strcpy(threadOpt, name); continue; }\r
if(!strcasecmp(name, "Ponder") || !strcasecmp(name, "USI_Ponder")) { strcpy(canPonder, name); continue; }\r
if(!strcasecmp(name, "Hash") || !strcasecmp(name, "USI_Hash") || !strcasecmp(name, "hashsize")) {\r
- memory = oldMem = atoi(val); hasHash = 1; \r
+ memory = oldMem = atoi(val); hasHash = max; \r
strcpy(hashOpt, name);\r
continue;\r
}\r
if(!*varList) strcpy(varList, sc=='s' ? ",shogi,5x5+5_shogi" : VARIANTS); // without clue guess liberally\r
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
+ printf("feature smp=1 memory=%d done=1\n", hasHash > 0);\r
if(unit == 2) { unit = 1; EPRINT((f, "# setoption usemillisec true\n")) }\r
fflush(stdout); return; // done with options\r
}\r
if(m[1] == '@') { // drop\r
m[1] = '*';\r
} else {\r
- m[0] = 'a'+'0'+size - m[0];\r
+ m[0] = 'a'+'0'+hsize - m[0];\r
m[1] = 'a'+'0'+size - m[1];\r
}\r
- m[2] = 'a'+'0'+size - m[2];\r
+ m[2] = 'a'+'0'+hsize - m[2];\r
m[3] = 'a'+'0'+size - m[3];\r
if(m[4] == '=') m[4] = 0; // no '=' in USI format!\r
else if(m[4]) m[4] = '+'; // cater to WB 4.4 bug :-(\r
if(!strcmp(command, "usermove")) { difficult--; break; } // for efficiency during game play, moves, time & otim are tried first\r
else if(!strcmp(command, "time")) sscanf(line+4, "%d", &myTime), myTime = (10*myTime)/unit;\r
else if(!strcmp(command, "otim")) sscanf(line+4, "%d", &hisTime), hisTime = (10*hisTime)/unit;\r
- else if(!strcmp(command, "offer")) drawOffer = 1; // backlogged anyway, so this can be done instantly\r
+ else if(!strcmp(command, "draw")) drawOffer = 1; // backlogged anyway, so this can be done instantly\r
else if(!strcmp(command, "post")) post = 1;\r
else if(!strcmp(command, "nopost"))post = 0;\r
else if(!strcmp(command, ".")) {\r
EPRINT((f, "# ponderhit%s\n", draw)) fflush(toE); fflush(stdout);\r
} else {\r
if(searching) StopSearch(1); // ponder miss or analysis, as moves won't arrive during thinking\r
- p = line+7; while(qEnd < queue+10000 && (*qEnd++ = *p++) != '\n') {}\r
+ p = command; *qEnd++ = 'e'; *qEnd++ = ' '; while(qEnd < queue+10000 && (*qEnd++ = *p++)) {}\r
Sync(WAKEUP); // queue move for adding it to game (and toggle stm)\r
}\r
} else\r
}\r
}\r
\r
+void\r
+IsReady ()\r
+{\r
+ EPRINT((f, "# isready\n")) fflush(toE);\r
+ HandleEngineOutput(); // wait for readyok\r
+}\r
\r
void\r
DoCommand ()\r
{\r
- char line[1024], command[256], *p, *q, *r, type[99];\r
+ char line[1024], command[256], *p, *q, *r, type[99], c;\r
int i;\r
\r
p=line; while(qStart < qEnd && (*p++ = *qStart++) != '\n') {} *p = 0;\r
oldMem = memory;\r
// we can set other options here\r
if(varOpt && strstr(varList, ",normal")) EPRINT((f, "# setoption name UCI_Variant value chess\n"))\r
- EPRINT((f, "# isready\n")) fflush(toE);\r
- HandleEngineOutput(); // wait for readyok\r
+ IsReady();\r
if(sc == 'x') { if(newGame) EPRINT((f, "# setoption newgame\n")) } else // optional in UCCI\r
- EPRINT((f, "# u%cinewgame\n", sc)) fflush(toE);\r
+ { EPRINT((f, "# u%cinewgame\n", sc)) fflush(toE); if(sc != 's') IsReady(); } // avoid isready in USI\r
}\r
else if(!strcmp(command, "e")) { strcpy(move[moveNr++], type); stm ^= WHITE|BLACK; return; }\r
else if(!strcmp(command, "option")) {\r
EPRINT((f, "# setoption name UCI_Variant value %sucinewgame\nisready\n", line+8))\r
fflush(toE); HandleEngineOutput(); // wait for readyok\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
+ c = 0; if(sscanf(line+8, "%dx%d+%d_shogi%c", &hsize, &size, &i, &c) && c == '\n') strcpy(iniPos, "position startpos");\r
+ if(!strcmp(line+8, "shogi\n")) hsize = size = 9, strcpy(iniPos, "position startpos");\r
if(!strcmp(line+8, "xiangqi\n")) sprintf(iniPos, "%s %c", XQPOS+9*(sc2 == 'c'), sc2 == 'c' ? 'r' : 'w'); // with -c use Cyclone dialect\r
if(!strcmp(line+8, "fischerandom\n")) { frc |= 1; if(frc > 0) EPRINT((f, "# setoption name UCI_Chess960 value true\n")) }\r
}\r
else if(!strcmp(command, "force")) computer = NONE;\r
else if(!strcmp(command, "go")) computer = stm;\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, "memory")) { sscanf(line, "memory %d", &memory); if(memory > hasHash) memory = hasHash; }\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")){\r
sscanf(line+8, "%s %[^\n]", type, command);\r
if(argc > 2 && !strcmp(argv[1], "-nice")) { sscanf(argv[2], "%d", &priority); argc-=2; argv+=2; }\r
if(argc > 2 && !strcmp(argv[1], "-kill")) { sscanf(argv[2], "%d", &killDelay); argc-=2; argv+=2; }\r
if(argc > 1 && argv[1][0] == '-') { sc = argv[1][1]; argc--; argv++; }\r
- if(argc < 2) { printf("usage is: U%cI2WB [debug] [-s] <engine.exe> [<engine directory>]\n", sc-32); exit(-1); }\r
+ if(argc < 2) { printf("usage is: %s [debug] [-s|-x|-c|-f] <engine.exe> [<engine directory>]\n", argv[0]); exit(-1); }\r
if(argc > 2) dir = argv[2];\r
if(argc > 3) strncpy(suffix, argv[3], 80);\r
\r