• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Hawkblood

Reversing a procedural generation

31 posts in this topic

Procedurally generated data has a random seed and random values generated by the process. Here is an example of what I mean:

You have a row of windows you want to either be broken or unbroken. You set you seed and loop through the "windows" randomly assigning "broken" or "unbroken" to each according to the output of the random number generator.

This is simple and straight forward......

 

What if I wanted to do that in reverse? If I started with all the windows "unbroken" and I throw rocks randomly and broke a few of them. I would like to reverse the process until I get THE random seed that would result in generating the windows into that state.

 

I'm sure it CAN be done, but how?

 

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!

0

Share this post


Link to post
Share on other sites

If I have a random seed of 12345 and with the process, the windows generate:

1,0,1,1,0,0,0,0

where 1=="broken" and 0=="unbroken"

 

Then every time I go to generate the windows with seed 12345 it will look exactly the same.

 

If I break a window:

1,0,1,1,0,1,0,0 then the seed 12345 won't generate this result.

 

There IS some seed that will generate 1,0,1,1,0,1,0,0..... I want to go from the result to the seed. It's not magic, it's logic I am not fully aware of.

0

Share this post


Link to post
Share on other sites

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.

-2

Share this post


Link to post
Share on other sites


You can design a PRNG that is easily reversible, by using just about any private-key cryptographic method (any block cipher would do).

Now that's positive thinking!

 

 

I thank you all for responding. After serious consideration, I think you may be right about one thing: the random number generator wouldn't have calculations that would repeat numbers. This means even if I had some linear values, I couldn't have all 0's or all 1's or any number. Otherwise it wouldn't be a PRNG.... The game state should have the ability to have any valid state for all parameters.

 

+1 to all......

0

Share this post


Link to post
Share on other sites

How about this.

 

Generate random locations for all mineral deposits every time you visit a planet.

 

When a player visits a planet, typically they will land at a location and collect all the minerals within range of their ship.

 

So work out a region that has been mined out. Store the region in the save game.

 

Next time you come to the planet, generate all the minerals again and compare each one to the mined region.

 

When you leave the planet, rationalise the region list. I.E. if two regions are contiguous, merge them into a single region.

 

Eventually you will end up with a single region, the whole planet.

 

The save game storage would not be a major problem then, and a simple point / region intersection test will not slow down the game very much.

1

Share this post


Link to post
Share on other sites

Yet another example is MineCraft. The world is generated by a 32-bit seed, yet it is infinitely large (theoretically). Obviously, you can't reverse that back into a seed, as explained above.

 

I would like to point out that early versions of MineCraft used to save the differences between the original world generated by the seed and the modified world edited by the player. Alas, the longer the world existed and the more you mined, the larger the save-files became and the longer it took to apply the differences whenever you loaded the world.

 

I recommend saving absolute states and not relative states. You can optimize it in many ways, one way is only saving the sub-sections that are different than what was generated by the seed.

1

Share this post


Link to post
Share on other sites


At this point it's probably obvious - there is no encoding that will work like you want it to

That's correct.....

 

To everyone: I've moved away from the idea of using a seed as a save state.

 

Perhaps I should start a new post on saving the state of a galactic sized game.....

Any ideas on minimizing the save game size for really huge games?

1

Share this post


Link to post
Share on other sites

That sounds interesting. How about storing save data as data for an image like .png? The data would look like a picture (noise), but it would utilize the image's compression..... Don't know if that's what you were getting to, but it made me think of it anyway.

 

Some values will be actual bites and some will be stored/read as bites but actually have 8 yes/no values..... Sounds like a good way to encrypt it too-- don't know if anyone is using this method.

0

Share this post


Link to post
Share on other sites


How about storing save data as data for an image like .png? The data would look like a picture (noise), but it would utilize the image's compression..... Don't know if that's what you were getting to, but it made me think of it anyway.

 

Yeah, that might make sense if you were using a library that had png support and for some reason weren't able to use some other 3rd party compression library.

 

I don't know the details of png compression, but I wouldn't be surprised if it made some assumptions about what a typical image looks like (e.g. smooth gradients from pixel to pixel, etc...). Basically, it assumes the data is an image, and will probably compress that better than arbitrary data.

 

The point being, if you know something about your data, you can probably choose a compression scheme that will work better with it.

0

Share this post


Link to post
Share on other sites

I don't know a lot about data compression. I've never written anything that used it. Image files are compressed on the disk (except .bmp). I was simply implying I could use something that already had support through DirectX.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

2

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  
Followers 0