This project has moved and is read-only. For the latest updates, please go here.

Should repeated runs of a simulation produce identical results

Topics: Developer Forum
Dec 4, 2007 at 9:26 AM

I just wanted to check a somewhat criticial assumption.

If I run the simulation multiple times, with the same initial state, and the same state changes, should I always end up with the same result.

(I have just noticed some odd behaviour in my replays, it will probably be my replay handling code failing to set everything up nicely)

Thanks muchly

ps... Once I have got this and a couple of other bits sorted, I will be able to release a test version of my game!
Dec 4, 2007 at 2:08 PM
I don't think you will always get the same results. The reason I'm thinking of (correct me if I'm wrong, someone) is that the accuracy of the numerical integration techniques in the physics engine depend on how frequently it is updated. On different runs of the same simulation, background processes or other random factors will cause the update timings to vary somewhat. This will lead to slightly different results in the predicted behavior of objects, which for a relatively simple system, will quickly lead to wildly different end results.
Dec 4, 2007 at 2:43 PM

Make sure that you have a constant update time, such as 0.01, so that the math works out the same
Or, record your update times each frame so you can play back the update times. (two updates at 0.01 != one update at 0.02 seconds)

Or you may have to manually record the positions of each objects 30x a second or so to replay the sim (that wouldn't be too bad either).
Dec 4, 2007 at 2:43 PM
Edited Dec 4, 2007 at 2:43 PM
Whoops accidental double post my bad
Dec 4, 2007 at 5:39 PM
Edited Dec 4, 2007 at 5:41 PM
Is this for playback purposes? If so, yoiu might consider just tracking the position and orientation of each body every loop. Then your playback would just run thru this list every timestep.. Playback wouldn't need the physics engine at all. We did this for a truck driving simulator we made a while back.
Dec 5, 2007 at 3:12 PM
Edited Dec 5, 2007 at 3:50 PM
I have fixed the problem. (it was a somewhat silly thing to do with objects altering shared state, that happened to be more noticable during replay) (EDIT-the problem was in my code, not farseer)

My game is turn based, so the current state can be reached by having a start state, and then replaying a series of orders.
(every 5 seconds, a new order is applied, which affects the motion of the units).

This is used both for replays and also internet multiplayer. When you sign into a multiplayer game, it replays the game upto the current point. The player can then submit their order.

I just need to do a bit more tweaking, and then finally I will be able to release the first version that uses farseer!