Fix clearing input buffer
[hachu.git] / hachu.c
diff --git a/hachu.c b/hachu.c
index ff5cc8f..7838313 100644 (file)
--- a/hachu.c
+++ b/hachu.c
@@ -1853,7 +1853,7 @@ if(PATH) printf("%d:%2d:%d %3d %6x %-10s %6d %6d\n", level, depth, iterDep, curM
        printf("\n");\r
         fflush(stdout);\r
       }\r
-      if(GetTickCount() - startTime > tlim1) break; // do not start iteration we can (most likely) not finish\r
+      if(!(abortFlag & 1) && GetTickCount() - startTime > tlim1) break; // do not start iteration we can (most likely) not finish\r
     }\r
     replyDep = iterDep;\r
 #ifdef HASH\r
@@ -2261,6 +2261,9 @@ MapFromScratch(attacks);
 void\r
 PonderUntilInput (int stm)\r
 {\r
+MapFromScratch(attacks);\r
+  repCnt = 0; abortFlag = -1;\r
+  Search(-INF-1, INF+1, rootEval, maxDepth, sup1, sup2);\r
 }\r
  \r
     int TakeBack(int n)\r
@@ -2292,11 +2295,13 @@ printf("# setup done");fflush(stdout);
 \r
         // extract the first word\r
         sscanf(inBuf, "%s", command);\r
+printf("# in (mode = %d,%d): %s\n", root, abortFlag, command);\r
         if(!strcmp(command, "otim"))    { continue; } // do not start pondering after receiving time commands, as move will follow immediately\r
         if(!strcmp(command, "time"))    { sscanf(inBuf, "time %d", &timeLeft); continue; }\r
         if(!strcmp(command, "put"))     { ReadSquare(inBuf+4, &lastPut); continue; }  // ditto\r
         if(!strcmp(command, "."))       { inBuf[0] = 0; return; } // ignore for now\r
         if(!strcmp(command, "lift"))    { inBuf[0] = 0; Highlight(inBuf+5); return; } // treat here\r
+        abortFlag = 1;\r
         return;\r
       }\r
     }\r
@@ -2304,7 +2309,11 @@ printf("# setup done");fflush(stdout);
     void\r
     TerminationCheck()\r
     {\r
+      if(abortFlag < 0) { // check for input\r
+        if(InputWaiting()) GetLine(0); // read & examine input command\r
+      } else {        // check for time\r
         if(GetTickCount() - startTime > tlim3) abortFlag = 2;\r
+      }\r
     }\r
 \r
     main()\r
@@ -2314,10 +2323,12 @@ printf("# setup done");fflush(stdout);
       int i, score, curVarNr;\r
 \r
   Init(V_CHU); // Chu\r
+      listEnd = 1;\r
 \r
       while(1) { // infinite loop\r
 \r
         fflush(stdout);                 // make sure everything is printed before we do something that might take time\r
+        *inBuf = 0;\r
 \r
         if(listEnd == 0) ListMoves();   // always maintain a list of legal moves in root position\r
 \r