Natural Selection Simulation
- 12 Devlogs
- 17 Total hours
I am making a simulation of natural selection in Godot.
I am making a simulation of natural selection in Godot.
I’ve been a bit lazy, but progress on procedural generation is coming along well. I finished it and tweaked it until I got a result I liked (there was more mathematics that I had to do, like I had to use the pythagorean theorem to figure out the distance away from the center and subtract that to ensure that edges are ocean). The way it works is by first creating ocean, beach, fertile land, and mountains from noise, then I use moisture and temperature to determine the biome. Temperature is calculated by getting the latitude, subtracting the elevation (to make higher areas naturally colder), and then a bit of noise is added on top of all of that. Moisture works similarly, minus the latitude part. I also started working on vegetation; see those savanna trees? But I do have to create plants for each biome (or the creatures will have nothing to eat) which I am too lazy to do (as you can see I just made a savanna tree), I do not know what I’ll do for that. There’s so much art I have to make; I’ll have to make the animals and all of the plants. I’m planning to code a bunch of traits gained from animal appearance as soon as I put in the work to create the animals, which will be really difficult to do. I’m finally moving away from MSFT Paint though!
I don’t have much to display at the moment, I’ve been optimizing the code (for example, I used for loops to repeat the same process with different variables used for graphing instead of having separate code for each variable to significantly shorten the code) and I’ve started working on biomes. Since it has been a while since I have last posted a devlog, I’ll post one, and since I have to attach a screenshot or video, here’s an demonstration of natural selection in my game. You can clearly see the memory trait rose a lot and certain traits balanced out at a certain level (the images are a bit low quality but the values tracked are speed, sight, metabolism, mutation, memory, and population).
I did a bit more work on the windows. Now you can select which stats to track (only sight and speed for now, but I’ll fix that) and you can track up to 2 stats (but it doesn’t take long to change how many stats you can track), and you can change the colors. In the video, I am tracking the average speed and sight (note that the graph is measuring not the value, but the change in value; sight is twice as large as speed by default). I also demonstrated some of the features of the windows in the video which I forgot to show in the last one.
I haven’t posted much because there wasn’t a lot to display or show that I’ve gotten something to work. Anyway, I coded a mutation trait which modifies how much a child’s traits can change (I noticed something pretty cool; when setting the mutation value super high like 1, it almost always drops back down to around 0.3). Here’s how mutation works: you get a child’s genes by calculating the average of the 2 parents genes plus that same number multiplied by mutation value. With a mutation of value of 1, the highest amount genes can change is double the original value. And most noticeably, I started working on UI; I started making charts that display certain traits. It’s nowhere near done, but it is coming along quite nicely. In the video attached, a chart is tracking the average speed value of the population. I didn’t show in the video, but you can drag the windows around, but that’s about it; I can only manually set the tracked value in code and drag windows around, they don’t have much features. A lot of the work I can’t really show; I was working on tracking, originally it was mostly for debugging, but now I can actually display those values with the graphs I am coding. Sorry that the video’s a bit long, Haaland scored a goal against Brazil and I forgot I was recording; I had to see the replay. He also scored a second one while I was typing this devlog. Go Norway (I’d root for Russia but they got suspended)!
I didn’t do much coding, and the game still needs a lot of work, but I have reached a great milestone! The game naturally selects traits! I added some statistics and a new memory trait because the creatures could just set off on a journey and remember the exact position down to the decimal places of the last food and water it saw, so I fixed that and added a timer which wipes the memory of the food/water position once it times out. The default traits are: 75 speed, 150 sight, 1 metabolism, and 7 memory. The average traits after running the simulation for some time: 65 speed, 125 sight, similar metabolism, and 10 memory. This result is pretty consistent with the exact plant and water setup in the image, but if I change it to a sparser environment, I saw speed go up by 10, sight go up by 5, metabolism stay the same, and surprisingly, despite being a trait with no negatives implemented yet, memory go down by 0.25. I guess memory doesn’t matter if you are fast enough and see well.
I’m a bit stuck. I don’t really like the gene system so I decided to code traits as numbers, but that needs a lot of balance and tweaking to properly implement, and all of this work is a bit overwhelming. I might take a break from this project for a few days.
I did a LOT of debugging. Fixed the last bug and numerous more that caused things like food not giving any hunger, genes getting incorrect effects, and more. I also changed how metabolism works and nerfed it. Now, Mm = 0, mm = -1, and MM = 1. These values are “intensified” by the I/i alleles. These work the same way as metabolism worked before, but now the values can be negative leading to efficient but low capacity creatures. I had to nerf it because capacity was becoming negative and creatures were getting infinite food.
I restored my work and added a new trait; metabolism. mm is default metabolism; 10 hunger/thirst capacity and normal depletion. Mm is higher metabolism with 12-15 capacity and increased depletion. MM is highest metabolism with 13-22.5 capacity and even more increased depletion. I also made growth smooth instead of how previously juveniles instantly became adults. There’s also a strange bug which I’m trying to fix. Sometimes, the metabolism genotype becomes part of the other genotype. “Qq” “Vv” “Mm” is default, but after a few generations, you start seeing things like “Qq” “vm” “Mm” and eventually, things like “mm” “MM” “Mm”
All of my progress since my last devlog is lost :( I’ll have to recode all of it, but it isn’t that much work. Probably happened because I set up Git incorrectly or something.
I coded limited resources and juvenile creatures. When creatures spawn, they have to wait 15 seconds until they can mate (so they don’t start mating right out of the womb like last time), and now when food is eaten, it regrows after 7 seconds. I’ll probably add more genes next time, or maybe even expand the map and add new biomes and plants (which would be really easy because I can just drag the food scene onto any plant and the plant now has fruits that grow and regrow).
I added genetics and reproduction! You can see in the output that each new organism has 2 genotypes, one for Q/q (short for quickness, didn’t want to use S because it’s a common letter and I might need it later idk I forgot), and one for V/v (short for vision) alleles (probably using all the wrong vocabulary). These genes directly affect speed and vision (with some slight randomness) and speed and vision also affects hunger and thirst depletion, meaning that being fast and seeing well has a tradeoff. I really need to code limited resources and I really need to code juvenile creatures (they’re mating at birth 😭😭😭). Maybe I could even make something like eggs?
The output got cut off in the image. Here’s what it’s supposed to say:
Genetics: [“Qq”,“vv”] Speed: 92.3979906001719 Sight: 150
Genetics: [“qQ”,vv”] Speed: 83.9082190561058 Sight: 150
Genetics: [“QQ”,“vV”] Speed: 142.633334008872 Sight: 171.81141852858
Genetics: [“QQ”,“vv”] Speed: 110.227173121233 Sight: 150
…
Finished coding a lil guy with some slight (heavy emphasis on slight) survival instincts. You can watch his hunger and thirst go down in the Godot output and watch him race towards food and water (oh wait forgot to add a hungry state he just runs after water, oh well, I’ll just add that next dev log). I just started working on this, so basically everything’s a prototype. And I also had the bright idea of making prototype assets in MS Paint, that’s why the art looks so beautiful and astounding. I have a lot of ideas for the future; I’ll probably code genes and reproduction next, but I also have a ton of ideas for the future, like Perlin noise generated terrain (like in my last project), adding natural selection for plants, multiple biomes, several species, etc… Who knows how this project will turn out? Anyways, it’s 10 PM and I have spend over an hour coding, so I should definitely go to sleep. Or should I? I reallyyyy want to code genes and reproduction.