Nick's Auto-Evo Algorithm (Episode 1)

Interesting stuff.

So say you had only one limited food source in a patch, like iron maybe. Are you saying (assuming no predation) that even if you started with 100 species all but one would go extinct? And even if that one splits one half will just die off? I’m not sure that’s particularly ideal.

On the wikipedia page you linked to it says:

Competitive exclusion is predicted by mathematical and theoretical models such as the Lotka-Volterra models of competition. However, for poorly understood reasons, competitive exclusion is rarely observed in natural ecosystems, and many biological communities appear to violate Gause’s law. The best-known example is the so-called “paradox of the plankton”.[7] All plankton species live on a very limited number of resources, primarily solar energy and minerals dissolved in the water. According to the competitive exclusion principle, only a small number of plankton species should be able to coexist on these resources. Nevertheless, large numbers of plankton species coexist within small regions of open sea.

I imagine that we would want a bunch of different plankton-like species right all coexisting?

1 Like

Ah thanks I fixed the post.

Also very interesting, what are you planning to include in the fitness calculations? Let me know if I can offer any of the equations or functions I’ve created so far.

Yeah that’s a good question. At the moment, since the model is so simple the Competitive Exclusion Principle has a very exaggerated effect. However, there are several reasons that I can think of that ideally should limit the Competitive Exclusion Principle acting strongly and quickly to wipe out competing species. As we build the algorithm these should start to be introduced. Technically, if there was a species predating on Modelus or Propagatus, that would be a additional factor that would limit the Competitive Exclusion, but we’ll assume that does not apply:

  • The model currently lacks intraspecific competition, which means that an increasing number of Modelus Specius will always perfectly cooperate with each other and each will decide to target separate foods from the other members of Modelus Specius. Even in times of shortage members of Modelus willingly choose to take, for example, 75% of the energy they need so that all other members also can get 75% of the energy they need. We know that realistically this doesn’t happen, so I’ve been thinking about how to model intraspecific competition and I might have a solution for the upcoming sub-part.
  • The model only has one niche which both species are trying to fill. In more complex ecosystems, Predator 1 might hunt Prey A and Prey B, and Predator 2 might hunt Prey B and Prey C, and Predator 3 might hunt Prey C and Prey A. Predator 1 is the dominant competitor for hunting Prey A, as is 2 with B, and 3 with C. However, since they all have different overlaps for their niches and the prey they are most successful at hunting, competitive exclusion will have less of an effect to reduce their numbers.
  • The predators are highly efficient. At the moment there are very few things obstructing the predators from catching their prey. For example the predators do not have to deal with the constraints of perception and simply always know where the prey are. They also always catch the prey and do not have to fight in combat with the prey. I’m predicting that once we add in new features like perception and prey that run or fight back, predators will become much less efficient and Competitive Exclusion will develop a weaker effect. I might be wrong on this one though.
  • The exclusion of weaker species only actually kicks in in times of shortage. Notice how before the food shortage both populations were growing, even the weaker predator. The shortage is also pretty unrealistic, since during the shortage months all the food is being eaten, and then 2,000,000 units of food are appearing out of thin air to replenish the food stocks in the next month. Once we implement predation on proper species that have realistic population growth, I’m predicting it will change the amount of Competitive Exclusion we see.
  • The Competitive Exclusion Principle as it’s currently implemented only applies to consumers (aka heterotrophs). The equation so far is specifically for chases when one predator catches the prey before you do, and there’s only a limited number to catch. For something like plankton, if one plankton consumes solar energy it doesn’t take any solar energy away from another plankton. Instead here the competition becomes more about location, and being the plankton that is at the top of the ocean to receive the sunlight and physically block plankton below you who will receive less of the light. Also, I’m not sure if the plankton all feed on the same minerals or on different minerals, because if it’s the latter there might also be some differences in the niches they are trying to occupy, again leading to less Competitive Exclusion.

It’s not super high priority. Initially I’m just going to duplicate the random population changes.
But it would definitely be helpful to think about how this simulation could be fed with the data that is in Thrive.
Once the initial work is done it will be easier to see what kind of information is easily available and what’s difficult to get.

1 Like

Yeah that’s true. I’m excited to cover that topic when it comes up. Episode 2 and especially Episode 3 will be about how to take the information provided by Thrive and feed it into the simulation. Episode 1 is mostly about how to process that information into an outcome once you already have it.

It’s one of the most interesting things I have ever read about evolution!
I really like what are you doing.
I have only one question, do you think could be interesting to introduce parameter about growing up, when member of that species become 100% effectively? How this affect competition with food?

I would be very interesting in see a species with low time to become full grown in the same patch with one stronger in hunting but not in growing.

Do you think could be interesting parameter?
@NickTheNick

Of course cells do not do that if they split by mitosis so they could have that parameter set o 0

This value could affect speed of hunt or effectiveness maybe, because all species would be generally more ineffective ( if both species has same lifespan and 1 need more time to o become fully effective)

I’m also thinking about age that could affect same value but I think I’m putting too many things on the same time :slight_smile:

We’ll absolutely get to the effects of aging! One of the current assumptions is:

The species does not change in physiology as they age.

However, in a future part, we’ll remove that assumption and create a process to track different age classes and how each one is able to survive in the environment.

1 Like

So I played around a little bit with a basic Lotka Volterra model. It’s less chaotic than I thought it would be which is good, but it is quite delicate, if you change the parameter values even a little it can break. However I’m a it more open to being convinced this might work.

One thing I’d suggest is it might be good to play around with it. The code is here. Try changing the predation relations or the birth and death rates and see what happens to it. You might need to pip install pygame to get it to work. I marked 3 places in the code where things can be changed relatively easily. Feel free to ask if you have any questions.

Well, finally got around to reading through all of this. There’s so much here that it’s quite difficult to respond to individual points so I’ll have to accept this post being quiet vague.

First off, thanks so much for doing this. We’ve been in need of a concrete approach to the CPA system for some time and even if this is eventually rejected, it’s good to be at the point where we can decide on something properly one way or the other. It’s also reminded me why I fell in love with Thrive in the first place. So again, thanks, and thanks for not giving up when you lost the first copy of all this.

One question I think we all need to answer as individuals before we define a system like this is: what is Thrive about?

For me, personally, I want a product where the central premise is, ‘Can you beat an evolution simulation at its own game?’ There’s no point having some crazy simulation in the background if it doesn’t affect the player’s experience, and there’s no point having the player do anything if it can’t affect the simulation. That’s a point I’ll return to later.

I really like your chess analogy, and I think we can extend it further. I’m good enough at chess to know how proper chess players play without actually being able to follow that myself, so let’s use some of that.

For the most part, it’s all about patterns. Sometimes there will be standard procedures and definite best strategies, such as the progression of an opening once it’s been chosen, but on the grander scale there’s less determinism about it. A grandmaster can look at the board and approximately match the situation to a pattern they’ve learnt, then use a heuristic approach to choose what’s likely the best response. That’s also how computers play chess as it drastically reduces computation requirements. Or at least, they did until the advent of, ironically, genetic learning algorithms.

Comparing this to Thrive, I would like to see a non-deterministic pattern-based approach to strategic gameplay too. If an ecosystem appears to be almost all herbivores, you can recognise that pattern and know that becoming a carnivore will in most cases be an advantage. But not always. Maybe you didn’t factor in the unique situation of this play through, such as established carnivores migrating in from surrounding patches that you now have to catch up with.

Perhaps there are a few situations when certain adaptations are absolutely optimal. If your prey develops poison, you develop poison resistance. But I really don’t want that to happen with everything.

Coming back to your algorithm, I’m worried it’ll be hard to strike that balance. While admittedly the situation is relatively simple so far, there’s little scope for variety. Increased speed is always better. Increased mating frequency is always better. At the moment the difference in improving any of these stats is purely cosmetic, they all lead to a general survivability advantage.

But, as TJWhale said, with more complexity you could see the opposite problem. Suddenly things become chaotic, and you have zero idea what the best strategy is.

I think once you introduce more than two species you’ll see the impact of this issue reduce, but I’m still hesitant. In the real world, there is always a cost for any benefit. Being faster means needing more food. Being bigger means less manoeuvrability. I assume this will be addressed later on but I think special care needs to be taken to make sure there aren’t too many outright wins, but instead advantages for certain situations or habitats that may have drawbacks.

I was also slightly disappointed to read you’d opted not to go the continuous route. Although you can get equations you can’t solve analytically and would have to discretise for computation anyway, I do think there are more tools available, especially calculus. For example, Holling functional responses can model the effects of hunting and nutrition in a simple way (or so I’ve learnt from one semester of modelling and dynamical systems). Still, discrete models have their uses and if we build a decent algorithm with one then that’s no issue.

Having said all that, I really like where this is all going. The potential for becoming over complicated for little gain is high but still I believe it’s worth pursuing.

I would like to take a look at your Python script, and maybe even try my hand at developing a dynamic version where the user can adjust values for species attributes on the fly and see how that affects population distribution. I need an excuse to practice Java outside of work.

Also, at every stage it should be important to keep gameplay in mind. One of my general worries about Thrive is that we’ll end up designing a system that’s entirely independent of the player’s actions outside the editor. If they design the perfect organism but play the actual game terribly, how do we take that into account? Or if their species is sub-par but they’re really good at hunting and surviving as an individual? I’m struggling to think of a way to do this that doesn’t cheat the evolution system.

Anyway, really great read and thanks again. Together with our recent uptick in concept art and considerable programming effort, Thrive is once again looking very viable.

4 Likes

Thanks yeah I’ll definitely check that out! My prediction is that even though Lotka-Volterra models do create pretty chaotic relationships, there are enough “soft boundaries” in the other features that we have introduced into the system that can sort of “box” the outputs of predator-prey interactions into a relatively understandable pattern. But we’ll see how well that prediction can hold up after I test with that and ultimately add more species and deeper interactions to the algorithm.

Thank you I appreciate it! For me as well it has helped tap into some of that original passion that drew me into the project, which is I think the only reason I was able to tackle it a second time after losing my progress. I think even if this approach doesn’t work, it gets the conversation going on how to concretely simulate Auto-Evo. Perhaps this algorithm can inspire a similar algorithm, or perhaps certain equations used in this algorithm can be used in the final algorithm, or perhaps even this algorithm will simply show us what route NOT to take.

Yes, I completely agree! In fact I am glad to see that so far every trait that has been introduced does affect the outcome in a believable way, and I’m going to try to keep it that way so there’s no useless complexity being added. Actually one trait I’ve noticed has been having a very small effect on things is the Clustering trait, so in a future part I might revisit why it’s not producing the results we intended.

That’s a good point! I was actually planning to address that 2 parts ago, but I decided to leave it for later. The thing is we are currently assuming that the traits are being fed to us from the Organism Editor. Since it’s only Episode 1, I’m only covering how these different traits will be used to calculate the final population numbers. However, Episode 3 will actually cover how this algorithm as a whole will integrate into the game. In other words, where the values for these traits are coming from. Part of that will be covering how the player’s performance in-game affects Auto-Evo, and another will be how the Organism Editor ties into the traits used in Auto-Evo. Realistically, many of these traits would actually be tied together. For example:

  • Increasing body size/volume will:
    • Increase base metabolism (you’ll need more energy)
    • Increase body radius (you can catch prey slightly faster)
    • Likely increase frontal surface area (Which will increase the drag you face from water and reduce your speed)
    • Reduce mating frequency (since it takes longer for your body to replicate all its cells)
    • Increase your energy yield when fed upon (Perhaps making you a more tempting prey)

Another two reasons why I think all mutations currently seem like brainless winning moves:

  • There’s almost no competition. With many other species also evolving around you, it’s no longer a matter of choosing a “good” mutation or a mutation that simply increases your population, it has to be a mutation that increases your population more than the mutations chosen by your competition that is increasing their populations. Think of it like the difference between being the only Toy Store in a town versus a Toy Store with 5 other competitors within several blocks. Of course being the only Toy Store will be pretty easy and it doesn’t really matter what business decisions you make, but Thrive is a game about being one of many Toy Stores and surviving the fight to become the best.
  • The environment is extremely forgiving and mild. We’re basically assuming that there is no change in climate over time, and there are no deaths from environmental conditions that the species is unadapted to (like temperature, pressure, acidity, salinity, radiation, etc.). Increased mating frequency is probably a pretty stupid choice of mutation if you are a hairless animal at the onset of an Ice-Age.

I’ll really dive into the details on all the interrelationships between traits on Episode 3, since I think it’ll be really cool since it’ll be a discussion both on Auto-Evo and the Organism Editor and how they tie together.

I would have if I could have, but I felt that my skills in continuous mathematics and modelling are nowhere near my ability to model discretely. Since I felt that this entire venture was already going to be difficult enough for me on its own, I decided to at least make the process around it easier for myself and use what I was best at (discrete modelling) and the language I’m most familiar with (Python), even if continuous modelling and learning a better programming language would have produced a better outcome. I mean worst case scenario, if this algorithm is chosen and we want to make it continuous, we’ll have an entire pre-built model to base it off of.

I’ll send it your way. In the script has a section that lets you do exactly that, tweak the numbers for each species, or the patch, and watch the outcome.

A very good question that we always need to keep in the back of our minds. In Episode 3, we’ll tackle this problem full on.

1 Like

Part 6.1: Intraspecific Competition

So we just implemented interspecific competition, which is competition between species, but what about competition within a species?

image
Two Terror Birds compete for the same prey

Intraspecific competition can very well affect the survival of a species. Say a T-Rex is roaming around looking for food. It’s possible that he spots a prey about the same time that another T-Rex spots a prey. They both chase for the prey, but only one gets to it first, making the other one have to hunt again. They could have agreed to chase different prey, but most species are not cooperative or altruistic, and many don’t even have the intelligence to be able to even discuss things in any way. As a result, the intraspecific competition actually increased the average hunting time of the species, even when there was no shortage of food.

What’s interesting to note is that Intraspecific Competition only affects the increase to hunting time, but has no effect on the fraction of food caught during shortages. This is because during a shortage, if one T-Rex catches a prey in a race with another T-Rex, that other T-Rex automatically loses that prey, so the differences cancel out. However, with the example I gave above, you can see why it still affects the time spent hunting (which applies with or without a shortage).

The only problem was that actually implementing intraspecific competition mathematically has been something I was wondering about for a while now, but I finally came up with an idea.

Intraspecific Competition

We can simulate intraspecific competition using a simple proportional model. And we’ll use the strategies you know and love, Proportional Estimations and Edge Cases!

Assume a Modelus Specius population has a very very small population in a patch, basically 1. He will face a very very small rate of intraspecific competition, basically 0%. This is because it’s almost impossible for another Modelus to beat him to a prey, since they’re just not there. As a result, he suffers essentially no increases to his hunting time.

But this will never happen, the populations of species will almost always be more than this in a patch. As you increase the population of Modelus, you increase the percentage of hunts he will fail due to intraspecific competition, AKA the average time he’ll have to spend hunting. We can model this using a simple relationship:

For every +1 organism/m^3 increase in the population density of Modelus Specius, there is a +0.1% increase in intraspecific competition, meaning there is a +0.1% increase in average hunting time.

Note that we’ve now added Population Density to the algorithm. This is represented as individuals per m^2 (or per m^3 if underwater).

Clustering will increase this number. At 0% clustering, there will be no effect on intraspecific competition. However, the more clustered a species is the more they will get in each others’ way, thus it will increase intraspecific competition. This gives us:

For every 1% increase in the clustering of Modelus Specius, there is a +0.1% increase in intraspecific competition, meaning there is a +0.1% increase in average hunting time.

Hopefully this also makes the Clustering trait a little more impactful on the simulation than it’s been so far.

Mathematically this looks like:

Intraspecific Competition = Intraspecific Competition Rate * Population Density * (1 + Clustering)

Note that the Intraspecific Competition Rate describes how fast the Intraspecific Competition of the species grows as a result of increases to population density or clustering. Intraspecific Competition Rate is a trait, it’s an innate behaviour of the species. Meanwhile, Intraspecific Competition is a Performance Stat, since it fluctuates with the changing levels of population density.

To summarize: Intraspecific competition simply describes what percentage of hunts are lost due to a member of the same species beating you to the prey. It technically can never reach 100%, because some members of the species have to be the ones winning, so it caps at around 99.99%.

Altruism & Cooperation

However, some species have evolved the ability to recognize their kin and even work with them and avoid conflicts with them. We still have a while to go before we get to intelligence and sociality, but for now we’ll create the potential for this feature when it is introduced in the future.

Increasing the altruism of your species will reduce how fast intraspecific competition increases with population density and clustering. Say the standard Intraspecific Competition Rate is +1.0%, an altruistic species might evolve to lower this to 0.5% or 0.1%. This represents social species that live in large groups and who have learned to avoid competing with each other.

2-Species Demo

So what should these changes do? The introduction of intraspecific competition should actually add as an additional limiter on the size of a species in a patch, on top of food. As a species grows larger and larger, there is more and more intraspecific competition which makes their hunting less and less efficient. This should actually help mitigate the effects of the Competitive Exclusion Principle that we observed last in Part 6, since the dominant species in a competitive relationship might not be able to fully take over the patch since they’ll face too much intraspecific competition. Let’s run the numbers and see the results:

The parameters of the demo are the same as in Part 6. Remember, Propagatus Maxima is the same as Modelus Specius in every trait except that it’s mating frequency is 0.6 times per month instead of 0.5. We’ll now add the following two trait changes/additions to Propagatus:

  • Clustering increased from 0% to 50%
  • Intraspecific Competition Rate set to +0.7% per 1 individual / m^3

Meanwhile, Modelus Specius has an Intraspecific Competition Rate of 0%, meaning it faces no within-species competition. Let’s see the results!

Interesting! Remember that the last time we ran the demo Modelus Specius was on its way to extinction, ending the 2 years at around 160 members. This time around Modelus is at over 400 members by the second year, and still at above 300 by the third! Clearly the intraspecific competition of Propagatus is holding it back from dominating the environment, even though it has the reproductive advantage.

It’s also interesting to note that Clustering actually has a significant impact now. Before, Clustering barely (and I mean barely) affected the average hunt distances even at the most extreme values, but now it plays a major role in intraspecific competition. Species that are clustered together will face a lot more competition between species members, and are better off evolving to live more solitary lives (think boars) OR to evolve cooperative tendencies so they can work together (think zebras).

3-Species Demo

Alright, time to crank up the simulation by a notch. We added a 2nd species last time, so now let’s add a 3rd! This species will be the exact same as Modelus Specius, but it will have slightly stronger muscles (3.0N/m^2 instead of 2.5N/m^2). To recap, the three species look like:

Modelus Specius: The typical species.
Propagatus Maxima: Same stats as Modelus Specius but Mating Frequency is 0.6 / month instead of 0.5, Clustering is 50% instead of 0%, and Intraspecific Competition Rate is 0.7% instead of 0%.
Minimus Rex: Same stats as Modelus but Muscle Strength is 3.0 N/m^2 instead of 2.5.

Let’s see the results:

Damn, even though Modelus Specius was able to hang in against the competition last time around, the double competition of Minimus Rex and Propagatus Maxima was just too much and they went extinct. It’s also interesting to see that Minimus and Propagatus do not seem to be pushing the other into extinction. Perhaps they will survive in an equilibrium? It could be that Minimus has the competitive edge because of the speed advantage, but Propagatus is able to “eat into” those losses with his increased mating frequency that covers for his starvation deaths. Or perhaps their declines are slower and we would need to run the simulation for longer.

Regardless, amazing to see the simulation still holding together with 3 species in the mix now! It’s really starting to feel a lot more like a living ecosystem compared to the first few parts of the series. It’s also really cool to see the results and predict what causes are leading to what outcomes. These interactions will only get more deep and exciting as we go!

Q&A

Before we close, we’ll take this moment to open the series up to for a Questions and Answers period for all readers. We’ve covered a LOT of content so far, and I want to make sure none of the readers are falling behind on their understanding. If you have any questions, comments, concerns, suggestions, or what have you on the series so far, submit it on our Discord, Subreddit, Facebook, or Twitter and I’ll answer as many as I can in the next post! You can also respond to the subreddit post that I’ll be making for this part shortly, or to the Devblog that will be coming out within a few days (that will be all about this series). Hopefully this Q&A can help bring us all up to speed on the series so far and address any ongoing confusions people may have.

Anyways, thanks for reading and see you guys next time!


Summary

New Performance Stats
Intraspecific Competition

New Traits
Intraspecific Competition Rate

Topics for Discussion

  • All feedback is welcome!
2 Likes

One question I have is what happens if you run the 2 species model for longer? Does it settle into an equilibrium or does one species die out? Same question for the 3 species model, what happens over a longer timespan.

For the 2 species model, Modelus died out after 1-2 more years. However, if I increased Propagatus’ Intraspecific Competition Rate to 0.8%, then they stabilize. Here’s a graph of their populations in the latter scenario over 10 years:

If I do the 3 species model over 10 years Minimus Rex wins and the other 2 species go extinct. However if I give Minimus Rex some intraspecific competition as well (an Intraspecific Competition Rate of 0.8%) we get a 2 species equilibrium. Modelus still goes extinct though. Here are the results.

I guess Modelus is just not competitive enough to survive against 2 competitors. Also there is probably not enough food being generated every turn in the ecosystem to support three species of around 500 individuals. I’m guessing if the food replenishment rate was increased, or if the intraspecific competition rates of Minimus or Propagatus were increased which would lower their equilibrium populations, Modelus could survive.

2 Likes

Part 6.2: Q&A

And we’re back with the questions that people had for the Q&A! Let’s see what feedback people had.

@DmitrisTerlegkas from Twitter asks:

Who the hell has time to write 10k words??? Give the man who wrote all that a metal and a raise

Me, and technically I shouldn’t have the time but I’m carving out what free time I can. A medal would be cool though!

LibertyBellSeven from Reddit asks:

Good stuff! My main concern about auto-evo is that it will produce similar and unnatural looking creatures. How can the algorithm generate lifeforms that can compete aesthetically with the player-species?

To which I answered on reddit. Here's the response I gave:

That’s a good question, and part of the answer is that it’s hard to give a straight answer since both Auto-Evo and the Organism Editor are still works in progress and haven’t been finalized yet. It’ll become more apparent how to address issues like these once we actually finish designing those.

However to answer your question as best I can right now, there’s a lot of physical, chemical, and biological reasons that creatures on earth look the way that they do. Hopefully, if we implement realistic enough rules and boundaries in the game, it will drive the creatures generated by Auto-Evo to approximately fall into believable looking aesthetics.

One example I can think of is that we’ll calculate the frontal surface area of any organism, and that will reduce their speed if they live underwater. This will tend to cause underwater species to go for more streamlined shapes to have higher speeds underwater, and have a more fish-like appearance as seen on earth.

Another example could be putting hard limits on where certain mutations can occur, since evolution always works with what DNA is currently available. For example a species might start evolving legs on the sides of its torso with the new leg bones evolving out of the existing spine bones, whereas we wouldn’t allow a leg to start evolving out of an earlobe. However, maybe that creature has very unique ears that have bones in them that could evolve to split off and develop a leg! The point is though that plausible biological and physical limits will exist to make things look more natural.

Solitarian from the Community Forum asks:

Actually the plan is to make the algorithm specifically note what kinds of movement organisms use and have that affect their survival. Some differences will be clear, such as underwater patches being specifically different patches than terrestrial patches and containing different species. However, there will of course be grey areas. There are birds that dive into water to catch fish, there are amphibians who live on both water and land, etc. I’ll address that all in future parts once we get major obstacles like predation, combat, and metabolism out of the way.

MisterMustachio from the Community Forum says:

I have to wonder how you’ll calculate the overlap of species in separate environments. A species may encounter a number of other species, but isn’t likely to encounter every member of those species, nor is every species likely to encounter every other species.

Species within a patch are assumed to pretty much interact with all of the other species in the patch. The differences will be between patches. Species A might overlap with Species B in some patches because they both exist in it, and not in other patches since only one of them exists there.


Those were all the questions from this Q&A. Unfortunately my free-time has been limited so the next part likely won’t be ready for another week. However, if it makes you feel better it’s because the next part includes some major changes.

2 Likes

Part 7: Predation

At the moment, all of the species hunt for the same free-floating clouds of glucose that we’ve been calling “Food”.

Boring!

Now that we have multiple species let’s add the first step to realistic feeding, carnivores!

Now that we’ve added other species to the mix, and gotten the nitty gritty of competition out of the way, we can start to make this model a lot more interesting. These next few parts will have a lot of juicy content, but will also involve some difficult conceptual hurdles, so it’ll be interesting to see how we make it past them. In fact, my notes for the parts after these next few posts are sparse, because it will depend so much on what we come up with for these next few parts.

Predation is a VERY complex topic, so we will be breaking it down into several parts. Today we will tackle the basic concept of catching and feeding on other species, and how that changes the population dynamics of the ecosystem (as well as how their speeds, accelerations, and endurances are pitted against each other). In future parts, we’ll address Combat, Parasitism, Scavenging, Prey Selection, Heterotrophy vs Autotrophy, and Cannibalism. By the end of implementing all the features related to predation, we’ll have a MUCH more robust algorithm on our hands. We’ll also see that the Starvation Deaths performance statistic is actually a very complex stat derived from many, many, many interplaying factors. It will be the stat that likely fluctuates the most between months, and it makes sense because success in hunting is a large part of survival. Many evolutions of species will simply be to improve success in hunting and reduce Starvation Deaths.

Let’s break down the following assumption from our list of assumptions:
  • Modelus Specius is a flat, tiny, simple, jelly-like organism that lives at the bottom of the ocean.
  • Members of the species can completely consume the food and gain 100% of the energy. (Hunting/Metabolism)
  • Members of the species can instantly perceive food regardless of distance (Perception)
  • Members can reproduce as many times as they want, instantly, with no pregnancy/gestation period. (Reproduction)
  • The species reproduces via asexual reproduction, spawning fully developed offspring that can themselves immediately begin reproducing. (Mating)
  • The species does not change in physiology as they age (Aging/Ontogeny)
  • The species is fully aquatic (Terrestriality)
  • Members of the species are solitary and do not cooperate with other species members in any way. (Cooperation/Sociality)
  • The species has no parental instincts, and will immediately abandon offspring (Parenting)
  • The species is perfectly adapted to its environment and suffers no death or disease from environmental conditions (Environment)
We will instead replace it with:
  • Modelus Specius is a flat, tiny, simple, jelly-like organism that lives at the bottom of the ocean.
  • Members of the species will always win combats against smaller individuals, and lose to larger ones (Combat)
  • Members of the species always consume 100% of the energy of defeated prey (Metabolism)
  • Members of the species can instantly perceive food regardless of distance (Perception)
  • Members can reproduce as many times as they want, instantly, with no pregnancy/gestation period. (Reproduction)
  • The species reproduces via asexual reproduction, spawning fully developed offspring that can themselves immediately begin reproducing. (Mating)
  • The species does not change in physiology as they age (Aging/Ontogeny)
  • The species is fully aquatic (Terrestriality)
  • Members of the species are solitary and do not cooperate with other species members in any way. (Cooperation/Sociality)
  • The species has no parental instincts, and will immediately abandon offspring (Parenting)
  • The species is perfectly adapted to its environment and suffers no death or disease from environmental conditions (Environment)

Changes to the Algorithm

This part again included some major changes to the code, so I had to do another major overhaul to make things cleaner and more organized. I also had to reorder how some things were calculated to make it easier to implement predation and the upcoming features. Here is a summary of the changes:

  • Prey lists and predator lists. Every species now has a list of species it preys on and a list of species that are predators to it. Instead of just calculating hunting statistics once for every species, we now calculate different statistics for each prey that they hunt. These include Required Hunts, Available Hunts, Time per Hunts, etc. The differences between how the predator favours the prey is based off of the priority that predator has for hunting each prey. If a species has a total energy requirement of 1000 joules for their entire species, and they have a prey priority of 50% for Species X, then they will try to get 500 joules of energy through hunting Species X (however many hunts that would be). At the moment, all species have only 1 prey, the food clouds, with a priority of 100%, so this makes no change to the simulation’s outcome. However things will change over the course of this part as we make species prey on each other.
  • Body mass, acceleration, and endurance added as traits. I will explain why below.

How Do we Implement Predation?

As a result of implementing predation, Modelus Specius will now be a carnivore. Carnivores will instead consume members of other species instead of the clouds of glucose. In this case, Modelus Specius will feed on Propagatus Maxima, and nothing else. Propagatus Maxima and Minimus Rex will continue to feed on glucose only. We’ll cover herbivores and omnivores in a future part. This gives us the chance to create our first food web!

We can see that it’s pretty simple so far, with Modelus Specius at the top of the food chain and only two species below him.

The major changes to the simulation by adding predation will be:

  1. Hunting prey that can move and escape you. So we need to come up with an equation that determines how successfully predators can catch prey.
  2. Hunting prey whose population can grow or shrink dynamically. This will not need to be specifically coded because it will naturally result from the changes we make. However, it will be interesting to observe how it changes the results of the simulation.

Planning how to start tackling this issue can be a pretty tricky concept, so let’s break it down into its constituent elements and think about it logically.

A predator can either be in two situations with the prey.

  1. The predator is faster than the prey.
  2. The predator is slower than the prey.

New Traits

Before we consider these two scenarios, I added 3 new traits to the mix to help in the calculations that you will see soon.

Acceleration is a trait representing a species’ initial acceleration going from not moving to his max speed. It is calculated by the simple physical equation of Acceleration = Force / Mass. Remember that force in this case is the force of the muscles, which we already have traits for. The units of acceleration are in meters per second squared.
Body Mass is a trait representing the mass of the species. So far, it is only used in calculating the acceleration of the species. The units of body mass are in kilograms.
Endurance is a trait representing how long the species can go at its max speed before it tires and has to stop. The units of endurance are in seconds.

Faster Predator

If the predator is faster, then it’s quite simple. The predator can overtake the prey in speed and catch him. In this case, we can refer to the predator as a “Speed Hunter”, since he’s using his greater speed to catch the prey in their chases.

There’s only one caveat. What if the predator starts 100m away and gets tired after just a couple meters of running? Even if he’s faster than the prey, it’s irrelevant because he started so far away he couldn’t traverse the distance. Thus we can see that even if the predator is faster than the prey, he has to have the endurance to overcome the distance between them. So a more accurate statement would be:

“If the predator is faster than the prey, AND the time it takes to catch the prey is less than or equal to the predator’s endurance, the predator will always win the chase.”

Mathematically, we’ll represent this using a fraction. We’ll divide the endurance of the predator by the average time per hunt. We’ll cap the success rate of the predator at 100%. This gives us the following equations:

IF Predator Speed > Prey Speed
THEN Success Rate = Endurance / Time per Hunt 

NOTE: For or any astute readers, you may recall that Time per Hunt is a performance stat that is affected by inter and intra specific competition! More competition increases the time per hunt. This means that increased competition makes it less likely that a predator will have enough endurance for all their hunts, since sometimes they’ll spend time chasing a prey that gets caught by someone else and wastes some of their endurance.

Also, remember that we added in a new trait called acceleration! Actually calculating a detailed realistic way of implementing varying speeds and accelerations into the hunting equation would be a nightmare. So the simpler way that I will tie in acceleration is by comparing the acceleration of the predator to the acceleration of the prey. If the predator has a higher acceleration than the prey, this gives him a bonus to his speed. If he has lower acceleration, this gives him a malus. This is to represent organisms who are very quick at accelerating and reaching their top speed and catching their prey (or getting away from their predators). So we’ll update the equations to this:

IF Predator Speed * (Predator Acceleration / Prey Acceleration) > Prey Speed
THEN Success Rate = Endurance / Time per Hunt

However, what if the predator does NOT have the endurance to outweigh the average time per hunt? Notice that the relationship is a simple ratio, so if the endurance is half of the average time per hunt, then that means the predator will win half of the chases. This represents that half of the time, the predator is close enough to catch the prey. The other half of the time, he starts so far away that he gets tired before he catches up to the prey (even though he is faster).

This seems like a good equation for now. If we find that it favours the predators or the prey too much, we can come back and rebalance it. Let’s see a quick visual demo of what we discussed:

Let’s say that the prey starts 25m away, and both species have equal acceleration so there is no bonus/malus to the predator. We can see that the time it will take the predator to catch the prey is just the distance he starts away from the prey, divided by the difference in their speeds:

Time per Hunt = Average Distance of Predator from Prey / (Predator Speed - Prey Speed)
Time per Hunt = 25m / (10m/s - 5m/s)
Time per Hunt = 25m / 5m/s
Time per Hunt = 5s

Notice how the prey has a much higher endurance than the predator. But it doesn’t matter! Since the predator is faster, he catches up to the prey in 5 seconds, exactly his endurance limit. Using the equation we have above, that gives the predator a success rate of:

Success Rate = Endurance / Time per Hunt = 5s / 5s = 1.0 = 100%

The average hunt is exactly within the endurance limit of the predator, so he catches the prey essentially an average of 100% of the times that he chases him.

Slower Predator

Ok, but what if the predator is not faster than the prey? In that case, there’s only one possible scenario where the predator could still win. This is what we’ll call an “Endurance Hunter”.

Imagine a predator starts to chase a prey 10 meters away. The prey has a speed of 10 m/s, but only 1 second of endurance. Meanwhile, the predator has a speed of 1 m/s but has 100 seconds of endurance. The prey outruns the predator for the first second, but then tires. Meanwhile, the predator second by second gets closer, until eventually catching the prey on the 20th second.

So even if the predator has a lower speed than the prey, he can still win if the overall distance he traverses is greater than the distance the prey traverses PLUS the distance of the gap between them. How does this look mathematically?

First, let’s define the distance traversed during a hunt as the speed of the organism multiplied by the endurance of the organism:

Predator Distance Travelled = Predator Speed * Predator Endurance
Prey Distance Travelled = Prey Speed * Prey Endurance

Now, combining this with what we discussed above we get:

IF Predator Speed * (Predator Acceleration / Prey Acceleration) <= Prey Speed
AND Predator Distance Travelled >=  Prey Distance Travelled + Average Distance from Predator to Prey
THEN Success Rate = Predator Distance Travelled / (Prey Distance Travelled + Average Distance from Predator to Prey)

Notice that again we are using a fraction for determining the success rate. This time we compare the distance travelled by the predator to the distance travelled by the prey plus the gap between them. This means that the total distance travelled of the predator would equal the total distance travelled of the prey plus the average gap between them for the predator to have a 100% success rate.

Let’s use another diagram to visualize this scenario:

Again the prey starts 25m away from the predator. Although the prey has a higher speed than the predator, he tires quickly while the predator continues chasing due to his high endurance. Eventually the predator catches the prey, at the 55th meter. The time the hunt takes is the total distance the predator has to move to catch the prey, divided by the predator’s speed.

Time per Hunt = (Prey Distance Travelled + Average Distance from Predator to Prey) / Predator Speed

The predator’s average success rate is modelled by:

Success Rate = Predator Distance Travelled / (Prey Distance Travelled + Average Distance from Predator to Prey)
Success Rate = 75m / (30m + 25m) = 75 / 65 = 1.00 = 100% (Capped at 100%)

Notice that you could have an alternate scenario where the predator’s distance travelled is less than the prey distance travelled plus the average distance from predator to prey. In this case, the success rate would just be the ratio of the predator’s distance travelled to the denominator.

Assumptions

Now what are some of the assumptions that this model is making? Well it assumes that predators and prey always have their maximum endurance available when chasing. What if a predator starts a chase with only half endurance? Or a prey with only 20% endurance? In this case it might make it better to see endurance as the AVERAGE endurance of members of that species when a hunt is initiated. We could keep this in mind though and revisit it in a future part (yes I know I sound like a broken record when saying that).

Order of Calculations

A key question to ask ourselves here is, what order do we calculate predation changes? The problem is that predation calculations for one species will affect the overall calculations of other species. Do we calculate the predation of herbivores first, and then the carnivores? Do we randomly pick one species at a time and calculate predation on it and keep rotating until we’ve hit all species?

The solution I’ve gone for here is to calculate it simultaneously to starvation. Is this entirely realistic? Perhaps not, because it’s currently possible that a species is preyed on at the beginning of the month but still contributes towards the overall hunger and thus starvation of the species over the course of the entire month. However, it means we avoid having to worry about who to calculate predation for first which would be a HUGE hassle on its own, so for now I think it’s a worthy sacrifice.

We can visualize the current life cycle of organisms using the following Life Cycle Diagram:

So the way it works is we start with the initial population, and we calculate the food it hunts and the number of individuals that are hunted first. Then the members who die from starvation and predation are killed off. From the survivors, offspring are born, and then some of those survivors also die of old age. The final group of survivors plus the offspring form the population of the next simulation step.

Demo

Now that we’ve ironed out all the additions of predation, let’s run a demo to see how things have changed.

Here are our Starting Conditions

image



The final populations of the species were:
Modelus Specius - 2,045
Minimus Rex - 70,679
Propagatus Maxima - 38,211

It’s good to see that the simulations have not become chaotic as I was worrying! It seems that the many soft caps we’ve introduced, such as intraspecific competition, interspecific competition, spatial population density, movement speed, and others have helped “cushion” major upheavals from disrupting the population numbers.

From looking at the graph we can see the typical rise in population until we hit the famine on the 22nd month, and then a big hit to the “herbivores” (Minimus and Propagatus). We can also see that once the shortage hits Minimus begins to outperform Minimus at being the dominant glucose-eater.

Meanwhile, although Modelus looks like he’s off the charts, he’s actually maintaining quite a stable population at several thousand members. He was also largely unaffected by the famine, catching essentially just as many prey in the 22nd, 23rd, and following months as he did before.

One thing that I noticed when balancing the simulation was that the predators are very overpowered at the moment. If I make them just even slightly more powerful than the prey in terms of speed or endurance, they will completely eat all the prey and then make themselves starve to extinction. The reasons for this are because perception and combat haven’t been implemented yet. The predators currently know where all prey are at at all times, and always win combats against them. They also suffer no deaths from intra-specific competition, only delays to hunting times. So the predators are extremely and unrealistically efficient. Once we implement these features, predators won’t be as omnipowerful and we’ll start seeing more realistic balances of numbers. Still, it’s cool to see that the predators are naturally forming a smaller proportion of the ecosystem than the prey, and are also reaching stabilized population numbers within 4 years of the simulation.

This part included some major changes, so get ready for some “bugfixing” sub-parts to come up in the next week or so if I run into any bugs or flaws with the implementation from this part. Anyways, it’s really cool to see these features making it into the algorithm and to watch the evolution get slowly and slowly more realistic! Now that we’ve got the basics of predation in place, stay tuned for the content we’ll be able to add next!


Summary

New Performance Statistics
Caught Hunts
Predation Deaths

New Traits
Acceleration
Body Mass
Endurance

Topics for Discussion

  • Comments and feedback are welcome!
2 Likes

Part 7.1: Understanding Predation

We implemented a big feature in the previous part, but I’ll admit the write-up was a bit rushed. There was so much coding involved in updating the script that when it came to writing the post I was ready to just post it.

But I think it’s important that we fully understand this model as we progress through building it. So to better explain the additions we’ve made, let’s do a sub-part to illustrate how adding predation has changed the model.

Bugfixes

Before we begin, one bug I caught was that I realized I wasn’t using the predator’s adjusted speed in calculating the time per hunt or success rate for hunts. Recall that the predator’s adjusted speed is:

Predator Speed * (Predator Acceleration / Prey Acceleration)

Essentially giving them a bonus or malus to their speed based on how much acceleration they have relative to the predator. This bugfix has greatly improved the power of predators in the predator-prey relationships.

Overview

First thing’s first, let’s summarize what was done in the last part. Besides the under-the-hood changes I had to make to the code to support predation, all we did was make two changes.

  1. Species can now predate on other species. This means that the fate of predators and prey are now getting tied together. If a predator does very well in hunting a prey, that could drive the prey to extinction, which would then cause the predator to go extinct. A predator would never want to over-hunt his prey.

  2. When a species predates on another species, he compares his speed, endurance, and acceleration to those of the prey. The comparison determines the success rate of the predator in catching the prey.

It’s these two changes that lay the foundation for predation in the algorithm, and will be used as the basis for adding in future features like Prey Selection, Parasitism, Scavenging, and more.

Types of Hunters

In order to create the equations we wanted, we categorized hunters into two types: Predators they are faster than their prey (Speed Predators), and predators that are not faster than their prey (Endurance Predators).

One change I’ve made here is that I’ve divided the outcome of the Speed Hunter success rates by 2. This is to represent the variability in hunting outcomes. Having an endurance that meets the average time per hunt likely won’t mean a predator will win 100% of hunts. In fact there will be a lot of variability with some hunts being shorter, some being longer, and only the average hunt having a length that is the average time per hunt. Thus it makes more sense if the predator’s endurance would actually have to be considerably higher than the average time per hunt to win 100% of them. With this change, they’ll need to have twice as much endurance.

The logic of this change was also applied to the success rate of Endurance Hunters.

Here’s a visual to represent these changes:

Problems with the “2 Types of Hunters” System

There is one problem I’ve noticed that this system introduces however. Since Speed Hunters and Endurance Hunters have their outcomes calculated differently, just a slight change in a predator’s speed can make it suddenly shift categories and dramatically change its survival. Sometimes, if the conditions are in a certain way, a predator actually performs WORSE by increasing their speed, since they switch from being an endurance hunter to being a speed hunter and the calculations give them a lower success rate. There are two ways I can think of to solve this:

  1. Hunting Spectrum. Make the hunter type a spectrum. Instead of a species being 100% a Speed Hunter or 100% an Endurance Hunter, we can allow for a range of combinations in between. Since we’re dealing with average speeds, average success rates, etc., we can say that on AVERAGE the species uses Speed Hunting X% of the time and uses Endurance Hunting Y% of the time.
  2. Fall-Back Option. Make Speed Hunters able to fall back to using Endurance Hunting if it gives them better success rates.

I ended up implementing both of these. I liked the idea of a Hunting Spectrum, because I didn’t like the sudden jump species were making from one category to another the moment their speed went a little higher than the prey. At the moment, if the predator’s speed is equal to or lower than the speed of the prey, he will use Endurance Hunting 100% of the time. If his speed is 50% higher than that of the prey, he will use Speed Hunting 50% of the time. If his speed is double that of the prey or higher, he will use Speed Hunting 100% of the time.

I also liked the idea of a Fall-Back option because it doesn’t make sense why improving speed should decrease the success of a predator. This now means that endurance hunting is the “default” for species, and evolving a higher speed than your prey simply offers you the option of using speed hunting if its more effective. I will have to do further research into why speed hunting often gives worse performance though.

Tying into the Algorithm

How does the addition of predation affect the overall process of hunting, acquiring food, and starvation deaths?

Predation simply adds an extra limiting step in the process of hunting. Recall that when we added food to the system, it introduced the ability for species members to die of starvation if not enough energy was consumed. Well since then we’ve been gradually increasing the possible factors that can cause a species to not get all the energy it needs, ultimately increasing the importance of Starvation Deaths. Implementing movement in part 3 introduced the idea of having to spend time to reach food, competition led to increases to time based on how many people were chasing the same food, and now predation adds the ability for prey to escape you if you are not fast enough. Since we’ve now added so many factors, let’s summarize the full “Hunting Breakdown” of all the steps that limit the success of energy consumption:

First a species determines how much total energy it needs and it divides it up into quotas between each prey based on how much it prioritizes that prey. This is used to calculate the Required Hunts for each prey. However, a species might require more hunts than there are prey, so required hunts is limited to produce the Available Hunts. However, an organism has to compete with other species and even members of his own species who could steal a prey before him, so the available hunts is limited by competition to produce the Uninterrupted Hunts. However, an organism may not always catch all the prey he chases if they are able to evade him, so the uninterrupted hunts is limited to produce the Caught Hunts (this is the step added by predation). Finally, the organism might not even have enough time in the day to perform the number of hunts he needs to feed himself, so the caught hunts is limited by the organism’s free time to produce the Completed Hunts. This final completed hunts value is what determines how much energy the species gets from that prey, and is used to calculate Starvation Deaths.

That was a big wall of text, so here is a visual:

In this diagram I focused on energy instead of hunts but it’s the same idea.

Think of the width of the bars representing the amount of energy at each step. The main pattern you can see is that each step reduces the final success rate of the species in getting the energy they need. The boxes to the right explain the limiting factors involved in that step. We can see that the amount of energy a species actually receives will almost always, without exception, be less than the ideal amount of energy they would need in a perfect world. That might not be entirely the case right now, but it will become more and more true as we continue to flesh out the algorithm.

This means species have many opportunities in evolution to better adapt to any one of the numerous limiting factors that are listed on the right-hand side. A good player will be one who can easily identify the factors that are limiting his hunting the most and plan what mutations would best respond to that for the short and long term.

For those who are interested, here is a sneak peek at a more expanded version of the “Hunting Breakdown” list. This is what it will look like once we’ve added more features to the algorithm (like perception and combat).

Order of Calculations

Before we move on to the final topic, I’d like to reiterate one more time how the order of calculations has been changed with the addition of predation. Here is a visual:

image

Predation and Starvation are calculated simultaneously. This means if a species has 100 members who require 100J of energy, but they only receive 50J, then 50 members die of starvation (assuming a starvation penalty of 100%). If 25 members are eaten by predators, this is further subtraced out of the remaining 50 members to leave 25 surviving members as the Intermediary Population 1.

This means that those 25 members who were eaten by predators still contributed towards starvation. What if all 25 of those members died at the beginning of the month? Shouldn’t the species have only suffered half as much starvation because it really only had to feed 75 mouths? Or what if the 50 members had died of starvation first? Then wouldn’t the predators have had a harder time finding the remaining 50 members and perhaps only eaten 15 of them instead of 25? This approach ignores all those possibilities and just has both starvation and predation occur at the same time.

I’m describing this again in case someone can find a flaw with this approach. I am worried that it is sacrificing some realism, but the alternatives were just far too complex and seemed to sacrifice even more realism. If you try to calculate predation first sometimes, you need to calculate starvation first other times to be realistic. You also then need to decide which species to calculate predation on first sometimes and which species to calculate predation on first other times. It becomes a whole Belgiuming mess, so “Simultaneous Calculation” was the best compromise I could think of.

Performance Stats and Traits

Now finally, we’ve explained what the changes were by adding predation into the model, and we’ve explained how these additions affected the rest of the model. But let’s take a look at a very significant but underappreciated feature that was added way back in Part 1, statistics!

We’ve been gradually piling up the number of Performance Stats and Traits in the game. It might get kind of easy to lose track of all of them. The “Starting Conditions” boxes have become pretty sizable with multiple images, and the Charts are so big now with so many Performance Stats I won’t always be posting them.

So in the interest of seeing how all the statistics tie together, and also cause it’s pretty cool, let’s make a tree of all the relationships between all of the traits and performance stats!

image


Legend:

  • Yellow boxes are Traits of the current species.
  • Blue boxes are Performance Stats of the current species.
  • Pink boxes are Traits or Performance Stats of any prey of the current species.
  • Purple boxes are Traits or Performance Stats of any predator of the current species.
  • Orange boxes are Traits of the environment.
  • Green arrows show proportional relationships (where an increase in the source leads to an increase in the target)
  • Red arrows show inversely proportional relationships (where an increase in the source leads to a decrease in the target)

Although the diagram can seem overwhelming at first, it actually contains a lot of cool information. For one thing, it contains all the current traits and performance stats in the model. Also, since it tells you what is calculated from what, it also essentially shows you the order of calculations!

The presence of pink and purple boxes on the chart representing stats from prey and predators show how the addition of predation has made species success a lot more dependent on the success of its prey and predators.

Orange boxes represent the features of the environment. Those boxes are the potential targets for change during climactic events like ice ages or global warming, and those variables will change when a species moves to a new biome. At the moment, the number of orange boxes is pretty limited. This will change as we introduce more features of the environment in future parts.

Another cool thing is that the yellow boxes represent all the potential targets for evolution for your species. These variables are the ones that will only change as a result of changes you make in the Organism Editor. They essentially represent the player’s input into the system. It’s through the manipulation of the yellow variables that the player tries to increase the survival and success of his species on his planet. In Episode 3 we will talk about how these Traits are derived from the designs of organisms the player makes in the Organism Editor.

Conclusion

That’s it for this sub-part! Thanks for reading, and hopefully this helped shed light on the recent changes to the system from adding Predation. Stay tuned to see what will be the topic for the next part, but I sense that it will be something interesting.

Part 8: Perception

For those of you reading since the beginning, you might remember that we started with really basic, (and yes dull) concepts. Population mathematics, spatial modelling of how species are distributed, the physics of calculating movement speed… the whole shebang. However, now that we’ve gotten those necessary foundational mechanics implemented, we’re going to be able to start implementing a lot more actually interesting concepts. These will take us leaps and bounds towards a more realistic model.

The interesting topic for today is Perception.


Can you recognize all the eyes in this photo?

Is it just me or is it pretty unrealistic that the species always knows where the food is. In fact, it’s one of the reasons that every species has been doing so well despite how poor their traits and starting conditions are. Now, we’ll finally take away their omniscience and watch their numbers plummet as they have to deal with limited perception like the rest of us.

Perception is a very important limiting factor of species survival. You can only eat the food you find, you can only chase the prey you detect, you can only escape a predator that you notice. There are so many different ways of sensing your environment, and for each method there are so many factors that improve one’s perception, or reduce it (i.e. camouflage). The environment can also impact perception and camouflage, with silty rivers or dark ocean floors making vision a lot less viable than it is for surface ocean dwellers, land dwellers, or particularly aerial organisms.

In fact, we almost cannot continue further in the design of the algorithm until we implement perception. Right now, organisms are just too powerful in their ability to detect food. Anytime I even slightly buff Modelus Specius, he becomes such an effective predator that he eats all of Propagatus Maxima, driving the latter to extinction. This leaves Modelus without any food, so then he goes extinct too. The solution to this is to implement perception, so that Modelus cannot always see where all of Propagatus are at all times.

In this part, we will be removing the following assumption from our model:
  • Modelus Specius is a flat, tiny, simple, jelly-like organism that lives at the bottom of the ocean.
  • Members of the species will always win combats against smaller individuals, and lose to larger ones (Combat)
  • Members of the species always consume 100% of the energy of defeated prey (Metabolism)
  • Members of the species can instantly perceive food regardless of distance (Perception)
  • Members can reproduce as many times as they want, instantly, with no pregnancy/gestation period. (Reproduction)
  • The species reproduces via asexual reproduction, spawning fully developed offspring that can themselves immediately begin reproducing. (Mating)
  • The species does not change in physiology as they age (Aging/Ontogeny)
  • The species is fully aquatic (Terrestriality)
  • Members of the species are solitary and do not cooperate with other species members in any way. (Cooperation/Sociality)
  • The species has no parental instincts, and will immediately abandon offspring (Parenting)
  • The species is perfectly adapted to its environment and suffers no death or disease from environmental conditions (Environment)

How do Organisms Use Their Senses?

Senses and the sensory system serve organisms in many different ways. Some of the examples of using sensation/perception are:

  • Hunting : Using senses to find prey.
  • Intimidation : Using senses to intimidate rivals to avoid combat, or determine whether a rival is worth engaging in combat.
  • Examining food : Using senses to determine whether found food is good to eat, as opposed to catching food from live prey.
  • Communication :
    • Using senses for cooperating for hunting/defence/tasks
    • Using senses for warning/distress calls
    • Using senses for mating rituals

Of these uses, we will only implement the first function for now. Intimidation will be implemented once we’ve added Combat to the algorithm. Examining food will be implemented once we’ve added Scavenging. Communication will be added once we add behaviour and sociality.

Modelling Perception

But how do we actually mathematically represent perception? Well, if you consider perception, it really boils down to two factors: Things that improve an observer’s ability to see a target, and things that reduce an observer’s ability to see a target. We will call these two values Perception and Camouflage.

  • Perception represents the ability to sense targets using a particular sense. It represents the strength of the organs involved in sensation.
  • Camouflage represents an organism’s “resistance” to being sensed using a particular sense.

These can be influenced by traits of the observer and target organisms, and from traits of the patch/environment (like the murky water example above). Every organism has Perception and Camouflage stats for each sense . For example, the stats of a certain creature for vision could look like:

Vision Perception: 1
+1 from Simple Occuli Eyes

Vision Camouflage: 3
+2 from Cryptic Camouflage Colouration
+1 from Silty Water

Perception vs Camouflage

How do the mathematics of these two stats work? We’ll use a simple ratio of Perception to Camouflage. For example if the species has a Visual Perception of 5, but the target has a Visual Camouflage of 3, then the predator will see the target 5/(5+3) (or 5/8) of the time. This is using a similar concept of ratios of values as we did with speed when determining races to catch prey between predators.

Note that camouflage refers to more than just an organism that has colouration that matches it’s environment. That is an EXAMPLE of camouflage, but here camouflage refers to ALL FACTORS that can make it more difficult for an observer to sense a target.

Perception Range

Another critical limitation of perception is range. There is only so far that you can actually detect organisms at. This means that organisms will now not be able to immediately and consistently detect all prey in the entire patch at all times. Instead they’ll only have a certain range that they can detect prey in. This will greatly reduce the efficacy of predators.

In real life, senses typically are strong when close up but get weaker the farther they are used. This will be too much effort for the algorithm and we’ll just treat the strength of the sense as the same for its entire range, assuming it’s its average strength over that distance.

Sensory Zones

Using these three new traits of Sensory Perception, Sensory Camouflage, and Sensory Range, we will create a model for how senses will work. I call this system, “Sensory Zones”.

Every organism has a multitude of senses that it uses to experience its environment, and each of these has a range that it can be used at. To mathematically model how these senses detect prey, we will approximate each sense as being like a sphere that extends out from the organism with the organism at its center. Let’s say we have an example organism with senses Tactition, Olfaction, and Audition, with ranges of 1m, 3m, and 5m respectively. What would that look like in zones?

An organism can have multiple spheres, and when they do then they will overlap towards the inside, near the organism. Each of these “regions” of overlapping spheres is referred to as a Sensory Zone.

An important thing to note is that this model ONLY works when senses are approximated using spheres. Cones of vision or different shapes CANNOT work. Instead, the best way to represent a cone of vision is to originally treat it as a sphere, and then reduce the number of targets found in that sphere by a value proportional to how small the cone is relative to that sphere. For example, a cone of length X might have 5% of the volume of a sphere with radius X, which means that to calculate the targets detected using that cone of vision you calculate using the volume of the sphere and then you reduce it by 95%.

Here we can see how the zones are delineated.

Note that the innermost zone, Zone 3, represents the area where the organism can use either Tactition or Olfaction or Audition to detect prey. As you move out to Zone 2, you lose the ability to use Tactition due to its limited range, and as you move out to Zone 1 you can only use Audition to detect targets in that area.

Each zone has a detection chance. This represents the chance that the observer will notice a target in that zone. This is calculated by taking 1 minus the probability that a target will not be detected by ANY of the senses operating in that zone.

Let’s say we are looking at a prey that is 2m away, meaning he is in Zone 2, meaning only Olfaction and Audition can be used to detect him. The probability that a target will not be detected by any senses operating in Zone 2 is equal to:

Recall that PD is short for predator and PY is short for Prey. Camo is camouflage.

Let’s use some example numbers. Let’s say the predator has a perception of 1 and the prey a camouflage of 1, and the patch has no environmental camouflage. Then the math would come out to:

(1 / (1+1)) * (1 / (1+1)) = 1/2 * 1/2 = 50% * 50% = 25%

Which means that there would be a 25% chance that a given prey would not be detected by either sense in that zone. Thus the “Detection” strength of that zone is 100% - 25%, or 75%.

Updating the Algorithm

How does this tie into the overall algorithm? Well once the algorithm determines the available amount of prey, but before it determines how many the predator can catch uninterrupted (aka without interspecific competition), it must first calculate how many prey the species actually detects.

The species will only hunt the organisms it detects, and if it does not detect any more then it will spend the rest of its time reproducing. This means that there could be available prey STILL roaming around the patch, but if the predator never detected them he doesn’t care and goes straight to reproducing. Recall the current behaviour tree of all our species:

The major change here is that, when the species asks itself if any food is still available, it only considers food that is has detected. If he’s hungry but hasn’t any more food, he will think none is available and move to reproducing.

Surveying vs Detecting Prey

So after the algorithm determines the available prey for the species, it calculates how many of them are actually detected. To do this, we first calculate how many prey are surveyed (Surveyed Hunts). This refers to prey that enter one of the sensory zones of the organism at some point, but not necessarily that are detected. To calculate this, we turn to chemistry to borrow the Collision Theory equations (thanks to @tjwhale for the idea).

In chemistry this is used to determine how often particles in a confined space bump into each other, and here we’ll repurpose it to calculate how often prey “bump” into the sensory zones of the species. Z represents the collisions per m^3 per second. The term in red represents the population density of the predator, and the term in blue the population density of the prey. The yellow term represents the reaction cross section, which is equal to:

pi * (Predator's sensory zone radius + Prey's body radius) ^ 2

This takes into account how big the predator’s sensory zone is and how big (or small) the prey is. Finally, the green term can be simplified to just be the average speed of the predator and prey. For now, we’ll assume that while surveying, the predator and prey both move at half their top speeds. Rewriting this in our terminology gives us:

But recall this is just prey surveyed per m^3 per second, so we need to multiply it by the volume of the patch and the number of seconds in a month to get the total number of prey surveyed.

Finally, when you have the total number of prey surveyed by each of an organism’s sensory zones every month, you then multiply that by the detection strength of that zone to see how many of those surveyed prey are actually detected by the predator. This finally yields the Detected Hunts, which the species then uses to determine how much to hunt. After this comes the calculation of Uninterrupted Hunts, Caught Hunts, and all the rest that I’ve already explained.

Major Bugfixing and Overhauls

However, before we get to the demo, this would not be a complete part before I rant about the recent bugfixes and code overhauls I did! It seems like the changes I made in Part 7 and now Part 8 were pretty damn major, and I’ve been finding bug after bug since then. I’ve solved as many of them as I’ve found, including some pretty major ones. One of the ones I caught was a bug where species were only attempting as many hunts that they required assuming all of them would be caught, and not taking into account the possibility for failure rates. This was a pretty big bug and came from my misunderstanding of the hunting breakdown. Now the species attempts as many hunts as it needs until it gets the number of successful ones that it requires (unless constrained by time or available prey). So if a species needs 500 hunts and has a failure rate of 50% when hunting, he will spend time attempting 1000 hunts to get the 500 successes he needs.

Demo

With the new features in and the bugs ironed out, let’s see how the simulation turns out!

Modelus Specius will have tactition and olfaction as his senses. Tactition will be a stronger sense (+2 Perception, 5cm range) but olfaction will have a farther range (+1 Perception, 25cm range). His intraspecific competition rate was also increased 5x to help curb his effectiveness as a predator.

All species will have a bit of natural camouflage (+1) towards being sensed by tactition and olfaction. The camouflage to tactition could be the fact that these creatures are all very soft-bodied and thus harder to perceive touching. The camouflage to olfaction could be that they are very small and simple and do not excrete too many chemicals or pheromones into the environment. The environment also has some camouflage to these two senses (+1), representing water currents blowing away scent trails and perhaps getting in the way of touch reception.

There are of course many other senses I could’ve included, like audition and gustation and vision, but I’ll hold off on those for now to keep the model simple.

This time I ran the simulation over 100 years (note the unit is months on the bottom axis). I also increased the starting populations by a lot. All species also had their energy yield (when consumed) reduced from 100 calories to 10 calories, meaning Modelus needs to hunt 10x as much as a carnivore. Note that this is a typo on the screenshots below which still show 100 calories as the energy yield.

Starting Conditions

image




The final population values are:

  • Minimus Rex: 56,264
  • Propagatus Maxima: 31,141
  • Modelus Specius: 3,597

When running the simulation, we can see we reach an equilibrium after 2 years. Perception does definitely drag out the time it takes for major events to occur, like the food supplies running out or predators overhunting prey, but we still do see the same patterns.

The initial spike is the initial growth of the “herbivores” (Propagatus and Minimus) before the food shortage kicks in. It’s interesting to note that the big famine causes the carnivore, Modelus, to also take a hit to its population. Another interesting thing is that immediately after the big famine, Minimus Rex’s population spikes up again, but then hits a second famine and crashes back down again. I’m guessing this is because immediately after the famine Minimus is still much higher in population than Propagatus and thus has a competitive advantage in catching the glucose clouds, but as Propagatus’ population grows Minimus loses this edge.

Eventually, after 2 years, equilibrium kicks in and we can see that all three populations stabilize. We can start to see the typical predator-prey cycles taught in ecology at this point, with prey and predator populations fluctuating in response to each other. Minimus Rex is also affected by this, since he competes with Propagatus for food. It will be interesting to see how these predator-prey dynamics change once we create a more complex food-chain, with predators feeding on predators.

Although it may not look very different, this part greatly helped to curb the effectiveness of predators in the predator-prey cycle. It’s now much more difficult for a predator to completely eat all of its prey in the patch, since he would need to actually detect all of them. This part also greatly increases the ability for evolution to impact the results of hunting. Now all of the traits of perception, camouflage, and range for every sense can play a huge role in how many prey are detected by each predator in the ecosystem!

That’s all for this part! It took a lot of coding and bugfixing but it’s finally done. Stay tuned for the next post. Chances are I will dive more into perception and sensation with a sub-part if I find that there was something I missed, or I might do a special version of a Simulation Demos sub-part. Once those sub-parts are done, we’ll then move on to the next big topic!


Summary

New Performance Stats
Surveyed Hunts
Detected Hunts

New Traits
Perception, Camouflage, and Range for the following senses:

  • Tactition, Gustation, Olfaction, Audition, Vision, Magnetoreception, Thermoreception, Electroreception

Topics for Discussion

  • All comments and feedback are welcome!

Part 8.1: Playtesting

We’ve made a lot of progress in this three episode series so far. Even though we’re still on the first episode, we’ve implemented concepts of hydrodynamics, demographics, competition, predation, and perception. I’ve covered a lot of concepts so far and the algorithm is getting pretty complex, but I think that the actual simulation, and the patterns between evolutions and changes to the environment, are still predictable and intuitive.

To test how intuitive the model is, as well as a free chance for catching any bugs, and to give readers a chance to get involved, I will be setting up a “play-testing” demo on the Community Forum and try to hit three birds with one stone. Everyone who joins will control a species which will be represented by a collection of stats in the algorithm. Every round I will input these into the algorithm to see how the populations change over the millennia. Every round players will get 100 Mutation Points, and will be able to spend these on evolving their Traits. Every time a species evolves I will input the evolved stats into the algorithm and see how it changes the overall ecosystem. At the end of every round, I will display stats of how your species performed via the Performance Statistics. I will basically be acting as the computer when you actually play Thrive with the final implementation of Auto-Evo. Hopefully this gives a little taste of what Thrive will feel like when the Aware Stage has been fleshed out!

Keep in mind this is a very, very, very early play-test. Think of it as an alpha of the alpha of the alpha. It’s mostly to fix bugs, observe patterns between traits, and see how intuitive the gameplay and the provided performance statistics are.

If you want to join, the play-testing will be hosted on the community forum (where you will have to make an account) here:

Part 8.2: Updates from Playtesting

The playtesting has been going well over on the Community Forum. I’m really glad I took the initiative, because it revealed a TON of problems I had with the current algorithm. One of these problems was actually a fundamental problem with how predation was being simulated in the algorithm, and fixing it has been the reason I’ve been pretty quiet on this thread lately.

However, I wanted to give anyone who is following this an update so that they can keep up with development. Here’s a summary of all the problems I’ve found SO FAR, and how I’ve improved the algorithm to address it. I’ll save the major change regarding predation for last:

  • Problem: Traits are not inter-dependent. Yes I know this is more of an Episode 2 issue, but it was good to get the basics done now. Traits like Base Metabolism, Body Volume, Body Mass, and others were completely independent. Some traits, like Body Density, didn’t even exist (meaning they couldn’t be evolved). But what happens to your other traits when your species evolves a larger body? What if they evolve a greater proportion of their body being muscle? Realistically, a larger creature should expend more energy than a smaller one.
    • Solution: Implement a basic version of tissues. Each creature is now composed of one or more tissues, and each tissue has properties like density, metabolism, strength, etc. The two basic ones for now are Connective Tissue (uses little energy but doesn’t do anything), and Muscle Tissue (uses lots of energy but provides strength for swimming). Now, instead of telling the algorithm how much an organism weighs, you tell the algorithm the shape and dimensions of the organism, and what tissues it has and how much of each, and the algorithm itself calculates things like volume, mass, total metabolism, etc. This means that creatures can now evolve changes to specific tissues, like reducing the metabolism of a certain tissue, or increasing the strength of another tissue, or changing the ratio of the tissues.
  • Problem: Species competitiveness was being funky. After doing a few simulations, I noticed that species with lots of members but poor perception were doing surprisingly well in terms of interspecific competition with other species. Even when their perception was so weak they would detect less prey than a competitor species, they were still outcompeting that species. That’s how I realized that competitiveness was using the Required Hunts, which is the theoretical total number of a species needs to feed all of its members!
    • Solution: Make competitiveness use Detected Hunts instead of Required Hunts. This made me realize that obviously, a competitor can’t compete with you for a prey he does not see, so I changed the equation for competitiveness to use detected hunts instead of required hunts. This way, a species with lots of members but with very poor detection could potentially be less competitive than a similar species with a smaller population but much better perception skills, since the latter species is actually finding and thus chasing much more prey.
  • Problem: It was getting hard to write the code for all the species. So far I had only been writing code for the algorithm for 1, 2, or at most 3 species. But during the playtest we went up to 4 by the 2nd round, and have the potential to go even higher. And many of the parts of the algorithm require me to write out a whole set of code for EACH species that is in the patch. For example, at the end of the algorithm I have instructions (aka code) on how the computer should produce Excel population reports of each species’ performance over the simulation. With 4x more species, I have to have 4x more code/instructions. And 4x more code doesn’t lead to 4x more mistakes, it leads to 4000x more mistakes, because your brain gets overwhelmed by all the words and numbers.
    • Solution: Automate as many parts of the algorithm as possible. This was a task I had been delaying for some time now, but I finally got around to doing it. For some parts of the algorithm, I had just been procrastinating doing it. For other parts (like the part that tells it to produce the population performance reports) I legitimately could not figure out how to program it. By running the play-test though, the pressure forced me to sit down and tackle all of these tasks, and I was able to solve and automate all of them! For example, with the population performance reports code, it now loops through every species of the patch and uses the same instructions (code) to produce the reports for each one. This drastically reduces the chance for errors, and also makes it super easy to just increase the number of species in the patch and the algorithm will automatically create reports for the new species. It even knows how to name each file separately after the species it’s being created for!

These next three problems are the ones that led to me realizing the need for a major predation overhaul.

Problem: How do I display performance stats easily?

The first time I got around to posting a round of the play-test, I realized a big problem: How do I show the information clearly to the players? I am very familiar with all of the variables and how to read the population reports, and I also have access to the simulation itself so I can dissect it to see why the species perform as they do. So I am a biased sample. Additionally, I post simulation results at the end of each of my posts on the development thread for the algorithm, but those are mostly to show readers the gist of the updates to the algorithm, not to inform players for what decisions to make that will affect the outcome of their gameplay. The latter requires much more detailed and clear information.

I needed something clear and concise to be able to show the player, which they could then use to gauge where the weak-points of there species lied and what to evolve next generation. However, I could not yet think of a solution to this issue so I just sat on it.

Problem: Reproduction is still taking up waaay too much time in the month.

After doing multiple simulations with multiple species with differing traits, I noticed that there was an irrefutable pattern that hunting was far too quick and reproduction was taking up far too much time. It was usually comprising 99.99% of the lifespan of the organism. As a result, this greatly overpowered evolutions to reproduction (like mating frequency) and underpowered evolutions to hunting (like increasing swimming speed). I could not for the life of me figure out why this was the issue. After a several days of skimming the code and trying to find the issue, I thought I stumbled across something when I looked at the code for surveying/detecting prey.

If you recall from Part 8, I borrowed an equation from chemistry called the Collision Frequency Equation. I used it to calculate how often a prey “collided” with the senses of a predator. In other words, how many prey a predator surveyed per month. I realized that the equation gives you the number of collisions per second, and I was multiplying this by the number of seconds in a month. But a predator may not spend the entire month surveying! In fact, he only surveys as part of his “Hunting” life activity, and spends the rest of his time reproducing (which should’ve been 99% of the month according to the problem I mentioned before this). Additionally, I realized that the seconds that were being spent surveying were not actually being included in the time that it took to hunt, which was part of the reason that hunting was taking such a short amount of time to finish.

So I had to make the collision equation use ONLY the number of seconds that the species was spending hunting, to accurately determine how many prey were actually surveyed. This brought me to the last and biggest problem

Problem: What do I calculate first?

It was at this moment that I realized the fundamental flaw with the current design of predation. What do I calculate first?

To find out how many prey are surveyed per month, I need to know how many seconds are spent hunting. But to find out how many seconds a predator needs to spend hunting every month to feed itself, I need to know how successful it is at its hunting, which includes how many prey it surveys and detects.

Furthermore, I realized that because of the change to how competitiveness is calculated, I needed to know how many prey were detected to calculate competitiveness, but to know how many prey are detected I need to know how much time is spent hunting, but to know how much time is spent hunting I need to know how successful the species is at hunting, and to find how successful the species is at hunting I needed to know how competitive it was (among other things).

What comes first?!?! Had I discovered an impossibility in simulating evolution through purely using population math?

This realization had me considering whether to quit the algorithm entirely, because it was so fundamental to the algorithm’s design, and I simply could find a way around it.

Solution: The predation overhaul.

After a few more days of sitting on the problem, I finally figured out a solution.

The collision equation gives a number of prey surveyed by the predator every second. If you take the reciprocal of this, that gives you the number of seconds it takes for the predator to survey one prey (Let’s say 60 seconds).

But what if the predator only actually detects 50% of the prey it surveys. In that case, the time it takes for a predator to detect one prey is 60 seconds ÷ 0.5, or 120 seconds. This includes the fact that the predator surveyed two prey and only detected one of them.

Then you repeat this for the multiple steps of hunting. If a predator only wins 50% of chases, then you divide 120 seconds by another 0.5. In fact, you keep dividing for every step of the hunting process that involves a success rate (like combat, interspecific competition, intraspecific competition, etc.). Once you’ve divided by all of those success rates, you’ll have the overall time you need to spend hunting to get one successful, completed hunt. Then you look at the time you have available in a month, and you calculate how much time you would have to spend hunting to get the number of successful, completed hunts you need to feed yourself. If there is not enough time in the month, or your prey runs out, or you finish feeding yourself, then you stop hunting and switch to reproducing. Then, once you have the final number of successful hunts you are able to perform, you use your success rates to work backwards and find out how many hunts you attempted to get that many successful hunts. This solves the problem of not knowing what to calculate first!

And as I thought of the steps of the hunting process, I realized that I could now calculate a time for each step of the hunting process. It takes time to detect, and if you successfully detect it takes time to chase, and if you successfully chase it takes time to defeat the prey in combat, etc. Additionally, the predators would spend time on both successful and failed hunts (which is something I realized I had not been calculating earlier, only the time spent on successful hunts). And even from among the failed hunts there would be different levels of how early it failed. One hunt could fail right at the get-go because the predator does not detect him, while another hunt could have the predator detect the prey but fail to catch the prey. So I also had to calculate the different amounts of time spent on the different types of failed hunts. The solution to this is that the species should now spend a LOT more time hunting, and thus a lot less time reproducing, and have much more realistic behaviours, solving the second problem.

Then I realized that each of these success percentages are perfect statistics to show to a player. Percentages are a very easy number to think about and use to represent values, and can easily convey how well a species is performing. Thus a species’ performance in hunting can be simply displayed by its success rates (as percentages) in each of the steps of hunting. Additionally, all of these percentages can be multiplied together to produce an Overall Hunting Success percentage, to give you an idea of your overall success as well. Using these different percentages, a player can more easily identify “Oh! My chase success is very high, which means I’m already very good at catching my prey and don’t need to increase my speed even more. But my detection success is very low! I should evolve better perception!” In addition to the success rates of each step, you can also show the time spent on each step, to give a the player a better idea of what they can evolve to improve their survival. This solves the third and final problem of how to show the performance information clearly to the player!

Conclusion

That’s an update on the progress I’ve made on the algorithm since I started the play-testing. The first few solutions have already been implemented, but the predation overhaul will be major and will take some time. I’m predicting that it could take anywhere from 1-2 weeks to fully finish and fix all of the bugs. In the meantime, I may not post another update to this thread until I finish the overhaul. I also may pause the play-test until I finish the overhaul, so I can use the overhauled algorithm for Round 4. But if the overhaul proves to be taking too long, I’ll just go ahead with using the old code for Round 4.

All in all, the play-test has proven to be a great success! It’s helped me catch a lot of major bugs and design flaws, and I hope has given the players a good chance to experience the excitement of the competitive race of evolution, and how that could feel in Thrive!

3 Likes

Impressive!

Hopefully the algorithm will come together at some point so that we can include in the game, instead of just the random population changes that are standing in for auto-evo currently.

1 Like