Recognize 'result' command in WB driver
[hachu.git] / hachu.c
diff --git a/hachu.c b/hachu.c
index ff3c901..c59149b 100644 (file)
--- a/hachu.c
+++ b/hachu.c
@@ -46,7 +46,7 @@
 #define EMPTY      0\r
 #define EDGE   (1<<11)\r
 #define TYPE   (WHITE|BLACK|EDGE)\r
-#define ABSENT  4095\r
+#define ABSENT  2047\r
 #define INF     8000\r
 #define NPIECES 2000               /* length of piece list    */\r
 \r
@@ -409,6 +409,13 @@ typedef struct {
   char age;\r
 } HashEntry; // hash-table entry\r
 \r
+    // Some global variables that control your engine's behavior\r
+    int ponder;\r
+    int randomize;\r
+    int postThinking;\r
+    int resign;         // engine-defined option\r
+    int contemptFactor; // likewise\r
+\r
 int squareKey[BSIZE];\r
 \r
 int rawBoard[BSIZE + 11*BW + 6];\r
@@ -1289,6 +1296,11 @@ if(flag && depth>= 0) printf("phase=%d: first/curr/last = %d / %d / %d\n", phase
            break;\r
          case 7: // bad captures\r
          case 8: // PV null move\r
+           phase = 9;\r
+           if(nullMove != ABSENT) {\r
+             moveStack[msp++] = nullMove + (nullMove << SQLEN) | DEFER; // kludge: setting DEFER guarantees != 0, and has no effect\r
+           }\r
+printf("# %d. sqr = %08x null = %08x\n", msp, nullMove, moveStack[msp-1]);\r
          case 9:\r
            goto cutoff;\r
        }\r
@@ -1379,6 +1391,12 @@ 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
+      if(postThinking > 0) {\r
+        int i;   // WB thinking output\r
+       printf("%d %d %d %d", iterDep, bestScore, (GetTickCount() - startTime)/10, nodes);\r
+       for(i=0; pv[i]; i++) printf(" %s", MoveToText(pv[i], 0));\r
+       printf("\n"); fflush(stdout);\r
+      }\r
       if(GetTickCount() - startTime > tlim1) break; // do not start iteration we can (most likely) not finish\r
     }\r
     replyDep = iterDep;\r
@@ -1533,6 +1551,7 @@ MoveToText (MOVE move, int multiLine)
 {\r
   static char buf[50];\r
   int f = move>>SQLEN & SQUARE, g = f, t = move & SQUARE;\r
+  if(f == t) { sprintf(buf, "@@@@"); return buf; } // null-move notation in WB protocol\r
   buf[0] = '\0';\r
   if(t >= SPECIAL) { // kludgy! Print as side effect non-standard WB command to remove victims from double-capture (breaks hint command!)\r
     int e = f + epList[t - SPECIAL];\r
@@ -1565,6 +1584,7 @@ MOVE
 ParseMove (char *moveText)\r
 {\r
   int i, j, f, t, t2, e, ret, deferred=0;\r
+  char c = moveText[0];\r
   moveText += ReadSquare(moveText, &f);\r
   moveText += ReadSquare(moveText, &t); t2 = t;\r
   if(*moveText == ',') {\r
@@ -1581,9 +1601,14 @@ ParseMove (char *moveText)
   }\r
   ret = f<<SQLEN | t2;\r
   if(*moveText == '+') ret |= PROMOTE;\r
+printf("# suppress = %c%d\n", sup1%BW+'a', sup1/BW);\r
 MapFromScratch(attacks);\r
+  postThinking--;\r
   Search(-INF-1, INF+1, 0, 1, sup1, sup2);\r
+  postThinking++;\r
   for(i=retFirst; i<retMSP; i++) {\r
+    if(moveStack[i] == INVALID) continue;\r
+    if(c == '@' && (moveStack[i] & SQUARE) == (moveStack[i] >> SQLEN & SQUARE)) break; // any null move matches @@@@\r
     if((moveStack[i] & (PROMOTE | DEFER-1)) == ret) break;\r
     if((moveStack[i] & DEFER-1) == ret) deferred = i; // promoted version of entered non-promotion is legal\r
   }\r
@@ -1613,7 +1638,9 @@ Highlight(char *coords)
   ReadSquare(coords, &sqr);\r
 MapFromScratch(attacks);\r
 flag=1;\r
+  postThinking--;\r
   Search(-INF-1, INF+1, 0, 1, sup1, sup2);\r
+  postThinking++;\r
 flag=0;\r
   for(i=retFirst; i<retMSP; i++) {\r
     if(sqr == (moveStack[i]>>SQLEN & SQUARE)) {\r
@@ -1680,13 +1707,6 @@ PonderUntilInput (int stm)
 {\r
 }\r
 \r
-    // Some global variables that control your engine's behavior\r
-    int ponder;\r
-    int randomize;\r
-    int postThinking;\r
-    int resign;         // engine-defined option\r
-    int contemptFactor; // likewise\r
-\r
     int TakeBack(int n)\r
     { // reset the game and then replay it to the desired point\r
       int last, stm;\r
@@ -1828,6 +1848,7 @@ printf("in: %s\n", command);
         if(!strcmp(command, "ics"))     { continue; }\r
         if(!strcmp(command, "accepted")){ continue; }\r
         if(!strcmp(command, "rejected")){ continue; }\r
+        if(!strcmp(command, "result"))  { continue; }\r
         if(!strcmp(command, "hover"))   {  continue; }\r
         if(!strcmp(command, ""))  {  continue; }\r
         if(!strcmp(command, "usermove")){\r