• Create Account

## Reversing a procedural generation

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

31 replies to this topic

### #21Álvaro  Members

20266
Like
3Likes
Like

Posted 07 March 2014 - 09:11 PM

You can also use a more straight-forward compression library, without the hack of going through an image. Start with something like zlib.

### #22jbadams  Senior Staff

24739
Like
0Likes
Like

Posted 07 March 2014 - 09:11 PM

You certainly can store your data in an image format, and may see some benefit from that format's compression -- because image formats are designed with images in mind, your non-image data may not get an optimal benefit from that compression -- you could get better compression with something designed specifically for the type of data you're storing.

### #23JTippetts  Moderators

12317
Like
2Likes
Like

Posted 08 March 2014 - 12:12 AM

Voxel world chunks do tend to end up very image-like, though, enough so that schemes such as RLE can achieve pretty significant compression. The caveat, of course, is that the more types of blocks you include, and the more widespread and scattered the types are throughout the world, the less effective RLE will be. You wouldn't want to actually use an image compression library (they're optimized for the 2D case, usually) but you can look to them for ideas.

### #24Hawkblood  Members

954
Like
0Likes
Like

Posted 08 March 2014 - 08:22 AM

Álvaro, the zlib link takes me to the first post in this thread

### #25FLeBlanc  Members

3133
Like
0Likes
Like

Posted 08 March 2014 - 09:13 AM

Álvaro, the zlib link takes me to the first post in this thread

Just google zlib. It's pretty well-known.

### #26aregee  Members

1072
Like
2Likes
Like

Posted 08 March 2014 - 09:36 AM

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...

### #27wodinoneeye  Members

1669
Like
0Likes
Like

Posted 08 March 2014 - 10:13 AM

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)

--------------------------------------------Ratings are Opinion, not Fact

### #28Servant of the Lord  Members

33539
Like
0Likes
Like

Posted 08 March 2014 - 12:56 PM

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, 08 March 2014 - 12:58 PM.

It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

### #29Hawkblood  Members

954
Like
0Likes
Like

Posted 11 March 2014 - 08:57 AM

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.....

### #30Lemunde  Members

128
Like
0Likes
Like

Posted 12 March 2014 - 04:17 PM

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.

### #31Buckeye  GDNet+

10739
Like
1Likes
Like

Posted 12 March 2014 - 06:27 PM

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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

### #32Aardvajk  Members

12280
Like
0Likes
Like

Posted 13 March 2014 - 03:28 AM

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, 13 March 2014 - 03:30 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.