Launch searches at end of GUI loop
[uci2wb.git] / UCI2WB.c
index 1fc24fc..b9df43c 100644 (file)
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -441,12 +441,9 @@ char mySide;
 char queue[10000], *qStart, *qEnd;\r
 \r
 void\r
-GUI2Engine()\r
+LaunchSearch()\r
 {\r
-    char line[256], command[256], *p;\r
-\r
-    while(1) {\r
-       int i, difficult;\r
+    int i;\r
 \r
        if((computer == stm || computer == ANALYZE && !searching) && !suspended) {\r
            DPRINT("# start search\n");\r
@@ -462,7 +459,16 @@ GUI2Engine()
                EPRINT((f, "\n")) searching = 2; // suppresses spurious commands during analysis starting new searches\r
            } else pause = 2, searching = 3, StartSearch(""); // request suspending of input processing while thinking\r
        } else if(ponderAlways && computer == NONE) move[moveNr][0] = 0, StartPonder(moveNr-1);\r
-      nomove:\r
+}\r
+\r
+void\r
+GUI2Engine()\r
+{\r
+    char line[256], command[256], *p;\r
+\r
+    while(1) {\r
+       int i, difficult;\r
+\r
        for(difficult=0; !difficult; ) { // read and handle commands that can (or must) be handled during thinking\r
        fflush(toE); fflush(stdout);\r
        if(!ReadLine(stdin, line)) printf("# EOF\n"), sprintf(line, "quit -1\n");\r
@@ -517,18 +523,18 @@ GUI2Engine()
                    searching = 0; pause = 2; moveNr++; startTime = GetTickCount(); // clock starts running now\r
                    EPRINT((f, "# ponderhit%s\n", draw)) fflush(toE); fflush(stdout);\r
                    searching = 3; // request blocking input during thinking\r
-                   goto nomove;\r
+                   continue;\r
                }\r
                StopPonder(1); searching = 0;\r
            }\r
            strcpy(move[moveNr++], command); // possibly overwrites ponder move\r
-           continue;\r
-       }\r
+       } else\r
        if(!strcmp(command, "resume")) {\r
            searching = 0;\r
            if(suspended == 2) StartPonder(moveNr); // restart interrupted ponder search\r
-           suspended = 0; continue;  // causes thinking to start in normal way if on move or analyzing\r
-       }\r
+           suspended = 0;  // causes thinking 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")) { EPRINT((f, "# stop\n")); fflush(toE); }\r
@@ -536,7 +542,10 @@ GUI2Engine()
        }\r
        if(qStart == qEnd) qStart = qEnd = queue;\r
        p = line; while(qEnd < queue+10000 && (*qEnd++ = *p++) != '\n') {}\r
-       if(DoCommand()) goto nomove;\r
+       if(DoCommand()) continue;\r
+      }\r
+\r
+       LaunchSearch(); // start a search if we need one\r
     }\r
 }\r
 \r