Let LaunchSearch() also start ponder search
[uci2wb.git] / UCI2WB.c
index 1cb0a16..7cdf340 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
@@ -188,6 +188,7 @@ StartPonder(int moveNr)
        if(!move[moveNr][0]) return; // no ponder move\r
        LoadPos(moveNr+1);\r
        searching = 1; lastDepth = 1;\r
+       DPRINT("# ponder on %s\n", move[moveNr]);\r
        StartSearch(" ponder");\r
 }\r
 \r
@@ -266,10 +267,7 @@ HandleEngineOutput()
            // first start a new ponder search, if pondering is on and we have a move to ponder on\r
            if(p = strstr(line+9, "ponder")) {\r
              sscanf(p+7, "%s", move[moveNr]);\r
-             if(computer != NONE && ponder) {\r
-               DPRINT("# ponder on %s\n", move[moveNr]);\r
-               StartPonder(moveNr);\r
-             }\r
+             if(computer != NONE && ponder) StartPonder(moveNr);\r
              p[-1] = '\n'; *p = 0; // strip off ponder move\r
            } else move[moveNr][0] = 0;\r
            Move4GUI(line+9);\r
@@ -294,17 +292,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 +300,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 +309,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
@@ -372,6 +369,7 @@ HandleEngineOutput()
                    sprintf(buf + strlen(buf), "%s%s%s", min++ ? " /// " : " ", strcmp(type, val) ? "" : "*", val);\r
                }\r
                strcat(q, "\"\n");\r
+\r
            }\r
            else buf[0] = 0; // ignore unrecognized option types\r
            if(buf[0]) printf("%s", buf);\r
@@ -425,7 +423,9 @@ LaunchSearch()
 {\r
     int i;\r
 \r
-       if((computer == stm || computer == ANALYZE && !searching && sm != 1) && !suspended) {\r
+    if(suspended || searching) return;\r
+\r
+       if(computer == stm || computer == ANALYZE && sm != 1) {\r
            DPRINT("# start search\n");\r
            LoadPos(moveNr); fflush(stdout); // load position\r
            // and set engine thinking (note USI swaps colors!)\r
@@ -439,6 +439,7 @@ LaunchSearch()
                EPRINT((f, "\n")) searching = 2; // suppresses spurious commands during analysis starting new searches\r
            } else searching = 3, StartSearch(""); // request suspending of input processing while thinking\r
        } else if(ponderAlways && computer == NONE) move[moveNr][0] = 0, StartPonder(moveNr-1);\r
+       else if(BLACK+WHITE-stm == computer && ponder && moveNr) StartPonder(moveNr);\r
 }\r
 \r
 void\r
@@ -460,7 +461,7 @@ 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
@@ -468,8 +469,12 @@ GUI2Engine()
            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
@@ -620,6 +625,7 @@ DoCommand ()
            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