Wednesday, July 9, 2014

Procedural generation in video games: A great lesson in measurement and variability

It has now been a while since E3 2014, where by many accounts one game sort of stole the show.  That game is called 'No Man's Sky'.

If you want a quick rundown, check out this video:



The premise of No Man's Sky is captured well by one of the things mentioned by the developer in the above video.  The demonstration shows off a landscape and a bunch of creatures, and the developer notes that this whole scene isn't something they 'built', so to speak.  It is something the game (sure, the game that they built) built, and something that they found.

It is a very unique and potentially missed point that the developers themselves don't really know what might be on the next planet until they go there and discover it.  They know the parameters of the universe, but they can experience the exploration of everything (the core of the game) just as much as any player.

It is a point perhaps best captured by a simple statement:

With a powerful enough computer you can simulate the universe.

There's a lot more nested in that statement.  We could start talking about the Matrix or all of that sort of stuff and get into a discussion of if we're actually in a simulation of the universe right now, but that's not what I want to talk about today.  What I want to talk about is the underlying assumptions about variability that make this game (and many others) possible.  This game is clearly possible because we're watching video of it, right?

In fact, a lot of people are bringing up the point that many people consider a game like this impossible.

http://kotaku.com/how-a-seemingly-impossible-game-is-possible-1592820595

Let's walk through why it's not.

The term 'procedurally generated' is sort of a hot buzzword in gaming at the moment.  There are plenty of games that utilize this fairly new method of creating the worlds in which we can then game.

If you've never heard the term, the quick breakdown is that content is not generated by the game developer and then shipped to the customer.  The game developer instead creates a game engine that generates content based on sets of rules.  That game engine is what is sold to customers, and all the content is generated on the fly by the customer's machine before or as they play.

This idea has been around in some form, and to some degree, for some time.  For instance, Fisher Random Chess is more or less procedurally generated chess based on a few rules of standard placement (e.g. bishops must end up on opposite color squares, the king must end up between the rooks).  It was designed to try to nullify the decided advantage that comes from memorizing chess openings and instead give more of an advantage to the skill of reacting quickly and accurately to new situations.

Not surprisingly, a lot of people who are really good at regular chess seem to hate this idea of being placed in new situations where all their accumulated knowledge isn't particularly useful.

Anyway, to bring it back to video games, I have recently been playing a game called Starbound.  Similar to No Man's Sky, it produces a universe of random worlds which you can fly around and explore in your spaceship.

While No Man's Sky looks like this, though:



Starbound looks like this:



It's not to say that one is better or worse than the other, they're simply different takes on an idea.  Starbound is a lot of fun, and also hits in the nostalgia feels for those of us who grew up on 2D platformers.

I've also played a bunch of games like Rogue Legacy:



And, well, I've certainly played way too much FTL:



You may have played some of these games, you may have not.  The thing that links them all is the concept of procedural generation.  No single run of FTL is going to be like any other run of FTL (well, except for the fact that you are likely to lose).  No dungeon layout and set of character traits in Rogue Legacy are going to match up across one playthrough to the next.  I'm sure I've played other games utilizing procedural generation, but probably not as much as these three.

http://en.wikipedia.org/wiki/Procedural_generation#Games_with_procedural_levels

The only other game that comes to mind, and which you have almost certainly at least heard of, is Minecraft.



I'm not sure why I'm reluctant to put Minecraft into the same category as the above three (or four) games, but it is either because it doesn't fit well enough or because it just fits too well.  The world in Minecraft is procedurally generated by seed numbers and by some estimates can be explored to reveal somewhere from as little as two or as much as eight times the surface area of the earth.

Don't believe it?  Check out this guy who generated a mine cart track with his world and is at the moment (for a few more days at least) riding at 20m/s toward the end of the world.  How long will this take?  17 days, by current estimates.  Not 17 in-game days, 17 IRL 'Earth spins on its axis' days.

http://kotaku.com/itll-take-him-17-days-to-get-to-the-end-of-minecraft-1598772102

It's fairly beautiful to watch, and if you don't understand Minecraft it might be a good way to get a feel for the kind of exploration that pulls people into it.  I have watched the stream here and there.  Every once in a while I see something cool off in the distance and get what can only be described as a compulsion to explore it.  It is exploring something new, something that no one has ever explored before.  What's going to be over there?  Nobody knows.

Probably some cows and chickens, though, most likely.

Like cows and chickens, there are some parts of Minecraft that don't change.  Pigs are never purple, for instance.



To be fair, the enemies in Rogue Legacy aren't procedurally generated, nor are the weapons in FTL.  In Starbound, for contrast, both enemies and weapons are procedurally generated.  Perhaps I'm nit-picking.

If you checked out either of those links, though, you'll see that enemies (or weapons) in Starbound fall into some pretty basic categories.  For instance, there is a section on quadruped enemies, that include things that look like this:






It's very possible that I've never seen any of these enemies in my game of Starbound, however.  Each is generated on the fly from a few basic parts.  The wiki seems to think these parts (for quadruped enemies) are head, legs, body, and tail.

Already you might start to see some of how this is holding together.  There is an assumption that all of these quadruped enemies will have some sort of a head, for instance.  Here lies the tip of the iceberg on how all of this is possible.

The clip of No Man's Sky above has some things that look like dinosaurs.  It also has some things that look (roughly) like gazelle.  The generation of these creatures is random, but based on certain rules and algorithms.

For instance, creatures of a certain size or type might be required to have some number of legs not equal to zero.  At the same time, number of legs might be bound to even numbers, and we might not ever run into a species of three-legged gazelle.

Quadrupeds also need to have a torso, presumably, to have a place for their legs to attach.  At the moment they might also be bound by some rules about head and face, as well.  All of these things are built into the algorithms to generate the world (or universe).

At the heart of all of this is a (probably implicit and potentially unspoken) discussion about measurement.

The first step of measurement, and most critical cornerstone, is definition.

There is a definition of what an animal is, and what a plant is.  There is a definition of what makes a planet, and what makes the space between them.  Some things are variable, and others are not.  The No Man's Sky developers talk about the process in some of those articles.  They don't build animals, they build prototypes of animals.  They build things that look like animals and then decide which parts can vary and which parts are fixed.

A fully procedurally generated animal based on nothing but randomness might look something like this:



Not really too much like an animal, right?

In this there exists a crucial difference between randomness and randomness within boundary conditions.

The above image is randomness.  The above games are randomness within boundary conditions.

By defining what things are crucial for something to be a quadruped (four legs, torso, head), you can start to vary the things that are not crucial for something to be a quadruped (color, size, facial expression).

This is the real magic that is being done in all these games, and is the part that is seemingly going widely unrecognized.  People are having to sit down to define what characteristics of a thing are free to vary and which things are uncompromisingly critical and not free to vary.  This is a really cool exercise, and I think people are missing it.  

A planet in No Man's Sky has to be spherical to weakly ellipsoidal.  The planets you might find in a game like, say, Mario Galaxy, are not the kind of planets that would be procedurally generated by No Man's Sky algorithms.



Nothing against Mario Galaxy, I enjoyed it as a completely different type of game.  It does get me thinking, though, and thinking often leads to Googling, and Googling often leads to me finding crazy things I never would have expected to exist.

So, I'll leave you today with that idea of procedural generation, and the concept that the next big innovation in gaming might be a content-lite industry simply churning out the coolest simulations of the worlds we want to game in.

I'll leave you with one other thing, though, the product of my above Google search.  Think any games are immune to procedural generation?  Exhibit A to get that discussion properly started can be found in the link below: procedurally generated Mario Bros. levels.

http://eis-blog.ucsc.edu/2010/04/infinite-fun-mario/

Enjoy!

1 comment: