Game Development

Nature Simulation Systems for Emergent Gameplay

In the article "Nature Simulation Systems for Emergent Gameplay," Saga Barros explores the use of nature-inspired systems to enhance player agency and create complex, emergent gameplay in video games. The article delves into four key systems: Cellular Automata, Fractals, Genetics, and Flocking Systems. Each system is explained in terms of its principles, real-world applications, and how it can be leveraged in game development. The goal is to provide game developers with tools and insights to create richer, more interactive, and personalized gaming experiences.

Saga Barrios
June 27, 2024

Some people say agency is the defining attribute of video games as a language and as a medium. It’s what makes it stand out from other art and entertainment languages like film, TV, comics, and literature.

We can understand agency as the ability to act in a determinate environment and impact the surroundings.

So how do we use agency as a scope in game development? Ideally, by giving the player as many possibilities as we can, so they are able to interact with the environment in the most personalized and custom way possible. We can do that by giving the player a wide set of tools with very different uses, by creating complex NPC (enemy and non-enemy) AI, by using Nature Simulation Systems, among others.

Disclaimer: We understand this is not the only way to work with agency, (The Last of Us 2 does amazing things making you feel guilty for your actions while giving you very limited possibilities in terms of the outcome of those actions) but it’s an exceptionally useful tool for us to handle, both in the design and engineering sides of game development.

The idea of Nature Simulation Systems is not necessarily a new one, although there doesn’t seem to be a wide agreement of sorts to embrace these concepts under a single name. One popular source is The Nature of Code, the book written by processing YouTube star Daniel Shiffman. Most of what I’ll be talking about in this article can be accomplished following the book’s instructions.

Nature, as you might already know, works in infinitely unpredictable and emergent ways. So much that we might never “finish” studying it, even if we would be able to live forever. One of the aspects that interests us here is how a lot of times, simple behaviors can result in increasingly complex systems when interacting with other agents in a suitable environment. There might be thousands of different examples one can think of this principle, but there are some that have been researched and simulated in computers in several ways, for different purposes, and some of those are the ones we’ll tackle in this article.

Nature Simulation Systems

Cellular Automata

Cellular Automata (CA), at its core, might be the simplest complex system around. It is a system composed of individual elements that are called Cellular Automaton (or cell), which are as simple by themselves as a single bit.

A CA system consists of a grid where the cells “reside”. This grid can have any number of dimensions. We’ll think of a one-dimensional example right now to keep it simple.

Each cell has a state. The number of possible states can also vary in any number of possibilities we might think of. Again, we’ll keep it simple and imagine a cell with only two possible states (like a bit!).

Also, each cell has a neighborhood, which is basically a list of the cells near this one. Of course, this can also vary, for example setting the neighborhood to be the cells that fall inside a certain radio.

Finally, the cells in a CA we’ll have a ruleset that will dictate how their state will change over time according to their current state and their neighbors’ current state.

Now that we know the basic characteristics of how CAs work, we can look at how these rules can create complex behaviors. Wolfram Elementary CA is a pretty famous example that uses the simplest form of rules possible: a one-dimensional grid, two possible states, and only recognizes the immediately adjacent cells as neighbors. Using this starting point, we can now think of the possible rules we can give the cells. In this case there are exactly 256 possible rulesets.

Three rulesets of the Wolfram Elementary CA

If each “generation” is visually shown below the previous one we can see how different patterns arrive.

Example of some of the 256 rulesets of the Wolfram Elementary CA

Now that we know how a CA works, we can imagine how much complexity can arise by simply changing the number of dimensions, states or neighbors.

The CA principle is often used in computer science for a lot of use cases, like bacteria behavior simulation and biology simulations in general, even anthropologic simulations. It’s even used outside of computer science for stuff like knitting!

Now, how does this apply to video games? There are a lot of ways CA can be used in gamedev, one of the most popular ones can be procedural generation (terrain, agents, treasure). There are even games that are almost completely a CA system (see Dwarf Fortress).

Terraria’s procedurally generated terrain

Fractals

Probably the most popular one, fractals are often used to create computer-generated images. We can see it in trippy electronic parties’ visuals, movies’ VFX, and digital art. Remember the visuals when playing music on WinAmp or the old Windows Video Player? Those where it seems we’re zooming in on abstract shapes endlessly but the shape always kind of looks the same from our point of view even though we zoomed in forever. That is a fractal.

So what does a shape need to be considered a fractal (and how can we create one)? First of all, fractals are -as mentioned in the example in the paragraph above- self similar. A smaller portion of the shape still looks like the bigger portion.

Fractal pattern in a cauliflower

Another key aspect of a fractal is recursion, which means that the set of rules or algorithms we use to create a fractal at some point contains a reference to that same set of rules. One can imagine right away that with recursion we can create a function that does not explicitly show repetition but can create infinite outputs out of a finite statement. Of course, in programming, for that, we need an exit condition, a way to stop the recursion.

int fac1(int n) {if (n <= 0)return 1;elsereturn fac1(n-1)*n;}

A simple example of a recursive function.

Finally, one last aspect we need to take into consideration about fractals is that they don’t need to be “perfect”. Fractals come in two categories. A fractal whose smaller portion looks perfectly equal to its greater portion is known as deterministic; while a fractal where we don’t see exactly the same at different scales, but there’s a general quality of the shape’s structure and pattern is known as stochastic and it’s the one we’ll most likely see in nature.

We can think of sea waves as stochastic fractals

Now we know what we need to create fractals, how do we use this in video games? Once again, one of our main use cases is procedural generation: probably every tree generator out there uses fractals to create the trees. They are also often used for VFX but usually in a non-interactive way (like a FMV scene of a character traveling to a different dimension and such). The truth is that, while fractals are a potentially huge tool, it can be very tricky to actually implement (both in the engineering and design sides): being able to create fractal interactive spaces or gadgets that don’t break or consume all our memory and, at the same time, are actually fun and rich to interact with can be an almost herculean task. Nonetheless, there are devs out there slaying the Nine-Headed Hydra: the trippy shooter Spaceflux and the Super Monkey Ball-esque racing game Marble Marcher are some pretty interesting examples to go check on.

Genetics

Genetics might be at the same time both the trickier system in this article (programming-wise) and the most used right now in computer science, with the rise of AI.

Genetic algorithms are models of simulations of evolution in software. Evolution in the terms we understand is based on the core principles described by Charles Darwin in The Origin of Species: over a number of generations, a population of entities/elements/objects evolve according to the principles of natural selection. Survival of the fittest and all that.

Let’s say we have a given problem, like “find the optimal route to go from point A to B”, and we have certain conditions to recognize a given route as optimal (short, safe, fun, etc.). Each of these entities can be seen as a possible solution to this problem.

We first create an initial generation of solutions, with a certain degree of variation on each of its parameters. Then there’s a stage of selection where we choose the best entities of the batch so they can “mate” to create a new generation. We do the selection by calculating the fitness of the entities, as to check who will be the fittest to survive. A disclaimer to be signed here is that we might instinctively think that we need two entities to create a new batch, like how it happens with animals, but here we can choose any number of survivors to mate (one, three, ten).

With the “parents” selected comes the reproduction stage, where we mix their genetic information to create the children. We do this by first making a crossover of the data, which can be performed in any way we might want (use the first half of one parent’s data and the second half of the other, mix it randomly, etc) and then adding a certain degree of artificial mutation to the mix. Why? Because there always might be a certain part of that “optimal” answer we are looking for that is not present in any of the selected entities, so randomizing a small fraction of that data can help us get that.

The exit state of our algorithm will then be to get an optimal solution, or in some cases the closest we can get to optimal by a given rate.

So how about video games? A quite popular (and literal) approximation to genetics in video games is the game Spore developed by Will Wright’s studio Maxis (probably the kings of emergent gameplay during the 90’s and 00’s). Besides a few examples like that, there aren’t a whole lot of games where we can see genetics in action; but it can be a useful tool during development nonetheless. AI training for enemies and NPCs in general can be done a lot faster and more elegantly with the use of genetic algorithms. We can even make the enemies learn throughout the game to exploit each individual player’s weaknesses in theory -EA allegedly did that with FIFA 22-.

2008 sim game Spore

Flocking Systems

The final system we’ll tackle in this article are Flocking Systems. Flocking systems are really useful for simulation large groups of simple agents that move through space. Flocks of birds, schools of fishes, swarms of bugs, herds in general. They are, at its core, complex systems: systems composed of many components that interact with each other. They are, as a whole, more than the sum of their parts. Usually, the individual components -the simple part of the complex whole- are agents with basic behaviors that, when interacting with a large number of pairs, can create complex and unpredictable results that blend between order and chaos.

The individual autonomous agent usually has three basic parameters (besides some basic stuff like move speed and rotation speed): separation tells the agent to avoid bumping into any of its pairs; alignment dictates the actual direction the agent wants to follow, which will be decided according to the general direction its neighboring pairs are taking; and cohesion which means that the agent will group with its neighbors. Each of these parameters also has a weight which basically gives us a priority order on how to mix them into one single desired speed and direction.

Flocking System example done in Processing

Simply messing around with these three basic parameters we can get lots of different behaviors for our system. Additionally, we can create stuff like a seek parameter and a fear parameter. The first one is to give the agents a final goal, besides their short-term goals of moving together. The second one can be used to make the agents avoid certain areas or objects in the environment. With these parameters, we can get a lot more control over our system when we don’t want the agents to wander aimlessly into the horizon.

So again, video games. Flocking systems usually create behaviors that are pretty to look at, although they are not usually super used in terms of gameplay. Probably every AAA out there uses flocking to simulate some group of animals or bugs that move in an ordered but emergent fashion. We at Azumo are currently working on a little video game project tentatively called Flock Hunt, where you get the role of an animal control employee in the town of Zumo, who has to capture a bunch of sick birds for your office to heal them. The birds as a group function as (you guessed it) a flocking system.

The birds use a fear parameter to avoid bumping into the limits the designer creates, so they won’t go too far away. Also, we have different species of birds, and each species has its own weight to their alignment, separation, and cohesion parameters (i.e. each species has a slightly different behavior). Mixing different species at the same level can create increasingly complex situations for the player to take into account. All of this by simply changing the value of some basic parameters.

Azumo’s Flock Hunt

Closing words

Of course, in this article, we merely scratched the surface of some nature simulation systems just to get an overview of what is possible in video games with these tools, the possibility space will potentially increase as you dig deeper. Emergence is one of the things gamers cherish the most (even though they might not even know it) so I hope this approximation to nature simulation systems will be helpful to create richer gaming experiences.

We are Azumo
and we get it

We understand the struggle of finding the right software development team to build your service or solution.

Since our founding in 2016 we have heard countless horror stories of the vanishing developer, the never-ending late night conference calls with the offshore dev team, and the mounting frustration of dealing with buggy code, missed deadlines and poor communication. We built Azumo to solve those problems and offer you more. We deliver well trained, senior developers, excited to work, communicate and build software together that will advance your business.

Want to see how we can deliver for you?

schedule my call

Benefits You Can Expect

Release software features faster and maintain apps with Azumo. Our developers are not freelancers and we are not a marketplace. We take pride in our work and seat dedicated Azumo engineers with you who take ownership of the project and create valuable solutions for you.

Industry Experts

Businesses across industries trust Azumo. Our expertise spans industries from healthcare, finance, retail, e-commerce, media, education, manufacturing and more.

Illustration of globe for technology nearshore software development outsourcing

Real-Time Collaboration

Enjoy seamless collaboration with our time zone-aligned developers. Collaborate, brainstorm, and share feedback easily during your working hours.

vCTO Solution Illustration

Boost Velocity

Increase your development speed. Scale your team up or down as you need with confidence, so you can meet deadlines and market demand without compromise.

Illustration of bullseye for technology nearshore software development outsourcing

Agile Approach

We adhere to strict project management principles that guarantee outstanding software development results.

Quality Code

Benefits from our commitment to quality. Our developers receive continuous training, so they can deliver top-notch code.

Flexible Models

Our engagement models allow you to tailor our services to your budget, so you get the most value for your investment.

Client Testimonials

Zynga

Azumo has been great to work with. Their team has impressed us with their professionalism and capacity. We have a mature and sophisticated tech stack, and they were able to jump in and rapidly make valuable contributions.

Zynga
Drew Heidgerken
Director of Engineering
Zaplabs

We worked with Azumo to help us staff up our custom software platform redevelopment efforts and they delivered everything we needed.

Zaplabs
James Wilson
President
Discovery Channel

The work was highly complicated and required a lot of planning, engineering, and customization. Their development knowledge is impressive.

Discovery Channel
Costa Constantinou
Senior Product Manager
Twitter

Azumo helped my team with the rapid development of a standalone app at Twitter and were incredibly thorough and detail oriented, resulting in a very solid product.

Twitter
Seth Harris
Senior Program Manager
Wine Enthusiast

Azumo's staff augmentation service has greatly expanded our digital custom publishing capabilities. Projects as diverse as Skills for Amazon Alexa to database-driven mobile apps are handled quickly, professionally and error free.

Wine Enthusiast Magazine
Greg Remillard
Executive Director
Zemax

So much of a successful Cloud development project is the listening. The Azumo team listens. They clearly understood the request and quickly provided solid answers.

Zemax
Matt Sutton
Head of Product

How it Works

schedule my call

Step 1: Schedule your call

Find a time convenient for you to discuss your needs and goals

Step 2: We review the details

We estimate the effort, design the team, and propose a solution for you to collaborate.

Step 3: Design, Build, Launch, Maintain

Seamlessly partner with us to confidently build software nearshore

We Deliver Every Sprint

Time Zone Aligned Developers

Our nearshore developers collaborate with you throughout your working day.

Experienced Engineers

We hire mid-career software development professionals and invest in them.

Transparent Communication

Good software is built on top of honest, english-always communication.

We Build Like Owners

We boost velocity by taking a problem solvers approach to software development.

You Get Consistent Results

Our internal quality assurance process ensures we push good working code.

Agile Project Management

We follow strict project management principles so we remain aligned to your goals