Refrain from starting analysis search if all moves excluded
[uci2wb.git] / UCI2WB.c
index b901bbc..81a7e5f 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
@@ -414,7 +415,7 @@ Move4Engine(char *m)
     }\r
 }\r
 \r
-int DoCommand ();\r
+void DoCommand ();\r
 char mySide;\r
 volatile char queue[10000], *qStart, *qEnd;\r
 \r
@@ -423,7 +424,7 @@ LaunchSearch()
 {\r
     int i;\r
 \r
-       if((computer == stm || computer == ANALYZE && !searching) && !suspended) {\r
+       if((computer == stm || computer == ANALYZE && !searching && sm != 1) && !suspended) {\r
            DPRINT("# start search\n");\r
            LoadPos(moveNr); fflush(stdout); // load position\r
            // and set engine thinking (note USI swaps colors!)\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
-           if(searching) searching = 0, StopPonder(1);\r
+           StopSearch(1);\r
        }\r
        else { //convert easy & hard to "option" after treating their effect on the adapter\r
          if(!strcmp(command, "easy")) {\r
@@ -493,7 +497,7 @@ 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
@@ -505,8 +509,8 @@ GUI2Engine()
       {\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
@@ -516,14 +520,14 @@ GUI2Engine()
     }\r
 }\r
 \r
-int\r
+void\r
 DoCommand ()\r
 {\r
     char line[1024], command[256], *p, *q, *r, type[99];\r
     int i;\r
 \r
     p=line; while(qStart < qEnd && (*p++ = *qStart++) != '\n') {} *p = 0;\r
-    if(line[0] == '\n') return 0;\r
+    if(line[0] == '\n') return;\r
     sscanf(line, "%s", command);\r
 \r
        if(!strcmp(command, "new")) {\r
@@ -586,15 +590,10 @@ 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
            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
-           if(!(sm & 2)) return 1; // no moves enabled; continue current search\r
        }\r
        else if(!strcmp(command, "xboard")) ;\r
        else if(!strcmp(command, "analyze"))computer = ANALYZE, collect = 1, sm = 0, Analyze("true");\r
@@ -618,8 +617,6 @@ DoCommand ()
            computer = NONE;\r
        }\r
        else if(!strcmp(command, "quit"))   { EPRINT((f, "# quit\n")) fflush(toE), exit(atoi(line+4)); }\r
-\r
-    return 0;\r
 }\r
 \r
 void *\r
@@ -630,7 +627,7 @@ Engine2GUI()
        if(searching > 1) HandleEngineOutput();  // this could leave us (or fall through) pondering\r
        while(qStart == qEnd && searching) HandleEngineOutput(); // relay ponder output until command arrives\r
        Sync(PAUSE); // possibly wait for command silently if engine is idle\r
-       if(!DoCommand()) LaunchSearch();\r
+       DoCommand(); LaunchSearch();\r
     }\r
 }\r
 \r