Disarm printing of 'uci' to the GUI in debug mode
[uci2wb.git] / UCI2WB.c
index 2971c3f..3db7bbd 100644 (file)
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -30,8 +30,9 @@
 #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
+#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
 #define NONE  2\r
 #define ANALYZE 3\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
+char move[2000][10], iniPos[256], hashOpt[20], pause, pondering, suspended, ponder, post, hasHash, c, sc='c', 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
-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 currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20], varList[8000], anaOpt[20], backLog[10000], 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
-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
 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
+char *strcasestr (char *p, char *q) { while(*p) { char *r=p++, *s=q; while(tolower(*r++) == tolower(*s) && *s) s++; if(!*s) return p-1; } return NULL; }\r
 \r
 WinPipe(HANDLE *hRd, HANDLE *hWr)\r
 {\r
@@ -155,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
@@ -191,6 +193,23 @@ StartPonder()
        StartSearch(" ponder");\r
 }\r
 \r
+void\r
+Analyze(char *val)\r
+{\r
+    if(*anaOpt) EPRINT((f, "# setoption %s%s %s%s\n", nameWord, anaOpt, valueWord, val));\r
+}\r
+\r
+int\r
+Release()\r
+{   // send setoption commands backlogged during thinking to engine, aborting ponder or analysis search if necessary\r
+    int len = logLen - sentLen, analyse = searching;\r
+    if(len <= 0) return 0;\r
+    StopPonder(pondering | searching); pondering = searching = 0; // force new search if settings change during analysis (multi-PV!)\r
+    fwrite(backLog + sentLen, 1, len, toE); sentLen += len; DPRINT("# release %d\n", len);\r
+    if(ponder && computer == 1 - stm) StartPonder(); // (re)start ponder search\r
+    return analyse; // return 1 if analysis search should be restarted\r
+}\r
+\r
 char *Convert(char *pv)\r
 {   // convert Shogi coordinates to WB\r
     char *p, *q, c;\r
@@ -237,16 +256,16 @@ GetChar()
 void *\r
 Engine2GUI()\r
 {\r
-    char line[1024], command[256];\r
+    char line[1024], command[256]; static char egts[999];\r
 \r
     if(fromF = fopen("DefectiveEngineOptions.ini", "r")) printf("# fake engine input\n");\r
     while(1) {\r
-       int i=0, x; char *p, dummy;\r
+       int i=0, x; char *p, dummy, len;\r
 \r
        fflush(stdout); fflush(toE);\r
        while((line[i] = x = GetChar()) != EOF && line[i] != '\n') i++;\r
        line[++i] = 0;\r
-       if(x == EOF) exit(0);\r
+       if(x == EOF) printf("tellusererror UCI2WB: %s died on me\n", binary), exit(0);\r
        DPRINT("# engine said: %s", line), fflush(stdout);\r
        if(sscanf(line, "%s", command) != 1) continue;\r
        if(!strcmp(command, "bestmove")) {\r
@@ -259,6 +278,7 @@ Engine2GUI()
            if(strstr(line+9, "(none)") || strstr(line+9, "null") ||\r
               strstr(line+9, "0000")) { printf("%s\n", lastScore < -99999 ? "resign" : "1/2-1/2 {stalemate}"); computer = NONE; }\r
            sscanf(line, "bestmove %s", move[moveNr++]);\r
+           Release(); // send setoption commands that arrived during search\r
            myTime -= (GetTickCount() - startTime)*1.02 + inc; // update own clock, so we can give correct wtime, btime with ponder\r
            if(mps && ((moveNr+1)/2) % mps == 0) myTime += tc; if(sTime) myTime = sTime; // new session or move starts\r
            stm = WHITE+BLACK - stm;\r
@@ -306,13 +326,17 @@ 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
            }\r
        }\r
        else if(!strcmp(command, "option")) { // USI option: extract data fields\r
            char name[80], type[80], buf[1024], val[256], *q;\r
-           int min=0, max=1e9;\r
+           int min=0, max=1e9; *val = 0;\r
            if(p = strstr(line+6, " type ")) sscanf(p+1, "type %s", type), *p = '\n';\r
            if(p = strstr(line+6, " min "))  sscanf(p+1, "min %d", &min), *p = '\n';\r
            if(p = strstr(line+6, " max "))  sscanf(p+1, "max %d", &max), *p = '\n';\r
@@ -321,6 +345,7 @@ Engine2GUI()
            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(!strcasecmp(name+2, "I_AnalyseMode")) { strcpy(anaOpt, name); continue; }\r
            if(frc< 0 && (strstr(name, "960") || strcasestr(name, "frc")) && !strcmp(type, "check")) {\r
                EPRINT((f, "# setoption name %s value true\n", name)) strcpy(val, "true"); // set non-standard suspected FRC options\r
            }\r
@@ -333,8 +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-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
@@ -367,6 +397,7 @@ Engine2GUI()
                                else *p++ = *q++; // copy other variant names unmodified\r
            if(frc) sprintf(p, ",normal,fischerandom"), printf("feature oocastle=%d\n", frc<0); // unannounced FRC uses O-O castling\r
            if(*varList) printf("feature variants=\"%s\"\n", varList+1); // from UCI_Variant combo and/or UCI_Chess960 check options\r
+           if(*egts) { for(p=egts; *p = tolower(*p); p++); printf("feature egt=\"%s\"\n", egts+1); }\r
            printf("feature smp=1 memory=%d done=1\n", hasHash);\r
            if(unit == 2) { unit = 1; EPRINT((f, "# setoption usemillisec true\n")) }\r
            Sync(WAKEUP); // done with options\r
@@ -395,10 +426,10 @@ Move4Engine(char *m)
 void\r
 GUI2Engine()\r
 {\r
-    char line[256], command[256], *p, *q, *r, mySide, searching = 0;\r
+    char line[256], command[256], *p, *q, *r, mySide, type[99];\r
 \r
     while(1) {\r
-       int i, x, think=0;\r
+       int i, x, difficult, think=0;\r
 \r
        if((computer == stm || computer == ANALYZE && !searching) && !suspended) {\r
            DPRINT("# start search\n");\r
@@ -406,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
@@ -415,29 +446,50 @@ GUI2Engine()
            } else pause = think = 2, StartSearch(""); // request suspending of input processing while thinking\r
        }\r
       nomove:\r
+       for(difficult=0; !difficult; ) { // read and handle commands that can (or must) be handled during thinking\r
        fflush(toE); fflush(stdout);\r
        i = 0; while((x = getchar()) != EOF && (line[i] = x) != '\n') i++;\r
-       line[++i] = 0; if(x == EOF) { printf("# EOF\n"); EPRINT((f, "# quit\n")) exit(-1); }\r
-       sscanf(line, "%s", command);\r
-       if(!strcmp(command, "offer")) { drawOffer = 1; goto nomove; } // backlogged anyway, so this can be done instantly\r
-       if(think) {      // command arrived during thinking; order abort for 'instant commands'\r
-           if(!strcmp(command, "quit") || !strcmp(command, "force") || !strcmp(command, "?")) { EPRINT((f, "# stop\n")); fflush(toE); }\r
-           Sync(PAUSE); // block processing of input during thinking\r
+       line[++i] = 0; if(x == EOF) { printf("# EOF\n"); sprintf(line, "quit -1\n"); }\r
+       if(think && !pause) Sync(PAUSE), think = 0, Release(); // if no longer thinking, take dummy pause\r
+       sscanf(line, "%s", command); DPRINT("# '%s' think=%d pause=%d log=%d sent=%d\n", command, think, pause, logLen, sentLen);\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, "post"))  post = 1;\r
+       else if(!strcmp(command, "nopost"))post = 0;\r
+       else if(!strcmp(command, "pause")) {\r
+           if(computer == stm) myTime -= GetTickCount() - startTime;\r
+           suspended = 1 + pondering; // remember if we were pondering, and stop search ignoring bestmove\r
+           StopPonder(pondering || computer == stm);\r
        }\r
-       if(!strcmp(command, "new")) {\r
-           computer = BLACK; moveNr = 0; depth = -1; move[0][0] = 0;\r
-           stm = WHITE; strcpy(iniPos, "position startpos"); frc &= ~1;\r
-           if(memory != oldMem && hasHash) EPRINT((f, "# setoption %s%s %s%d\n", nameWord, hashOpt, valueWord, memory))\r
-           oldMem = memory;\r
-           // we can set other options here\r
-           if(sc == 'x') { if(newGame) EPRINT((f, "# setoption newgame\n")) } else // optional in UCCI\r
-           if(varOpt) EPRINT((f, "# setoption name UCI_Variant value chess\n"))\r
-           pause = 1; // wait for option settings to take effect\r
-           EPRINT((f, "# isready\n")) fflush(toE);\r
-           Sync(PAUSE); // wait for readyok\r
-           EPRINT((f, "# u%cinewgame\n", sc)) fflush(toE);\r
+       else { //convert easy & hard to "option" after treating their effect on the adapter\r
+         if(!strcmp(command, "easy")) {\r
+           if(*canPonder) ponder = 0, sprintf(command, "option"), sprintf(line, "option %s=0\n", canPonder); else continue;\r
+         }\r
+         else if(!strcmp(command, "hard")) {\r
+           if(*canPonder) ponder = 1, sprintf(command, "option"), sprintf(line, "option %s=1\n", canPonder); else continue;\r
+         }\r
+         if(!strcmp(command, "option")) {\r
+           char *p;\r
+           if(logLen == sentLen) logLen = 0, sentLen = 0; // engine is up to date; reset buffer\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
+           if(p = strchr(line, '=')) {\r
+               *p++ = 0;\r
+               if(strstr(checkOptions, line+7)) sprintf(p, "%s\n", atoi(p) ? "true" : "false");\r
+               snprintf(backLog+logLen, 9999-logLen, "setoption %s%s %s%s", nameWord, line+7, valueWord, p);\r
+           } else snprintf(backLog+logLen, 9999-logLen, "setoption %s%s\n", nameWord, line+7);\r
+           DPRINT("# backlog: %s", backLog+logLen); logLen += strlen(backLog+logLen);\r
+           if(!think && Release()) break; // break will restart analysis; pondering is restarted by Release itself\r
+         }\r
+         else difficult = 1; // difficult command; terminate loop for easy ones\r
        }\r
-       else if(!strcmp(command, "usermove")) {\r
+       } // next command\r
+\r
+       // some commands that should never come during thinking can be safely processed here\r
+       if(difficult < 0) { // used as kludge to signal "usermove" was already matched\r
            sscanf(line, "usermove %s", command); // strips off linefeed\r
            Move4Engine(command);\r
            stm = WHITE+BLACK - stm; collect = (computer == ANALYZE); sm = 0;\r
@@ -447,12 +499,35 @@ GUI2Engine()
                    char *draw = drawOffer ? " draw" : ""; drawOffer = 0;\r
                    pondering = 0; pause = 2; moveNr++; startTime = GetTickCount(); // clock starts running now\r
                    EPRINT((f, "# ponderhit%s\n", draw)) fflush(toE); fflush(stdout);\r
-                   Sync(PAUSE); // block input during thinking\r
+                   think = 2; // request blocking input during thinking\r
                    goto nomove;\r
                }\r
                StopPonder(1); searching = 0;\r
            }\r
            strcpy(move[moveNr++], command); // possibly overwrites ponder move\r
+           continue;\r
+       }\r
+       if(!strcmp(command, "resume")) {\r
+           if(suspended == 2) StartPonder(); // restart interrupted ponder search\r
+           suspended = think = 0; continue;  // causes thinking to start in normal way if on move or analyzing\r
+       }\r
+       if(think) { // command arrived during thinking; order abort for 'instant commands'\r
+           if(!strcmp(command, "?") || !strcmp(command, "quit") ||\r
+              !strcmp(command, "force") || !strcmp(command, "result")) { EPRINT((f, "# stop\n")); fflush(toE); }\r
+           Sync(PAUSE); Release(); // block processing of difficult commands during thinking; send backlog left because of race\r
+       }\r
+       if(!strcmp(command, "new")) {\r
+           computer = BLACK; moveNr = 0; depth = -1; move[0][0] = 0;\r
+           stm = WHITE; strcpy(iniPos, "position startpos"); frc &= ~1;\r
+           if(memory != oldMem && hasHash) EPRINT((f, "# setoption %s%s %s%d\n", nameWord, hashOpt, valueWord, memory))\r
+           oldMem = memory;\r
+           // we can set other options here\r
+           if(sc == 'x') { if(newGame) EPRINT((f, "# setoption newgame\n")) } else // optional in UCCI\r
+           if(varOpt) EPRINT((f, "# setoption name UCI_Variant value chess\n"))\r
+           pause = 1; // wait for option settings to take effect\r
+           EPRINT((f, "# isready\n")) fflush(toE);\r
+           Sync(PAUSE); // wait for readyok\r
+           EPRINT((f, "# u%cinewgame\n", sc)) fflush(toE);\r
        }\r
        else if(!strcmp(command, "level")) {\r
            int sec = 0;\r
@@ -460,24 +535,12 @@ GUI2Engine()
            sscanf(line, "level %d %d %d", &mps, &tc, &inc);\r
            tc = (60*tc + sec)*1000; inc *= 1000; sTime = 0; tc /= unit; inc /= unit;\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
-           if(p = strchr(line, '=')) {\r
-               *p++ = 0;\r
-               if(strstr(checkOptions, line+7)) sprintf(p, "%s\n", atoi(p) ? "true" : "false");\r
-               EPRINT((f, "# setoption %s%s %s%s", nameWord, line+7, valueWord, p))\r
-           } else EPRINT((f, "# setoption %s%s\n", nameWord, line+7))\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 name=1 reuse=0 exclude=1 pause=1 sigint=0 sigterm=0 done=0\n", variants);\r
+           if(!varList[0]) strcpy(varList, sc=='s' ? ",shogi,5x5+5_shogi" : VARIANTS);\r
+           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
@@ -517,35 +580,27 @@ GUI2Engine()
            if(!(sm & 2)) goto nomove; // no moves enabled; continue current search\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
-           suspended = 1 + pondering; // remember if we were pondering, and stop search ignoring bestmove\r
-           StopPonder(pondering || computer == stm);\r
-       }\r
-       else if(!strcmp(command, "resume")) {\r
-           if(suspended == 2) StartPonder(); // restart interrupted ponder search\r
-           suspended = 0; // causes thinking to start in normal way if on move or analyzing\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), searching = 0;\r
+       else if(!strcmp(command, "analyze"))computer = ANALYZE, collect = 1, sm = 0, Analyze("true");\r
+       else if(!strcmp(command, "exit"))   computer = NONE, StopPonder(1), searching = 0, Analyze("false");\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, "otim"))   sscanf(line+4, "%d", &hisTime), hisTime = (10*hisTime)/unit;\r
-       else if(!strcmp(command, "post"))   post = 1;\r
-       else if(!strcmp(command, "nopost")) post = 0;\r
-       else if(!strcmp(command, "easy") && !!*canPonder) { ponder = 0; StopPonder(pondering); EPRINT((f, "# setoption %s%s %sfalse\n", nameWord, canPonder, valueWord)) }\r
-       else if(!strcmp(command, "hard") && !!*canPonder) { ponder = 1; EPRINT((f, "# setoption %s%s %strue\n", nameWord, canPonder, valueWord)) StartPonder(); }\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, "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
+           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
        else if(!strcmp(command, "computer")) comp = 1;\r
-       else if(!strcmp(command, "result")) { if(sc == 's') EPRINT((f, "# gameover %s\n", line[8] == '/' ? "draw" : (line[7] == '0') == mySide ? "win" : "lose")) }\r
-       else if(!strcmp(command, "quit"))   { EPRINT((f, "# quit\n")) fflush(toE), exit(0); }\r
+       else if(!strcmp(command, "result")) {\r
+           if(sc == 's') EPRINT((f, "# gameover %s\n", line[8] == '/' ? "draw" : (line[7] == '0') == mySide ? "win" : "lose"))\r
+           computer = NONE;\r
+       }\r
+       else if(!strcmp(command, "quit"))   { EPRINT((f, "# quit\n")) fflush(toE), exit(atoi(line+4)); }\r
     }\r
 }\r
 \r
@@ -640,7 +695,7 @@ main(int argc, char **argv)
 \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 && !strcmp(argv[1], "-var")) { strcpy(varList+1, argv[2]); *varList = ','; 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
@@ -651,7 +706,7 @@ main(int argc, char **argv)
        else if(sc == 'n') sc = 'c'; // UCI for normal Chess\r
 \r
        // spawn engine proc\r
-       if(StartEngine(argv[1], dir) != NO_ERROR) { perror(argv[1]), exit(-1); }\r
+       if(StartEngine(binary = argv[1], dir) != NO_ERROR) { perror(argv[1]), exit(-1); }\r
 \r
        Sync(INIT);\r
 \r