Coding Adventure: Simulating an Ecosystem

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Do you have any idea how I would be able to do something like this for myself and do you think it would work on a MacBook Air?

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/DanVan06 πŸ“…οΈŽ︎ Aug 08 2019 πŸ—«︎ replies

It’s amazing. I definitely want more of this!

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/Nopinopa πŸ“…οΈŽ︎ Aug 08 2019 πŸ—«︎ replies

when your favorite youtuber is inspired by your other favorite youtuber.

πŸ‘οΈŽ︎ 1 πŸ‘€οΈŽ︎ u/Iseenoghosts πŸ“…οΈŽ︎ Aug 16 2019 πŸ—«︎ replies
Captions
Hello and welcome to a new coding adventure today I'm going to be simulating a simple ecosystem an idea which was inspired by this really cool video from the channel primer I Started by generating a little map with water tiles that creatures which has something to drink and land tiles for them to move around on I also added some trees. It's decorations and obstacles and then some little plants is a food source Next I needed a creature. So I made a crude little bunny out of some cubes and placed him into the world He seemed happy enough. Just hopping around but of course I wasn't going to let him have such an easy life I gave him hunger and thirst so he'll need to find some water soon or else dying Fortunately for him there's some nearby so he's hopping over to that and having a drink There's also a plant over this he's going to head over to that and gobble it up Now he's thirsty again So back to the water this by the way is his sensory radius outside of which he's blind So he currently he's just hopping around randomly trying to find some food, but now that he spotted that plant up there He's gonna head directly over to it The next thing I added was an urge to reproduce Currently that urge is stronger than the bunny's hunger thirst. So he'll go searching for a mate He's not likely to have much luck value on account of being the only rabbit in existence So I'll add in a female bunny and let's see if they get together They're both searching and it looks like they've spotted one another. You may want to avert your eyes for this All right, it's safe to look again The bunny is not pregnant - so in just a few moments we should be able to welcome some new little creatures to the world These little fellas will take some time to grow up during which their speed and sense of sight will develop So right now they're of course particularly vulnerable in the simulation and female bunnies actually have a gene which controls how long they're pregnant for if That duration is short They can obviously have offspring more frequently, but the offspring will be more underdeveloped and have less of a chance of surviving to adulthood There are a few more genes one for sensory distance and one for reproductive urge Which I've described already, then there's one for speed along the rabbit to move faster at the cost of getting hungry and thirsty more quickly Finally for males only there's desirability which here is expressed by having redder fur So looking at the code for a second when a male rabbit spots a female who's also looking for a mate He will send a signal to her and the more desirable he is the higher chance that she will accept his advances If she rejects him He'll add her to his mental list of unimpressed females and won't approach her again until he's forgotten about it a little while later Now when two rabbits mate the offspring will inherit these genes from their parents in the code You can see that each gene will be randomly selected to come from either the mother or the father on top of that There's a small chance for each change in mutate which will increase or decrease its value by a little bit All right. I'm going to start the simulation out with 300 rabbits and let's see what happens. So The population first shoots up with the first wave of babies, but the majority of them aren't very good at surviving So the numbers quickly decline At this stage with just around a hundred rabbits in existence. They're at a high risk of extinction Several times when I ran the simulation they got unlucky at this point and just died out But this time they seemed to be hanging on tenaciously and with each new generation Becoming more adept at surviving after about 20 minutes of simulation. The population was over 1,400 about 2600 rabbits died from hunger the way and over 4,000 from thirst Let's have a look at what happened to the jeans of this time The average gestation duration was quite steadily indicating that in this environment. It was better to have fewer but stronger offspring The sensory distance rose rapidly as those too short-sighted to reliably find food and water were weeded out The reproductive urge initially dropped but I guess as the senses of the rabbits improved it became less risky to spend more time searching for a mate Next this speed but apparently moving faster wasn't really worth the cost and Finally desirability which fluctuated a bit for some reason before finally heading upwards. I Then thought it would be interesting to introduce a predator So I made something that hopefully looks at least a little bit like a fox and told it to move towards rabbits and eat them These rabbits are basically just sitting ducks though So I made the Fox after work a little harder for his meal by making them flee from him So going back to where we were in the simulation I added in an initial population of 10 foxes and let it continue running At first things seemed to be going okay But the number of foxes grew rapidly since they're at the top of the food chain, and they hunted the rabbits to extinction Then they realized they'd made a terrible mistake and stuff to death With the introduction of the Foxes speed of course became much more valuable to a rabbit survival the other traits though remained roughly the same I tried running the simulation again this time with the foxes being there from the outset as The foxes became more numerous the rabbits were nearly hunted to extinction, but they managed to make a huge comeback Unfortunately this led to an explosion in the Fox population as well. The rabbits went extinct and the foxes followed shortly thereafter What I found interesting about this run is that in the presence of the foxes the rabbits evolved to have an extremely high reproductive Urge, I guess if they didn't find a mate quickly they might be killed by a fox and not have the chance to pass their genes on the Gestation duration stayed low this time a favour and quantity of offspring over quality. Here's how the other traits turned out in case you're interested I'm rather sad that I couldn't get the rabbits and foxes to co-exist for very long The only time the Foxes didn't hunt the rabbits to extinction Was once when they weren't able to find the last remaining group of bunnies and starve to death Those bunnies that lived happily ever after though. So I guess it's a happy ending in any case I hope you've enjoyed this coding adventure. Make sure to have a look at the others in the series if you did And until next time Cheers
Info
Channel: Sebastian Lague
Views: 1,993,208
Rating: undefined out of 5
Keywords: evolution, natural selection, ecosystem, simulation, gene, coding, programming, survival, Unity
Id: r_It_X7v-1E
Channel Id: undefined
Length: 6min 40sec (400 seconds)
Published: Mon Jun 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.