From ad3790c613d301fb6f234e78cb63a5a743bde0d6 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Fri, 28 Sep 2012 13:28:17 +0200 Subject: [PATCH] Allow Analyze Game to auto-step through entire game file If the game index is set to auto-increment (-lgi -1), the Analyze Game function will automatically load the next game of the current game file (starting to auto-play/annotate that) when the end of the current game is reached. This flushes the annotated game if auto-saving was set, so that eventually all games in the file will be annotatd and saved. The game index is automatically set to auto-increment when we load a file while in Analyze Game mode, but switching this mode on while a game is already loaded will stop at the end of that game, as usual (if -lgi was not explicitly set). --- backend.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/backend.c b/backend.c index 6442bea..52fb515 100644 --- a/backend.c +++ b/backend.c @@ -270,6 +270,7 @@ char lastMsg[MSG_SIZ]; ChessSquare pieceSweep = EmptySquare; ChessSquare promoSweep = EmptySquare, defaultPromoChoice; int promoDefaultAltered; +int keepInfo = 0; /* [HGM] to protect PGN tags in auto-step game analysis */ /* States for ics_getting_history */ #define H_FALSE 0 @@ -11007,6 +11008,11 @@ AutoPlayGameLoop () } } +void +AnalyzeNextGame() +{ + ReloadGame(1); // next game +} int AutoPlayOneMove () @@ -11028,7 +11034,14 @@ AutoPlayOneMove () } if (currentMove >= forwardMostMove) { - if(gameMode == AnalyzeFile) { ExitAnalyzeMode(); SendToProgram("force\n", &first); } + if(gameMode == AnalyzeFile) { + if(appData.loadGameIndex == -1) { + GameEnds(EndOfFile, NULL, GE_FILE); + ScheduleDelayedEvent(AnalyzeNextGame, 10); + } else { + ExitAnalyzeMode(); SendToProgram("force\n", &first); + } + } // gameMode = EndOfGame; // ModeHighlight(); @@ -11872,6 +11885,9 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList) gn = 1; } else { + if(gameMode == AnalyzeFile && appData.loadGameIndex == -1) + appData.loadGameIndex = 0; // [HGM] suppress error message if we reach file end after auto-stepping analysis + else DisplayError(_("Game number out of range"), 0); return FALSE; } @@ -12265,7 +12281,10 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList) if (oldGameMode == AnalyzeFile || oldGameMode == AnalyzeMode) { + appData.loadGameIndex = -1; // [HGM] order auto-stepping through games + keepInfo = 1; AnalyzeFileEvent(); + keepInfo = 0; } if (!matchMode && pos > 0) { @@ -15053,6 +15072,8 @@ SetGameInfo () ChessMove r = GameUnfinished; char *p = NULL; + if(keepInfo) return; + if(gameMode == EditGame) { // [HGM] vari: do not erase result on EditGame r = gameInfo.result; p = gameInfo.resultDetails; -- 1.7.0.4