From f3aa0e4aa40a4a97632cb7d7bceffc171a1dc055 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Sun, 6 Nov 2022 19:22:35 +0100 Subject: [PATCH] Fix protocol move in Duck Chess 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 | 14 ++++++++++---- winboard/winboard.c | 10 ++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backend.c b/backend.c index c092efb..4161d35 100644 --- 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); diff --git a/winboard/winboard.c b/winboard/winboard.c index e152a9a..15526e2 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -382,6 +382,7 @@ LoadLanguageFile(char *name) } languageBuf[--i] = k; + } i++; } @@ -2770,7 +2771,7 @@ InitDrawingSizes(BoardSize boardSize, int flags) pieceBitmap[0][WhiteGnu] = DoLoadBitmap(hInst, "gnu", squareSize, "s"); pieceBitmap[1][WhiteGnu] = DoLoadBitmap(hInst, "gnu", squareSize, "o"); pieceBitmap[2][WhiteGnu] = DoLoadBitmap(hInst, "gnu", squareSize, "w"); - if(gameInfo.variant == VariantDuck) { char name[20]; sprintf(name, " ducky%d", squareSize); ducky = LoadBitmap(hInst, name); } + if(gameInfo.variant == VariantDuck) { char name[20]; sprintf(name, "ducky%d", squareSize); ducky = LoadBitmap(hInst, name); } if(gameInfo.variant == VariantShogi && BOARD_HEIGHT != 7) { /* promoted Gold representations (but not in Tori!)*/ pieceBitmap[0][WhiteCannon] = DoLoadBitmap(hInst, "wp", squareSize, "s"); @@ -3607,12 +3608,12 @@ DrawBoardOnDC(HDC hdc, Board board, HDC tmphdc) } if(column == BOARD_LEFT-1 ) /* left align */ DisplayHoldingsCount(hdc, x, y, flipView, (int) board[row][column]); - else if( column == BOARD_RGHT) /* right align */ + else if( column == BOARD_RGHT) /* right align */squareSize, DisplayHoldingsCount(hdc, x, y, !flipView, (int) board[row][column]); else if( piece == DarkSquare) { if(gameInfo.variant == VariantDuck && ducky) { HBITMAP oldBitmap = SelectObject(tmphdc, ducky); - BitBlt( hdc, x, y, squareSize, tmphdc, 0, 0, SRCPAINT ); + BitBlt( hdc, x, y, squareSize, squareSize, tmphdc, 0, 0, SRCPAINT ); SelectObject(tmphdc, oldBitmap); } else DisplayHoldingsCount(hdc, x, y, 0, 0); } else @@ -5061,7 +5062,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) appData.oldSaveStyle ? "pos" : "fen", POSITION_FILT, _("Save Position to File"), NULL, fileTitle, NULL); - SetCurrentDirectory(MSG_SIZ, dir); + SetCurrentDirectory(dir); if (f != NULL) { SavePosition(f, 0, ""); } @@ -7900,6 +7901,7 @@ DoWriteFile(HANDLE hFile, char *buf, int count, DWORD *outCount, } return err; + } /* [AS] If input is line by line and a line exceed the buffer size, force an error */ -- 1.7.0.4