Fix Edit Position with engine-defined variant
authorH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 26 Jan 2018 13:01:19 +0000 (14:01 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 26 Jan 2018 13:01:19 +0000 (14:01 +0100)
Submitting a new position starts a new game, but the position would be
set up before the engine had the time to reply to the 'variant' command
wit a 'setup'. As a consequence WinBoard would be unaware of the correct
starting position, with as a consequence that Pawns might not be considered
virgin for their Betza 'i' moves.
 Now even late reception of a 'setup' command from the engine when
startedFromSetupPosition is true will cause initialPosition to be
initialized. The assumption is that XBoard was already switched to the
variant before, so that the 'setup' command is not needed for defining the
pieceToCharTable used to interpret the FEN that set up the position.

backend.c

index c531656..e0f60b4 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -9257,6 +9257,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
           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];
+      Board tmp;
       if(appData.icsActive || forwardMostMove != 0 || cps != &first) return;
       *buf = NULLCHAR;
       if(sscanf(message, "setup (%s", buf) == 1) {
@@ -9277,10 +9278,11 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
           startedFromSetupPosition = FALSE;
         }
       }
-      if(startedFromSetupPosition) return;
+      CopyBoard(tmp, boards[0]);
       ParseFEN(boards[0], &dummy, message+s, FALSE);
-      DrawPosition(TRUE, boards[0]);
       CopyBoard(initialPosition, boards[0]);
+      if(startedFromSetupPosition) { CopyBoard(boards[0], tmp); return; }
+      DrawPosition(TRUE, boards[0]);
       startedFromSetupPosition = TRUE;
       return;
     }