Fix protocol move in Duck Chess
authorH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 6 Nov 2022 18:22:35 +0000 (19:22 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 6 Nov 2022 18:22:35 +0000 (19:22 +0100)
The move format used the Duck destination as intermediate square,
while it was supposed to use the FIDE destination as such.
And the trailing comma of the first leg would make the parser erase
the kill location read in the second leg, replacing it by an invalid one.

backend.c
winboard/winboard.c

index c092efb..4161d35 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -5215,7 +5215,12 @@ SendMoveToProgram (int moveNum, ChessProgramState *cps)
                                               m[5], m[6] - '0',
                                               m[5], m[6] - '0',
                                               m[2], m[3] - '0', c);
-       } else
+       } else if(gameInfo.variant == VariantDuck)
+         snprintf(buf, MSG_SIZ, "%c%d%c%d,%c%d%c%d%s\n", m[0], m[1] - '0', // convert to two moves
+                                              m[2], m[3] - '0',
+                                              m[2], m[3] - '0',
+                                              m[5], m[6] - '0', c);
+       else
          snprintf(buf, MSG_SIZ, "%c%d%c%d,%c%d%c%d%s\n", m[0], m[1] - '0', // convert to two moves
                                               m[5], m[6] - '0',
                                               m[5], m[6] - '0',
@@ -8810,7 +8815,8 @@ Adjudicate (ChessProgramState *cps)
                  */
                if((gameMode == TwoMachinesPlay ? second.offeredDraw : userOfferedDraw) || first.offeredDraw ) {
                          char *p = NULL;
-                         if((signed char)boards[forwardMostMove][EP_STATUS] == EP_RULE_DRAW)
+                         if((signed char)boards[forwardMostMove][EP_STATUS] == EP_RULE_DRAW)-      safeStrCpy(machineMove, firstLeg, 20); machineMove[strlen(machineMove)-1] = 0;
+
                              p = "Draw claim: 50-move rule";
                          if((signed char)boards[forwardMostMove][EP_STATUS] == EP_REP_DRAW)
                              p = "Draw claim: 3-fold repetition";
@@ -9132,7 +9138,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
 
        // [HGM] lion: (some very limited) support for Alien protocol
        killX = killY = kill2X = kill2Y = -1;
-       if(machineMove[strlen(machineMove)-1] == ',') { // move ends in coma: non-final leg of composite move
+       if(machineMove[strlen(machineMove)-1] == ',') { // move ends in comma: non-final leg of composite move
            if(legs++) return;                     // middle leg contains only redundant info, ignore (but count it)
            safeStrCpy(firstLeg, machineMove, 20); // just remember it for processing when second leg arrives
            return;
@@ -9147,7 +9153,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
          char buf[20], *p = machineMove+1, *q = buf+1, f;
          if(gameInfo.variant == VariantDuck) { // Duck Chess: 1st leg is FIDE move, 2nd is Duck
            sscanf(machineMove, "%c%d%c%d", &f, &killY, &f, &killY); killX = f - AAA; killY -= ONE - '0';
-           safeStrCpy(machineMove, firstLeg, 20);
+           safeStrCpy(machineMove, firstLeg, 20); machineMove[strlen(machineMove)-1] = 0;
           } else {
            // only support case where same piece makes two step
            safeStrCpy(buf, machineMove, 20);
index e152a9a..15526e2 100644 (file)
@@ -382,6 +382,7 @@ LoadLanguageFile(char *name)
             }\r
             languageBuf[--i] = k;\r
 \r
+\r
         }\r
         i++;\r
     }\r
@@ -2770,7 +2771,7 @@ InitDrawingSizes(BoardSize boardSize, int flags)
     pieceBitmap[0][WhiteGnu] = DoLoadBitmap(hInst, "gnu", squareSize, "s");\r
     pieceBitmap[1][WhiteGnu] = DoLoadBitmap(hInst, "gnu", squareSize, "o");\r
     pieceBitmap[2][WhiteGnu] = DoLoadBitmap(hInst, "gnu", squareSize, "w");\r
-    if(gameInfo.variant == VariantDuck) { char name[20]; sprintf(name, " ducky%d", squareSize); ducky = LoadBitmap(hInst, name); }\r
+    if(gameInfo.variant == VariantDuck) { char name[20]; sprintf(name, "ducky%d", squareSize); ducky = LoadBitmap(hInst, name); }\r
 \r
     if(gameInfo.variant == VariantShogi && BOARD_HEIGHT != 7) { /* promoted Gold representations (but not in Tori!)*/\r
       pieceBitmap[0][WhiteCannon] = DoLoadBitmap(hInst, "wp", squareSize, "s");\r
@@ -3607,12 +3608,12 @@ DrawBoardOnDC(HDC hdc, Board board, HDC tmphdc)
       }\r
       if(column == BOARD_LEFT-1 ) /* left align */\r
             DisplayHoldingsCount(hdc, x, y, flipView, (int) board[row][column]);\r
-      else if( column == BOARD_RGHT) /* right align */\r
+      else if( column == BOARD_RGHT) /* right align */squareSize, \r
             DisplayHoldingsCount(hdc, x, y, !flipView, (int) board[row][column]);\r
       else if( piece == DarkSquare) {\r
             if(gameInfo.variant == VariantDuck && ducky) {\r
                  HBITMAP oldBitmap = SelectObject(tmphdc, ducky);\r
-                 BitBlt( hdc, x, y, squareSize, tmphdc, 0, 0, SRCPAINT );\r
+                 BitBlt( hdc, x, y, squareSize, squareSize, tmphdc, 0, 0, SRCPAINT );\r
                  SelectObject(tmphdc, oldBitmap);\r
             } else DisplayHoldingsCount(hdc, x, y, 0, 0);\r
       } else\r
@@ -5061,7 +5062,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                         appData.oldSaveStyle ? "pos" : "fen",\r
                         POSITION_FILT,\r
                         _("Save Position to File"), NULL, fileTitle, NULL);\r
-      SetCurrentDirectory(MSG_SIZ, dir);\r
+      SetCurrentDirectory(dir);\r
       if (f != NULL) {\r
        SavePosition(f, 0, "");\r
       }\r
@@ -7900,6 +7901,7 @@ DoWriteFile(HANDLE hFile, char *buf, int count, DWORD *outCount,
 \r
   }\r
   return err;\r
+\r
 }\r
 \r
 /* [AS] If input is line by line and a line exceed the buffer size, force an error */\r