Followers 0

# Reversing a procedural generation

## 31 posts in this topic

This is a SUPER SIMPLE random number generator:

int RNSeed=12345;
int randomnum(void){
RNSeed=abs(RNSeed*8786545643)%987654321;
return RNSeed;
}



With this initial seed, the first time it's called it results in 770159010, and the second time it results in 808599291.

This will happen EVERY time I start with 12345. The problem with reversing the calculation is the modulus of 987654321. Any seed value greater than that number will be some value that can't be found and therefore the previous seed us unknown. The solution would involve a random number generator that can be reversed-- I don't know how to make that (or if it can be made at all).

All of you are either think I don't know how random generators work or you are missing my point entirely.

The modulus IS the problem with the whole thing...  It means that you have lost some piece of the information.  You can go one way, you can even go back, BUT which of the UNLIMITED number of combinations is the right one?  Oh shoot!  You can't go back anyway...

2

##### Share on other sites

You will need a change patch log system to record all the subsequent changes for the direct and indirect object your procedural system will initially create.   The changes get added ontop of the procedurally generated initial data set whenever the area is rebuilt.

Some changes will be trivial and not need to be added to the patch log. (like bullet hole decals that the elves come and cleanup while player isnt watching)

Some changes may themselves be a 'procedural' generation (ie- a pattern a fire event spreads) and alot of 'sub' detail might be expressed in only a small amount of patch data.

Some changes may 'heal' over time (possibly since some player last saw it)  and be able to eventually be removed from the patch log (reverting the change back to the initial generation state)

Some dynamic changes created 'on the fly' to match a game situation  may be regrouped/nullified and regenerated newly when the area is rebuilt (matching a newer game situation).

Sometimes its possible (depending on game mechanics) to have catastrophic events periodicly overwhelm a location and wipe clean/consume  more than a few accumulated changes.

Many times a procedural generation cycle is based on more than just a random number and additional information used in activating its 'subprocedures'  will also have to be saved.

Sometimes there are 'in the area' significant objects whichhave been custom built (with too many variable attributes and states) and they have to be preserved with much greater detail saved.

Some world systems mutate (faction entities with spheres of influence move around, or seasonal variations) and areas can rebuild somewhat differently and any change log data may have to be checked/arbitrated if their are dependencies that cause them to mutate (or become irrelevant)

0

##### Share on other sites

This is a SUPER SIMPLE random number generator:
//...snip...

With this initial seed, the first time it's called it results in 770159010, and the second time it results in 808599291.
This will happen EVERY time I start with 12345. The problem with reversing the calculation is the modulus of 987654321. Any seed value greater than that number will be some value that can't be found and therefore the previous seed us unknown. The solution would involve a random number generator that can be reversed-- I don't know how to make that (or if it can be made at all).

Maybe I'm misunderstanding your original question, but I thought you were wanting to reverse player actions, and the effects of a complex system being fed with input data that comes from player actions.

Players aren't random number generators. You can't reverse player actions backwards, because you can't predict player actions forward. Instead, you save the result of those actions (the current game state) or save the actions themselves (like undo/redo frameworks), and re-apply them later.

"This process could be very useful in games that have a huge amount of "object states". Like a planet with mineral deposits. If the player collects a certain amount of them, it would be silly for the player to be able to come back to the planet and get those deposits again. And saving the state of each mineral deposit on every planet in every solar system would be crazy!"

Every object state is either generated solely by the simulation (procedural generation, later simulations that aren't affected by the game world, ...), prefabricated by the developer (manually made maps and game events, even some of the pre-written code and scripts), resulting from direct player actions (my character has blue eyes, I choose to mine this ore deposit), or affected by the complex simulation that is fed input from player actions, the passage of time, and other inputs (Enemy223 lobs a grenade in direction XYZ at Ally17 because the player told Ally17 to guard the mobile Entity452 which wandered in that direction because it needs sunlight for power and the weather simulation was cloudy at that point in time).

The isolated simulations (procedural generation, and self-contained non-influenced simulations like weather systems) can be re-simulated.
The prefabricated data must be reloaded, and cannot be generated (though theoretically you could use really good compression and pattern-matching to semi-generate parts of it, or maybe even to lossy-generate the whole imperfectly).
The player actions must be saved and re-applied or else the result of those actions (just the states you care about).
The complex whole simulation cannot be re-ran, unless the above three areas are also precisely reran (with recorded player actions, not just recorded results).

Edited by Servant of the Lord
0

##### Share on other sites
The main reason I started this post was to flesh out an idea to limit save game data for a huge scale game. I think I would like to have a "player profile" instead of a save game. I would create a seperate file for each solar system (or something like that) and save it with some standard convention within the player profile folder.....
0

##### Share on other sites

I think this might actually be possible without having to save a bunch of states for the window. What you need is some kind of "random.previous" function (as opposed to the traditional "random.next" function found in most languages). However as far as I know no programming language supports this. I would recommend programming your own PRNG from scratch for this task. Assign each window it's own random class and once it needs to be put back together just throw the PRNG in reverse.

0

##### Share on other sites

Be sure you carefully review the limitations of any compression algorithm you consider. Some compression schemes can be lossy (jpeg); some (lossless) preserve the original data.

1

##### Share on other sites

I think this might actually be possible without having to save a bunch of states for the window. What you need is some kind of "random.previous" function (as opposed to the traditional "random.next" function found in most languages). However as far as I know no programming language supports this. I would recommend programming your own PRNG from scratch for this task. Assign each window it's own random class and once it needs to be put back together just throw the PRNG in reverse.

Any where exactly are you planning to get the random number to reverse from, given the existing game state?

Plus of course any random number generator using a modulus can't have a previous method, since data is lost at each iteration.

Edited by Aardvajk
0

## Create an account

Register a new account