From f9704573586c2aa2f57643c76f5b7f2780643c44 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Sun, 15 Dec 2019 21:59:43 +0100 Subject: [PATCH] Support preludes in human-engine games In an engine-defined variant the engine can now show several boards at the start of the game by sending those to the GUI in a 'setup' command, by letting all non-final 'setup' commands specify the (newly introduced) parent variant 'prelude'. These board are intended as 'graphical menus', from which the user can select a piece or square by clicking on it. The 'lift' command of the highlight protocol can be used to relay such clicks to the engine, and prompt it for the next 'setup' command. --- backend.c | 9 +++++++-- common.h | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend.c b/backend.c index f2dede6..02144c5 100644 --- a/backend.c +++ b/backend.c @@ -8919,7 +8919,6 @@ HandleMachineMove (char *message, ChessProgramState *cps) static char firstLeg[20], legs; char machineMove[MSG_SIZ], buf1[MSG_SIZ*10], buf2[MSG_SIZ]; char realname[MSG_SIZ]; - int fromX, fromY, toX, toY; ChessMove moveType; char promoChar, roar; char *p, *pv=buf1; @@ -8978,6 +8977,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if ((sscanf(message, "%s %s %s", buf1, buf2, machineMove) == 3 && strcmp(buf2, "...") == 0) || (sscanf(message, "%s %s", buf1, machineMove) == 2 && strcmp(buf1, "move") == 0)) { + int fromX, fromY, toX, toY; if(pausing && !cps->pause) { // for pausing engine that does not support 'pause', we stash its move for processing when we resume. if(appData.debugMode) fprintf(debugFP, "pause %s engine after move\n", cps->which); safeStrCpy(stashedInputMove, message, MSG_SIZ); @@ -9320,6 +9320,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if (!strncmp(message, "setup ", 6) && (!appData.testLegality || gameInfo.variant == VariantFairy || gameInfo.variant == VariantUnknown || + gameInfo.variant == VariantPrelude || NonStandardBoardSize(gameInfo.variant, gameInfo.boardWidth, gameInfo.boardHeight, gameInfo.holdingsSize)) ) { // [HGM] allow first engine to define opening position int dummy, w, h, hand, s=6; char buf[MSG_SIZ], varName[MSG_SIZ]; @@ -9345,12 +9346,13 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h startedFromSetupPosition = FALSE; } } + fromX = fromY = -1; CopyBoard(tmp, boards[0]); ParseFEN(boards[0], &dummy, message+s, FALSE); CopyBoard(initialPosition, boards[0]); if(startedFromSetupPosition) { CopyBoard(boards[0], tmp); return; } DrawPosition(TRUE, boards[0]); - startedFromSetupPosition = TRUE; + if(gameInfo.variant != VariantPrelude) startedFromSetupPosition = TRUE; return; } if(sscanf(message, "piece %s %s", buf2, buf1) == 2) { @@ -9688,6 +9690,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h * Look for hint output */ if (sscanf(message, "Hint: %s", buf1) == 1) { + int fromX, fromY, toX, toY; if (cps == &first && hintRequested) { hintRequested = FALSE; if (ParseOneMove(buf1, forwardMostMove, &moveType, @@ -18768,6 +18771,8 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen, Boolean autoSize) #endif } else if (*p == '*') { board[i][(j++)+gameInfo.holdingsWidth] = DarkSquare; p++; + } else if(*p == '0') { + p++; board[i][(j++) + gameInfo.holdingsWidth] = EmptySquare; } else if (isdigit(*p)) { emptycount = *p++ - '0'; while(isdigit(*p)) emptycount = 10*emptycount + *p++ - '0'; /* [HGM] allow > 9 */ diff --git a/common.h b/common.h index 55daf29..ddaf0e3 100644 --- a/common.h +++ b/common.h @@ -414,6 +414,7 @@ typedef enum { VariantASEAN, VariantLion, VariantChuChess, + VariantPrelude, VariantUnknown /* Catchall for other unknown variants */ } VariantClass; @@ -464,6 +465,7 @@ typedef enum { "asean",\ "lion",\ "elven",\ + "prelude", \ "unknown" \ } -- 1.7.0.4