/************************* UCI2WB by H.G.Muller ****************************/\r
\r
-#define VERSION "1.6"\r
+#define VERSION "1.9"\r
\r
#include <stdio.h>\r
#include <stdlib.h>\r
#define NONE 2\r
#define ANALYZE 3\r
\r
-char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, pondering, ponder, post, hasHash, c, sc='c', *suffix;\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
return buf;\r
}\r
\r
+void\r
+Move4GUI(char *m)\r
+{\r
+ if(sc == 's') {\r
+ // convert USI move to WB format\r
+ m[2] = 'a'+'0'+size - 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[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
+ m[4] = '=', m[5] = 0;\r
+ }\r
+ }\r
+}\r
+\r
void *\r
Engine2GUI()\r
{\r
}\r
p[-1] = '\n'; *p = 0; // strip off ponder move\r
}\r
- if(sc == 's') {\r
- // convert USI move to WB format\r
- line[11] = 'a'+'0'+size - line[11];\r
- line[12] = 'a'+'0'+size - line[12];\r
- if(line[10] == '*') { // drop\r
- line[10] = '@';\r
- } else {\r
- line[9] = 'a'+'0'+size - line[9];\r
- line[10] = 'a'+'0'+size - line[10];\r
- if((stm == WHITE ? (line[10]>'0'+size-size/3 || line[12]>'0'+size-size/3)\r
- : (line[10] <= '0'+size/3 || line[12] <= '0'+size/3)) && line[13] != '+')\r
- line[13] = '=', line[14] = 0;\r
- }\r
- }\r
+ Move4GUI(line+9);\r
printf("move %s\n", line+9); // send move to GUI\r
if(lastScore == 100001 && iniPos[0] != 'f') { printf("%s {mate}\n", stm == WHITE ? "1-0" : "0-1"); computer = NONE; }\r
stm = WHITE+BLACK - stm;\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
+Move4Engine(char *m)\r
+{\r
+ if(sc == 's') {\r
+ // convert input move to USI format\r
+ if(m[1] == '@') { // drop\r
+ m[1] = '*';\r
+ } else {\r
+ m[0] = 'a'+'0'+size - m[0];\r
+ m[1] = 'a'+'0'+size - m[1];\r
+ }\r
+ m[2] = 'a'+'0'+size - 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] != '\n') m[4] = '+'; // cater to WB 4.4 bug :-(\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
Sync(PAUSE); // wait for readyok\r
}\r
else if(!strcmp(command, "usermove")) {\r
- if(sc == 's') {\r
- // convert input move to USI format\r
- if(line[10] == '@') { // drop\r
- line[10] = '*';\r
- } else {\r
- line[9] = 'a'+'0'+size - line[9];\r
- line[10] = 'a'+'0'+size - line[10];\r
- }\r
- line[11] = 'a'+'0'+size - line[11];\r
- line[12] = 'a'+'0'+size - line[12];\r
- if(line[13] == '=') line[13] = 0; // no '=' in USI format!\r
- else if(line[13] != '\n') line[13] = '+'; // cater to WB 4.4 bug :-(\r
- }\r
sscanf(line, "usermove %s", command); // strips off linefeed\r
- stm = WHITE+BLACK - stm;\r
+ Move4Engine(command);\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
StopPonder(1);\r
}\r
- sscanf(line, "usermove %s", move[moveNr++]); // possibly overwrites ponder move\r
+ strcpy(move[moveNr++], command); // possibly overwrites ponder move\r
}\r
else if(!strcmp(command, "level")) {\r
int sec = 0;\r
} else { fprintf(toE, "setoption name %s\n", line+7); DPRINT("# setoption name %s\n", line+7); }\r
}\r
else if(!strcmp(command, "protover")) {\r
- printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 reuse=0 done=0\n", sc=='s' ? "shogi,5x5+5_shogi" : VARIANTS);\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 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
else if(!strcmp(command, "memory")) sscanf(line, "memory %d", &memory);\r
else if(!strcmp(command, "cores")) sscanf(line, "cores %d", &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, inc = 0;\r
+ else if(!strcmp(command, "st")) sscanf(line, "st %d", &sTime), sTime = 1000*sTime - 30, inc = 0;\r
else if(!strcmp(command, "quit")) fprintf(toE, "quit\n"), fflush(toE), exit(0);\r
}\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")) { variants = argv[2]; 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) dir = argv[2];\r