/************************* UCI2WB by H.G.Muller ****************************/\r
\r
-#define VERSION "1.7"\r
+#define VERSION "1.8"\r
\r
#include <stdio.h>\r
#include <stdlib.h>\r
\r
char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, pondering, ponder, post, hasHash, c, sc='c', *suffix, *variants;\r
int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime, debug;\r
-int statDepth, statScore, statNodes, statTime, currNr, size; char currMove[20]; // for analyze mode\r
+int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500]; char currMove[20], moveMap[500][10]; // for analyze mode\r
\r
FILE *toE, *fromE;\r
int pid;\r
int d=0, s=0, t=0, n=0;\r
char *pv;\r
if(sscanf(line+5, "string times @ %c", &dummy) == 1) { printf("# %s", line+12); continue; }\r
+ if(collect && (pv = strstr(line+5, "currmove "))) {\r
+ if(p = strstr(line+5, "currmovenumber ")) {\r
+ n = atoi(p+15);\r
+ if(collect == 1 && n != 1) continue; // wait for move 1\r
+ if(collect + (n == 1) > 2) { // done collecting\r
+ if(inex && collect == 2) printf("%d 0 0 0 OK to exclude\n", lastDepth);\r
+ collect = 3; continue;\r
+ }\r
+ collect = 2; on[nr=n] = 1; sscanf(pv+9, "%s", moveMap[n]); continue; // store move\r
+ }\r
+ }\r
if(!post) continue;\r
if(sscanf(line+5, "string %c", &dummy) == 1) printf("%d 0 0 0 %s", lastDepth, line+12); else {\r
if(p = strstr(line+4, " depth ")) sscanf(p+7, "%d", &d), statDepth = d;\r
if(sscanf(line, "id name %[^\n]", name) == 1) printf("feature myname=\"%s (U%cI2WB)\"\n", name, sc-32);\r
}\r
else if(!strcmp(command, "readyok")) { pause = 0; Sync(WAKEUP); } // resume processing of GUI commands\r
- else if(sscanf(command, "u%ciok", &c)==1 && c==sc) printf("feature smp=1 memory=%d done=1\n", hasHash); // done with options\r
+ else if(sscanf(command, "u%ciok", &c)==1 && c==sc) printf("feature smp=1 memory=%d done=1\n", hasHash), Sync(WAKEUP); // done with options\r
}\r
}\r
\r
void\r
GUI2Engine()\r
{\r
- char line[256], command[256], *p, *q;\r
+ char line[256], command[256], *p, *q, *r;\r
\r
while(1) {\r
int i, x;\r
LoadPos(moveNr); // load position\r
// and set engine thinking (note USI swaps colors!)\r
startTime = GetTickCount();\r
- if(computer == ANALYZE) fprintf(toE, "\ngo infinite\n"), printf("\ngo infinite\n");\r
- else StartSearch("");\r
+ if(computer == ANALYZE) {\r
+ fprintf(toE, "\ngo infinite"); DPRINT("\n# go infinite");\r
+ if(sm & 1) { // some moves are disabled\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
+ } else StartSearch("");\r
}\r
nomove:\r
fflush(toE); fflush(stdout);\r
else if(!strcmp(command, "usermove")) {\r
sscanf(line, "usermove %s", command); // strips off linefeed\r
Move4Engine(command);\r
- stm = WHITE+BLACK - stm;\r
+ stm = WHITE+BLACK - stm; collect = (computer == ANALYZE); sm = 0;\r
// when pondering we either continue the ponder search as normal search, or abort it\r
if(pondering || computer == ANALYZE) {\r
if(pondering && !strcmp(command, move[moveNr])) { // ponder hit\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 done=0\n", variants);\r
+ printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 reuse=0 exclude=1 done=0\n", variants);\r
printf("feature option=\"UCI2WB debug output -check %d\"\n", debug);\r
- fprintf(toE, "u%ci\n", sc); // this prompts UCI engine for options\r
+ fprintf(toE, "u%ci\n", sc); fflush(toE); // this prompts UCI engine for options\r
+ Sync(PAUSE); // wait for uciok\r
}\r
else if(!strcmp(command, "setboard")) {\r
if(strstr(line+9, " b ")) stm = BLACK;\r
- if(sc == 's' && (p = strchr(line+9, '['))) { char c;\r
- *p++ = ' '; q = strchr(p, ']'); c = 'w' + 'b' - q[2]; strcpy(q+2, " 1\n"); while(*--q != ' ') q[2] = *q; *p = c; p[1] = ' '; \r
- }\r
- sprintf(iniPos, "%s%sfen %s", iniPos[0]=='p' ? "position " : "", sc=='s' ? "s" : "", line+9);\r
- iniPos[strlen(iniPos)-1] = 0;\r
+ if(p = strchr(line+9, '[')) { 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
+ *r = 0; sprintf(command, "%s%s %s %s", line+9, q+1, p, r+1);\r
+ } else strcpy(command, line+9);\r
+ sprintf(iniPos, "%s%sfen %s", iniPos[0]=='p' ? "position " : "", sc=='s' ? "s" : "", command);\r
+ iniPos[strlen(iniPos)-1] = sm = 0; collect = (computer == ANALYZE);\r
}\r
else if(!strcmp(command, "variant")) {\r
if(!strcmp(line+8, "shogi\n")) size = 9, strcpy(iniPos, "position startpos");\r
}\r
else if(!strcmp(command, "undo") && (i=1) || !strcmp(command, "remove") && (i=2)) {\r
if(pondering || computer == ANALYZE) StopPonder(1);\r
- moveNr = moveNr > i ? moveNr - i : 0;\r
+ moveNr = moveNr > i ? moveNr - i : 0; collect = (computer == ANALYZE); sm = 0;\r
}\r
else if(!strcmp(command, ".")) {\r
printf("stat01: %d %d %d %d 100 %s\n", statTime, statNodes, statDepth, 100-currNr, currMove);\r
goto nomove;\r
}\r
+ else if(!strcmp(command+2, "clude") && collect > 2) { // include or exclude\r
+ int all = !strcmp(line+8, "all"), in = command[1] == 'n';\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
+ }\r
else if(!strcmp(command, "xboard")) ;\r
- else if(!strcmp(command, "analyze"))computer = ANALYZE;\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, "force")) computer = NONE, StopPonder(pondering);\r
else if(!strcmp(command, "go")) computer = stm;\r