Sign in to follow this  
roos

Reproducible behavior / random numbers

Recommended Posts

Hi, I was reading one of the articles on gamasutra about reproducible game behavior, and the author said the following:
Quote:
When a game is reloaded it is clearly necessary to restore the random number generator so that it will generate the same sequence from that point as it did after the game was saved. A tempting solution would be to re-seed the random number generator whenever a save occurs, and save the seed as part of the saved game state. However, this is not a good approach, because it means that the act of saving the game will effectively change the game state, and we wish to be able to save and reload the game freely.
I didn't really understand this. Why do you need to re-seed when saving the game, and thus change the game state? This seems like it would be a bad idea. For example, if you were playing a slot machine game, you could save right before your turn, then if you lose, you load your game with a different random seed, so effectively you could win every round... Thanks, roos

Share this post


Link to post
Share on other sites
If your looking for reproducable sudorandom number generation you could try using semirandom sources on the computer to create a key value and then use that value, which would be saved locally, to seed the ISAAC sudorandom number generator.

Isaac

This way, you could always create a different game for different seeds but have the ability to debug a particular game with the knowledge of the initial seed.

g/l

Share this post


Link to post
Share on other sites
Quote:
Original post by roos
I didn't really understand this. Why do you need to re-seed when saving the game, and thus change the game state? This seems like it would be a bad idea. For example, if you were playing a slot machine game, you could save right before your turn, then if you lose, you load your game with a different random seed, so effectively you could win every round...


No, that's precisely what this solution is intended to prevent. You reseed as soon you save the game, store that new seed, but you don't continue playing with the old seed - you carry on with the new seed, exactly the same as if you loaded the saved game with the new seed.

I'm not sure I fully understand the author's objection to this though. It's could be a pain for certain things, like replays, as you'd have to keep a record of every reseeding (every time someone saves) but outside of that it seems a bit metaphysical.

Share this post


Link to post
Share on other sites
one could save, try something based on the PRG, and if it fails, load and immediately save again, until you got a "good" new seed withthe save game.

i think it would be better to save the number of calls made (x) on the original seed (y), so when loading the game you reseed with the one and only seed (y), and then call rand() x times.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sandman
Quote:
Original post by roos
I didn't really understand this. Why do you need to re-seed when saving the game, and thus change the game state? This seems like it would be a bad idea. For example, if you were playing a slot machine game, you could save right before your turn, then if you lose, you load your game with a different random seed, so effectively you could win every round...


No, that's precisely what this solution is intended to prevent. You reseed as soon you save the game, store that new seed, but you don't continue playing with the old seed - you carry on with the new seed, exactly the same as if you loaded the saved game with the new seed.


That's actually quite nifty; I've never thought about doing that as a method for keeping the state of the random number generator.

Quote:

I'm not sure I fully understand the author's objection to this though. It's could be a pain for certain things, like replays, as you'd have to keep a record of every reseeding (every time someone saves) but outside of that it seems a bit metaphysical.


I'm just not sure about the justification for ensuring that the random numbers generated are always the same after a save. I can see how this could help in a gambling simulation, but I've seen this implemented in RPGs and strategy games and the result always ends up a bit like this:

Trapper Zoid: attempt to fire rocket launcher at goblin
Critical Failure! Rocket launcher explodes!
Trapper Zoid is dead

Me: Damn, better reload...

Trapper Zoid: attempt to fire rocket launcher at goblin
Critical Failure! Rocket launcher explodes!
Trapper Zoid is dead

Me: Damn stupid random number seeding, better try that again...

Trapper Zoid: does a stupid futile dance to use up a random number
Trapper Zoid: attempt to fire rocket launcher at goblin
Critical Hit! Goblin dies



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this