Trending
Opinion: How will Project 2025 impact game developers?
The Heritage Foundation's manifesto for the possible next administration could do great harm to many, including large portions of the game development community.
Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs or learn how to Submit Your Own Blog Post
Using procedural generation to create living populations where player interaction determines their evolution.
Hey!
You probably skipped my first article about procedural generation, it's just an introduction, but you can read it here.
Today we're going to design a game which uses procedural generation in order to create meaningful player interaction, each article will feature a different example but I encourage you to use this resources to come up with your own implementations.
What we are going to do is design a turn-based game about hunting squirrels, but player interaction will affect the population of squirrels and how they evolve.
Now, without further delay, let's get to it!
We already talked about this algorithm on the introduction, it's quite easy to understand so it should be a good starting point for our game about hunting squirrels. As you know this "game" requires just an initial input, once we enter a grid/array(which represents a population) the algorithm "evolves" the data. To achieve that it uses four simple rules.
1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.
2. Any live cell with two or three live neighbours lives on to the next generation.
3. Any live cell with more than three live neighbours dies, as if by overcrowding.
4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
(these rules can be found here, or you can check out this online example)
This algorithm was conceived with cells in mind, but changing those four rules we can build a logical model for any kind of population.
Let's start imagining a simple game using "Conway's game of life".
Main Loop:
1) Our turn begins and we are shown the map(imagine something like in the pic below).
2) We choose one of the squirrels on the grid, the one we want to hunt.
3) We go through a mini-game, zelda-like battle or whatever we decide to determine if the player catches the squirrel.
a) if succeeds the chosen squirrel is removed from the map.
4) We run Conway's algorithm or a similar one to change the squirrel population.
Right now, we would have a game where the player has the power to shape the environment with his/her actions, let's take a look at how we can keep expanding this.
A cool way to add more complexity to our system would be if our squirrels were to evolve, I'm talking about natural selection. Natural selection acts when there's a quality that makes certain specimens "fitter to survive"; usually just those with that quality get to survive after a certain time.
Let's say we create a skill called "become invisible" and assign it to a few squirrels. Whenever the player tries to hunt a squirrel with the "become invisible" skill there's an additional chance it will get away. Doing so, those with the given skill are more likely to survive.
If we wanted to take this one step further, we could modify the forth step of our algorithm (the one about reproduction), adding two new "sub-rules":
a) If one of the parents has a given skill there's a 50% chance that the son will inherit it.
b) If both parents have a given skill there's a 85% chance that the son will inherit it.
We could set up a couple of skills, and try to make it look more realistic or more goofy(depending on what we're trying to achieve); just play around with the percentages and tweak them as you wish. You could even make squirrels that evolved into some kind of super-beings which fought back, there are hundreds of possibilities and it's up to you to choose which ones you want to explore.
Just with a basic implementation of this algorithm we can create a population of beings which reacts in a realistic way to player's actions, isn't that cool? And we can keep expanding this system, think about how much it can add to certain projects and how easy is to implement.
Perhaps you're making a game which can use this kind of procedural generation as its main feature, or maybe you're working on a project which could use these kind of things to add more complexity to its core (and there's a big chance you're working on something which wouldn't benefict from all this).
Keep thinking about procedural generation and how players interact with that type of content and try to come up with new implementations apart from map generation.
On the next article we won't be using "Conway's Game of Life", because we won't represent the life and death of the beings from a given population; so we'll talk about creating simple algorithms which adapt to what we want to make.
Let me know if you found this example confusing so I can try to fix that on the next article.
You can always find me on twitter or leave a comment here ^^
Read more about:
Featured BlogsYou May Also Like