changes from H.G. Muller; version 4.3.16
[xboard.git] / zippy.c
diff --git a/zippy.c b/zippy.c
index c788318..c77276f 100644 (file)
--- a/zippy.c
+++ b/zippy.c
@@ -88,6 +88,8 @@ extern char *getenv();
 #include "backend.h"\r
 #include "backendz.h"\r
 \r
+char *SendMoveToBookUser P((int nr, ChessProgramState *cps, int initial)); // [HGM] book
+
 static char zippyPartner[MSG_SIZ];\r
 static char zippyLastOpp[MSG_SIZ];\r
 static int zippyConsecGames;\r
@@ -873,7 +875,11 @@ int ZippyMatch(buf, i)
     if (looking_at(buf, i, "Challenge: * (*) *(*) * * * * Loaded from *")) {\r
        /* note: star_match[2] can include "[white] " or "[black] "\r
           before our own name. */\r
-       ZippyHandleChallenge(star_match[4], star_match[8],\r
+       if(star_match[8] == NULL || star_match[8][0] == 0) // [HGM] chessd: open-source ICS has file on next line\r
+            ZippyHandleChallenge(star_match[4], star_match[5],\r
+                            star_match[6], star_match[7],\r
+                            StripHighlightAndTitle(star_match[0]));\r
+       else ZippyHandleChallenge(star_match[4], star_match[8],\r
                             star_match[6], star_match[7],\r
                             StripHighlightAndTitle(star_match[0]));\r
        return TRUE;\r
@@ -960,7 +966,8 @@ void ZippyFirstBoard(moveNum, basetime, increment)
     char buf[MSG_SIZ];\r
     int w, b;\r
     char *opp = (gameMode==IcsPlayingWhite ? gameInfo.black : gameInfo.white);\r
-    Boolean sentPos = FALSE;\r
+    Boolean sentPos = FALSE;
+    char *bookHit = NULL; // [HGM] book\r
 \r
     if (!first.initDone) {\r
       /* Game is starting prematurely.  We can't deal with this */\r
@@ -1031,7 +1038,7 @@ void ZippyFirstBoard(moveNum, basetime, increment)
                  SendTimeRemaining(&first, TRUE);\r
                }\r
              }\r
-             SendToProgram("go\n", &first);\r
+             bookHit = SendMoveToBookUser(forwardMostMove-1, &first, TRUE); // [HGM] book: send go or retrieve book move\r
            } else {\r
                /* Engine's opponent is on move now */\r
                if (first.usePlayother) {\r
@@ -1057,7 +1064,8 @@ void ZippyFirstBoard(moveNum, basetime, increment)
                  SendTimeRemaining(&first, TRUE);\r
                }\r
              }\r
-             SendToProgram("go\n", &first);\r
+//           SendToProgram("go\n", &first);\r
+             bookHit = SendMoveToBookUser(forwardMostMove-1, &first, TRUE); // [HGM] book: send go or retrieve book move\r
            }\r
        }\r
     } else if (gameMode == IcsPlayingBlack) {\r
@@ -1081,7 +1089,8 @@ void ZippyFirstBoard(moveNum, basetime, increment)
                  SendTimeRemaining(&first, FALSE);\r
                }\r
              }\r
-             SendToProgram("go\n", &first);\r
+//           SendToProgram("go\n", &first);\r
+             bookHit = SendMoveToBookUser(forwardMostMove-1, &first, TRUE); // [HGM] book: send go or retrieve book move\r
            } else {\r
                /* Engine's opponent is on move now */\r
                if (first.usePlayother) {\r
@@ -1099,6 +1108,18 @@ void ZippyFirstBoard(moveNum, basetime, increment)
            /* Nothing needs to be done here */\r
        }       \r
     }\r
+
+    if(bookHit) { // [HGM] book: simulate book reply
+       static char bookMove[MSG_SIZ]; // a bit generous?
+
+       programStats.depth = programStats.nodes = programStats.time = 
+       programStats.score = programStats.got_only_move = 0;
+       sprintf(programStats.movelist, "%s (xbook)", bookHit);
+
+       strcpy(bookMove, "move ");
+       strcat(bookMove, bookHit);
+       HandleMachineMove(bookMove, &first);
+    }
 }\r
 \r
 \r