Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2003:
[Freeciv-Dev] Re: (PR#4733) reloading a savegame should give identical r
Home

[Freeciv-Dev] Re: (PR#4733) reloading a savegame should give identical r

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#4733) reloading a savegame should give identical results
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Aug 2003 13:03:10 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Jason Short wrote:
> This is a substantial problem.  The main thing to avoid is any spurious
> recalculation that involves calls to myrand(), since this changes the
> random number ordering and leads to completely different games.

Per suggests that if all game saving were done _between_ turns (as 
opposed to during a turn) this would be much easier.

For command-line saves this is a problem.  The only solution, really, is 
to make a recording of the savegame at the beginning of the turn, so 
that it could be written out to disk on demand later in the turn. 
Unfortunately this is probably slow and error-prone.

The attached patch does this for the autogame.  There will still be 
differences in reloaded games, presumably because not all AI state is 
saved or correctly recalculated.

jason

? rc
? shuffled_players.diff
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.135
diff -u -r1.135 srv_main.c
--- server/srv_main.c   2003/08/09 15:34:19     1.135
+++ server/srv_main.c   2003/08/15 20:00:11
@@ -1429,6 +1429,15 @@
   lsend_packet_generic_empty(&game.game_connections, PACKET_FREEZE_HINT);
 
   while(server_state==RUN_GAME_STATE) {
+    /* Do auto-saves at the very beginning of the turn, so that a reloaded
+     * game should proceed identically to the original game.
+     * Post-increment so we don't count the first loop. */
+    if (save_counter >= game.save_nturns && game.save_nturns > 0) {
+      save_counter = 0;
+      save_game_auto();
+    }
+    save_counter++;
+    
     /* absolute beginning of a turn */
     freelog(LOG_DEBUG, "Begin turn");
     begin_turn();
@@ -1454,17 +1463,6 @@
     freelog(LOG_VERBOSE, "End/start-turn server/ai activities: %g seconds",
            read_timer_seconds(eot_timer));
 
-    /* Do auto-saves just before starting sniff_packets(), so that
-     * autosave happens effectively "at the same time" as manual
-     * saves, from the point of view of restarting and AI players.
-     * Post-increment so we don't count the first loop.
-     */
-    if(save_counter >= game.save_nturns && game.save_nturns>0) {
-      save_counter=0;
-      save_game_auto();
-    }
-    save_counter++;
-    
     freelog(LOG_DEBUG, "sniffingpackets");
     while (sniff_packets() == 1) {
       /* nothing */

[Prev in Thread] Current Thread [Next in Thread]