Disarm printing of 'uci' to the GUI in debug mode
[uci2wb.git] / UCI2WB.c
index ebcd79c..3db7bbd 100644 (file)
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -32,7 +32,7 @@
 // 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 EGT ",syzygypath,nalimovpath,gaviotapath,"\r
+#define EGT ",gaviotatbpath,syzygypath,nalimovpath,"\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
@@ -46,9 +46,9 @@ char move[2000][10], iniPos[256], hashOpt[20], pause, pondering, suspended, pond
 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;\r
 volatile int logLen, sentLen;\r
 \r
 FILE *toE, *fromE, *fromF;\r
@@ -157,7 +157,7 @@ StartSearch(char *ponder)
        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
@@ -326,9 +326,12 @@ Engine2GUI()
                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
+                 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
@@ -355,9 +358,13 @@ Engine2GUI()
            }\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(strcasestr(EGT, buf)) { buf[strlen(buf)-5] = 0; strcat(egts, buf); continue; } // collect EGT formats\r
+           sprintf(buf, ",%s,", name); if(strcasestr(EGT, buf)) { buf[strlen(buf)-5-2*(buf[3]=='v')] = 0; strcat(egts, buf); continue; } // collect EGT formats\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
@@ -430,7 +437,7 @@ GUI2Engine()
            // 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
@@ -533,7 +540,7 @@ GUI2Engine()
            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
            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
@@ -581,7 +588,10 @@ GUI2Engine()
        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
+           EPRINT((f, "# setoption name %s%sPath value %s\n", type, *type == 'g' ? "Tb" : "", 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