From: H.G. Muller Date: Sun, 10 Apr 2011 18:32:57 +0000 (+0200) Subject: Fix use of game/position file in first match game X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=commitdiff_plain;h=4a8d41d0be4291df44a78bbf346c841a8710799c Fix use of game/position file in first match game When a match was started from the menu, it was not paying attention to game and position files. (Later games were.) The code that handled this in the initialization when a match is started through the command line was made into a routine MatchEvent, which can be called from the menu proc too. --- diff --git a/backend.c b/backend.c index 3f36345..c1ea28a 100644 --- a/backend.c +++ b/backend.c @@ -1176,6 +1176,40 @@ InitBackEnd2() } void +MatchEvent(int mode) +{ // [HGM] moved out of InitBackend3, to make it callable when match starts through menu + /* Set up machine vs. machine match */ + if (appData.noChessProgram) { + DisplayFatalError(_("Can't have a match with no chess programs"), + 0, 2); + return; + } + matchMode = mode; + matchGame = 1; + if (*appData.loadGameFile != NULLCHAR) { + int index = appData.loadGameIndex; // [HGM] autoinc + if(index<0) lastIndex = index = 1; + if (!LoadGameFromFile(appData.loadGameFile, + index, + appData.loadGameFile, FALSE)) { + DisplayFatalError(_("Bad game file"), 0, 1); + return; + } + } else if (*appData.loadPositionFile != NULLCHAR) { + int index = appData.loadPositionIndex; // [HGM] autoinc + if(index<0) lastIndex = index = 1; + if (!LoadPositionFromFile(appData.loadPositionFile, + index, + appData.loadPositionFile)) { + DisplayFatalError(_("Bad position file"), 0, 1); + return; + } + } + first.matchWins = second.matchWins = 0; // [HGM] match: needed in later matches + TwoMachinesEvent(); +} + +void InitBackEnd3 P((void)) { GameMode initialMode; @@ -1261,34 +1295,7 @@ InitBackEnd3 P((void)) } if (appData.matchMode) { - /* Set up machine vs. machine match */ - if (appData.noChessProgram) { - DisplayFatalError(_("Can't have a match with no chess programs"), - 0, 2); - return; - } - matchMode = TRUE; - matchGame = 1; - if (*appData.loadGameFile != NULLCHAR) { - int index = appData.loadGameIndex; // [HGM] autoinc - if(index<0) lastIndex = index = 1; - if (!LoadGameFromFile(appData.loadGameFile, - index, - appData.loadGameFile, FALSE)) { - DisplayFatalError(_("Bad game file"), 0, 1); - return; - } - } else if (*appData.loadPositionFile != NULLCHAR) { - int index = appData.loadPositionIndex; // [HGM] autoinc - if(index<0) lastIndex = index = 1; - if (!LoadPositionFromFile(appData.loadPositionFile, - index, - appData.loadPositionFile)) { - DisplayFatalError(_("Bad position file"), 0, 1); - return; - } - } - TwoMachinesEvent(); + MatchEvent(TRUE); } else if (*appData.cmailGameName != NULLCHAR) { /* Set up cmail mode */ ReloadCmailMsgEvent(TRUE); diff --git a/backend.h b/backend.h index 419a1b1..74d2a64 100644 --- a/backend.h +++ b/backend.h @@ -205,6 +205,7 @@ void GetMoveListEvent P((void)); void ExitAnalyzeMode P((void)); void AnalyzeModeEvent P((void)); void AnalyzeFileEvent P((void)); +void MatchEvent P((int mode)); void InitPosition P((int redraw)); void NewSettingEvent P((int option, int *feature, char *command, int value)); int WaitForSecond P((DelayedEventCallback x)); diff --git a/winboard/winboard.c b/winboard/winboard.c index a1fe6ed..ea7c7a7 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -4847,10 +4847,9 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if(gameMode != BeginningOfGame) { // allow menu item to remain enabled for better mode highligting DisplayError(_("You can only start a match from the initial position."), 0); break; } - matchMode = 2;// distinguish from command-line-triggered case (matchMode=1) - appData.matchGames = appData.defaultMatchGames; - matchGame = 1; - first.matchWins = second.matchWins = 0; + appData.matchGames = appData.defaultMatchGames; + MatchEvent(2); // distinguish from command-line-triggered case (matchMode=1) + break; case IDM_TwoMachines: TwoMachinesEvent(); diff --git a/xboard.c b/xboard.c index 5b0d6b2..e9a4dc2 100644 --- a/xboard.c +++ b/xboard.c @@ -5800,11 +5800,8 @@ void MatchProc(w, event, prms, nprms) Cardinal *nprms; { if(gameMode != BeginningOfGame) { DisplayError(_("You can only start a match from the initial position."), 0); return; } - matchMode = 2; // This is back-end, really - appData.matchGames = appData.defaultMatchGames; - matchGame = 1; - first.matchWins = second.matchWins = 0; - TwoMachinesEvent(); + appData.matchGames = appData.defaultMatchGames; + MatchEvent(2); } void IcsClientProc(w, event, prms, nprms)