Handle periodic updates with easy commands
[uci2wb.git] / UCI2WB.c
index 536eb44..41c71c8 100644 (file)
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -160,9 +160,10 @@ StartSearch(char *ponder)
 }\r
 \r
 void\r
-StopPonder(int pondering)\r
+StopSearch(int discard)\r
 {\r
-       if(!pondering) return;\r
+       if(!searching) return;\r
+       if(discard) searching = 0; // this causes bestmove to be ignored\r
        EPRINT((f, "# stop\n")) fflush(toE); // note: 'pondering' remains set until engine acknowledges 'stop' with 'bestmove'\r
 }\r
 \r
@@ -457,10 +458,13 @@ GUI2Engine()
        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, ".")) {\r
+           printf("stat01: %d %d %d %d 100 %s\n", statTime, statNodes, statDepth, 100-currNr, 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
-           StopPonder(searching);\r
+           StopSearch(1);\r
        }\r
        else { //convert easy & hard to "option" after treating their effect on the adapter\r
          if(!strcmp(command, "easy")) {\r
@@ -468,8 +472,8 @@ GUI2Engine()
          }\r
          else if(!strcmp(command, "hard")) {\r
            if(*canPonder) ponder = 1, sprintf(command, "option"), sprintf(line, "option %s=1\n", canPonder); else continue;\r
-         } else\r
-         if(!strcmp(command, "option")) {\r
+         }\r
+         else if(!strcmp(command, "option")) {\r
            if(sscanf(line+7, "UCI2WB debug output=%d", &debug) == 1) ; else\r
            if(sscanf(line+7, "ponder always=%d", &ponderAlways) == 1) ; else\r
            if(sscanf(line+7, "Floating Byoyomi=%d", &flob) == 1) ; else\r
@@ -493,21 +497,20 @@ GUI2Engine()
                    EPRINT((f, "# ponderhit%s\n", draw)) fflush(toE); fflush(stdout);\r
                    continue;\r
                }\r
-               searching = 0; StopPonder(1);\r
+               StopSearch(1);\r
            }\r
            strcpy(move[moveNr++], command); // possibly overwrites ponder move\r
            *qEnd++ = '\n'; Sync(WAKEUP);    // make sure engine thread considers starting a search\r
        } else\r
        if(!strcmp(command, "resume")) {\r
-           searching = 0;\r
            if(suspended == 2) StartPonder(moveNr); // restart interrupted ponder search\r
-           suspended = 0;  // causes thinking to start in normal way if on move or analyzing\r
+           suspended = 0;  *qEnd++ = '\n'; Sync(WAKEUP); // causes search to start in normal way if on move or analyzing\r
        } else\r
       {\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")) StopPonder(1);\r
-       } else if(searching) searching = 0, StopPonder(1); // always abort pondering or analysis\r
+              !strcmp(command, "force") || !strcmp(command, "result")) StopSearch(0);\r
+       } else StopSearch(1); // always abort pondering or analysis\r
 \r
        // queue command for execution by engine thread\r
        if(qStart == qEnd) qStart = qEnd = queue;\r
@@ -587,10 +590,6 @@ DoCommand ()
        else if(!strcmp(command, "undo") && (i=1) || !strcmp(command, "remove") && (i=2)) {\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
-           return 1;\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