Process usermove in ponder input
[hachu.git] / hachu.c
diff --git a/hachu.c b/hachu.c
index 9a8c518..609f05e 100644 (file)
--- a/hachu.c
+++ b/hachu.c
@@ -131,7 +131,7 @@ typedef struct {
 char *array, fenArray[4000], *reason;\r
 int bWidth, bHeight, bsize, zone, currentVariant, chuFlag, tenFlag, chessFlag, repDraws;\r
 int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, rootEval, retMSP, retFirst, retDep, pvPtr, level, cnt50, mobilityScore;\r
-int nodes, startTime, tlim1, tlim2, tlim3, repCnt, comp, abortFlag;\r
+int nodes, startTime, lastRootMove, lastRootIter, tlim1, tlim2, tlim3, repCnt, comp, abortFlag;\r
 Move ponderMove;\r
 Move retMove, moveStack[10000], path[100], repStack[300], pv[1000], repeatMove[300], killer[100][2];\r
 \r
@@ -1644,6 +1644,7 @@ if(PATH) /*pboard(board),pmap(attacks, BLACK),*/printf("search(%d) {%d,%d} eval=
   replyDep = (depth < 1 ? depth-1 : iterDep);\r
   while(++iterDep <= depth || iterDep == 1) {\r
 if(flag && depth>= 0) printf("iter %d:%d\n", depth,iterDep),fflush(stdout);\r
+    oldBest = bestScore;\r
     iterAlpha = alpha; bestScore = -INF; bestMoveNr = 0; resDep = 60;\r
     for(curMove = firstMove; ; curMove++) { // loop over moves\r
 if(flag && depth>= 0) printf("phase=%d: first/curr/last = %d / %d / %d\n", phase, firstMove, curMove, msp);fflush(stdout);\r
@@ -1846,9 +1847,11 @@ if(PATH) printf("%d:%2d:%d %3d %6x %-10s %6d %6d\n", level, depth, iterDep, curM
     } // next move\r
   cutoff:\r
     if(!level) { // root node\r
+      lastRootIter = GetTickCount() - startTime;\r
       if(postThinking > 0) {\r
         int i;   // WB thinking output\r
-       printf("%d %d %d %d", iterDep, bestScore, (GetTickCount() - startTime)/10, nodes);\r
+       printf("%d %d %d %d", iterDep, bestScore, lastRootIter/10, nodes);\r
+        if(ponderMove) printf(" (%s)", MoveToText(ponderMove, 0));\r
        for(i=0; pv[i]; i++) printf(" %s", MoveToText(pv[i], 0));\r
         if(iterDep == 1) printf(" { root eval = %4.2f dif = %4.2f; abs = %4.2f}", curEval/100., difEval/100., PSTest()/100.);\r
        printf("\n");\r
@@ -2303,6 +2306,15 @@ printf("# in (mode = %d,%d): %s\n", root, abortFlag, command);
         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
+        if(!root && !strcmp(command, "usermove")) {\r
+          abortFlag = !!strcmp(inBuf+9, ponderMoveText);\r
+          if(!abortFlag) { // ponder hit, continue as time-based search\r
+            SetSearchTimes(10*timeLeft + GetTickCount() - startTime); // add time we already have been pondering to total\r
+            if(lastRootIter > tlim1) abortFlag = 2; // abort instantly if we are in iteration we should not have started\r
+            inBuf[0] = 0; ponderMove = INVALID;\r
+            return;\r
+          }\r
+        }\r
         abortFlag = 1;\r
         return;\r
       }\r
@@ -2360,7 +2372,7 @@ pboard(board);
             PrintResult(stm, score);\r
           } else {\r
             stm = MakeMove2(stm, move);  // assumes MakeMove returns new side to move\r
-            gameMove[moveNr++] = move;  // remember game\r
+            gameMove[moveNr++] = move;   // remember game\r
             printf("move %s\n", MoveToText(move, 1));\r
             listEnd = 0;\r
             continue;\r