VariantClass currentlyInitializedVariant; /* [HGM] variantswitch */
int lastIndex = 0; /* [HGM] autoinc: last game/position used in match mode */
int opponentKibitzes;
+int lastSavedGame; /* [HGM] save: ID of game */
/* States for ics_getting_history */
#define H_FALSE 0
}
+// [HGM] save: calculate checksum of game to make games easily identifiable
+int StringCheckSum(char *s)
+{
+ int i = 0;
+ if(s==NULL) return 0;
+ while(*s) i = i*259 + *s++;
+ return i;
+}
+
+int GameCheckSum()
+{
+ int i, sum=0;
+ for(i=backwardMostMove; i<forwardMostMove; i++) {
+ sum += pvInfoList[i].depth;
+ sum += StringCheckSum(parseList[i]);
+ sum += StringCheckSum(commentList[i]);
+ sum *= 261;
+ }
+ if(i>1 && sum==0) sum++; // make sure never zero for non-empty game
+ return sum + StringCheckSum(commentList[i]);
+} // end of save patch
+
void
GameEnds(result, resultDetails, whosays)
ChessMove result;
DisplayMove(currentMove - 1);
if (forwardMostMove != 0) {
- if (gameMode != PlayFromGameFile && gameMode != EditGame) {
+ if (gameMode != PlayFromGameFile && gameMode != EditGame
+ && lastSavedGame != GameCheckSum() // [HGM] save: suppress duplicates
+ ) {
if (*appData.saveGameFile != NULLCHAR) {
SaveGameToFile(appData.saveGameFile, TRUE);
} else if (appData.autoSaveGames) {
DisplayTitle("");
DisplayMessage("", "");
HistorySet(parseList, backwardMostMove, forwardMostMove, currentMove-1);
+ lastSavedGame = 0; // [HGM] save: make sure next game counts as unsaved
}
void
}
fclose(f);
+ lastSavedGame = GameCheckSum(); // [HGM] save: remember ID of last saved game to prevent double saving
return TRUE;
}
char *dummy2;
{
if (gameMode == EditPosition) EditPositionDone();
+ lastSavedGame = GameCheckSum(); // [HGM] save: remember ID of last saved game to prevent double saving
if (appData.oldSaveStyle)
return SaveGameOldStyle(f);
else
DrawPosition(FALSE, boards[currentMove]);
}
}
-}
+}
\ No newline at end of file