Bump version to 4.0
[uci2wb.git] / UCI2WB.c
index 1632b81..a546859 100644 (file)
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -9,7 +9,7 @@
 /* of which you should have received a copy together with this file.        */\r
 /****************************************************************************/\r
 \r
-#define VERSION "3.0"\r
+#define VERSION "4.0"\r
 \r
 #include <stdio.h>\r
 #include <stdlib.h>\r
@@ -294,17 +294,6 @@ HandleEngineOutput()
                }\r
                continue;\r
            }\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
@@ -313,8 +302,6 @@ HandleEngineOutput()
                if(p = strstr(line+4, " score "))      sscanf(p+7, "%d", &s), statScore = s;\r
                if(p = strstr(line+4, " nodes "))      sscanf(p+7, "%d", &n), statNodes = n;\r
                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(d > maxDepth) maxDepth = d, mpvSP = 0; else if(d < maxDepth) continue; // ignore depth regressions\r
                  if(p = strstr(line+4, " upperbound ")) strcat(p, "?\n"); else\r
@@ -324,6 +311,18 @@ HandleEngineOutput()
                    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
+           if(collect && (pv = strstr(line+4, " currmove "))) {\r
+               sscanf(pv+10,"%s", currMove);\r
+               if(p = strstr(line+4, " currmovenumber ")) {\r
+                   n = currNr = atoi(p+16);\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; strcpy(moveMap[n], currMove); continue; // store move\r
+               }\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
@@ -453,7 +452,6 @@ GUI2Engine()
        fflush(toE); fflush(stdout);\r
        if(!ReadLine(stdin, line)) printf("# EOF\n"), sprintf(line, "quit -1\n");\r
        sscanf(line, "%s", command);\r
-       DPRINT("# %s searching=%d\n", command, searching);\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
@@ -461,13 +459,21 @@ GUI2Engine()
        else if(!strcmp(command, "post"))  post = 1;\r
        else if(!strcmp(command, "nopost"))post = 0;\r
        else if(!strcmp(command, ".")) {\r
-           printf("stat01: %d %d %d %d 100 %s\n", statTime, statNodes, statDepth, 100-currNr, currMove);\r
+           printf("stat01: %d %d %d %d %d %s\n", statTime, statNodes, statDepth, nr-currNr, nr, currMove);\r
        }\r
        else if(!strcmp(command, "pause")) {\r
            if(computer == stm) myTime -= GetTickCount() - startTime;\r
            suspended = 1 + (searching == 1); // remember if we were pondering, and stop search ignoring bestmove\r
            StopSearch(1);\r
        }\r
+       else if(!strcmp(command, "xboard")) ;\r
+       else if(!strcmp(command, "random")) ;\r
+       else if(!strcmp(command, "accepted")) ;\r
+       else if(!strcmp(command, "rejected")) ;\r
+       else if(!strcmp(command, "book")) ;\r
+       else if(!strcmp(command, "ics")) ;\r
+       else if(!strcmp(command, "hint")) ;\r
+       else if(!strcmp(command, "computer")) comp = 1;\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
@@ -509,6 +515,7 @@ GUI2Engine()
            suspended = 0;  *qEnd++ = '\n'; Sync(WAKEUP); // causes search to start in normal way if on move or analyzing\r
        } else\r
       {\r
+       DPRINT("# queue '%s', searching=%d\n", command, searching);\r
        if(searching == 3) { // command arrived during thinking; order abort for 'instant commands'\r
            if(!strcmp(command, "?") || !strcmp(command, "quit") ||\r
               !strcmp(command, "force") || !strcmp(command, "result")) StopSearch(0);\r
@@ -538,10 +545,10 @@ DoCommand ()
            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
            EPRINT((f, "# isready\n")) fflush(toE);\r
            HandleEngineOutput(); // wait for readyok\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
        }\r
        else if(!strcmp(command, "option")) {\r
@@ -596,7 +603,6 @@ DoCommand ()
            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
        }\r
-       else if(!strcmp(command, "xboard")) ;\r
        else if(!strcmp(command, "analyze"))computer = ANALYZE, collect = 1, sm = 0, Analyze("true");\r
        else if(!strcmp(command, "exit"))   computer = NONE, Analyze("false");\r
        else if(!strcmp(command, "force"))  computer = NONE;\r
@@ -612,12 +618,12 @@ DoCommand ()
        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")) {\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
+       else printf("Error (unknown command): %s\n", command);\r
 \r
        fflush(stdout);\r
 }\r