Coding "Empire" Cellular Automaton in C++/SFML

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so a few days ago I came up wearing two cellular automaton as a sort of a twist on predator and prey and I call it Empire so how does it work well let's get into the rules as always the world is made out of a grid of cells each one of these cells represents one person and each one of these people hold some data their age their strength their reproduction value I'll get to that in a second and lastly a couple of booty ins like whether they're alive or dead or not or whether they're diseased or healthy each person belongs to a different colony where the different colonies can be told apart by the different cell colors in each step of the simulation each person will try to move through a random spot around them if they try to move on to water then they will just stay put if they try to move on to grass then they will move there successively and lastly if they try to move on to a spot where someone from a different color knee is already standing the new tee people will fight and the one of the highest strength value will win and the other person will die will so a nice depth of simulation the age and B production value of each person will increase if the age of the parson is higher than their strength then the person will die due to old age when their reproduction value reaches a certain threshold they will give birth and then their reproduction value resets back to zero when this new person is born they will inherit some values from their parents whether the parentless diseased or not and the parents strength value however there's also a slight chance of mutations so a newborn baby might get their strength value slightly increased or slightly decrease from the parents value and they may also contact a disease which is how the disease actually enters the simulation and given a person's already diseased the knee disease has a 50% chance for spreading when people tried to move on to ask where was someone from the same colony at the start of the simulation small colonies are placed in random spots around the world and the idea is that you will eventually be left with just massive colonies aka empires so without any further ado less kin to this to start off I simply wanted to get a blue and green map of the earth where Green is land and blue as a sea so what I did I googled black cod map and I colored it in using paint.net the colors are actually very important as I'll be reading the pixel colors are certain location in the image to determine if a person can actually be there or not and I feel the picture actually turned out pretty nicely so anyways into the code as always the first step is to get something drawing and seeing is nothing new was really going on here just copy and pasted the rendering code from the predator and prey simulation to save time so yeah nothing too exciting for now so the next thing I want to do is to get the roadmap drawing onto the window and this was as simple as using an SML rectangle and then just you know rendering onto the window and again nothing too exciting happening so far but now that all my visuals are ready it was time to actually begin implementing my simulation so to begin I created the class called person which simply hulls today to mentioned at the start of the video for each person are then create an array structure to hold all these people where one person is equal to one pixel on the window the next thing to do was to create colonies and scatter them around the world at this point the different colonies were stored as a color in an array of size ten each person will support an integer for their colony ID which actually refers back to the index of the colony array this will make easy to set the pixel colors as like in your sleep through all the people and set the pixel color by looking up the color in the colony array using the person who's calling me ID for example let's say we're looping through the people of the world using a nested loop us see in the top right this picture we have reached the point where x equals 10 and Y is equal to 500 so we get the colony ID of the person at 10500 and let's just say his colony ID is 2 and so we set the pixel color at 10500 to be pink because as you can see by the colony around the left there the colony at index 2 is pink so now that people in colonies were set up it was now possible to please some people around the world to do this a random location on land has chosen to each colonies who are originated through and then 50 people were placed for each colony in an area around the respective origin points the very small colonies of people can be seen here to help you see them I'm circling number of my mouse singers there but they're barely visible right now and now it was time to implement the base rules people moving Overland people reproducing and people dying of old age furthermore the basic strength altering mutations were implemented for when the people will be produced there were two mutation types a small mutation and a large mutation where the small mutation is more common than the large one the small mutation alter the Charles Street value very plus minus 2% while the large one changed it by plus minus 20% disease and fighting was not implemented just yet anyways as you can see it works exactly as I expect it to the people are moving around it looks really cool and they're dying straight away so obviously something wasn't right now it was quite likely to be the mutations so as a test I commented the house so every child was as strong as their parents and well the result is quite possibly one of the coolest things I have ever seen but anyways regardless of how cool it looks it was cleared the mutations were to blame and so I adjusted the mutation alteration value so that was the bias towards making a child stronger rather than equal chance of making a child stronger or weaker as well as doing this I also made it so the colors of the different colony types are more contrasting so you could tell them apart more easily as you can see the people are not dying right away anymore which is good and their colors are a bit better the next one today was very important the fights between the colonies this was really as simple as a couple of if statement was checking the colony types and the strength value between the people and here's how it looks I just heard you tube compression doesn't ruin this clip has this potash she looks quite cool anyways here is how it looks it's about 40 or so minutes later and I noticed something rather interesting on the bottom left you can see the different colonies statistics how many people are in each clone knee and the average street value of each one take a look at colony 6 which is the people isolated in Australia now compared to other colonies their strength value is extremely low in contrast look at colony 10 of whom are scattered and more around Asia and Eastern Europe these people have a very very very high strength value and this is interesting because it means this simulation sort of turned into a real-life evolution simulator where the very strongest of its colony is surviving believing the average strength values for those in war extremely high mean more the solitude colonies such as too in the American continents and colony six in Australia had very low string values and this is because they didn't eat high strength to survive seeing as there are no France and so they didn't evolved have those traits so yeah that's kind of interesting I guess but anyways I was interested to see how it looks if Europe so here's what Europe looks like and I was also curious to see how it would look with just various random shapes unfortunately I noticed a huge mistake in my code when people tried to move to places where someone of these same colony was already standing they would move there anyway effectively meaning loads of people were just dying and when I fixed this overpopulation clearly became a massive problem and so I think it was about time to finally implement disease as I said earlier in the video to ceases sometimes creators when a child is born due to mutations something I did not mention was the effect of disease so what disease does is it effectively half the strength value of the infected people causing them to die of old age a lot faster and well hopefully this would solve the overpopulation problem and here's how it looks unless you can see it works perfectly but unfortunately well actually not perfectly it worked a little too well as you can see in Eastern Europe and Asia it's looking very patchy of different colonies in 20 of each other which just doesn't look right that's the way to combat this I tried to change how disease works a little bit rather than making them lose their strength I made it so they instead aged a bit faster and here is the final result and I can proudly say it's working exactly as I'd hoped it would looks like colony 5 is doing a pretty good job of taking over America and I can say colony 8 is doing a pretty good job of taking over Asia in Europe in Africa and that's another thing that's interesting if you have got this strength value of colony 5 now it's gone down dramatically because there's no fraction anymore so yeah I think that the simulation ended up being pretty interesting so that's it I guess and I want to take a moment to thank my patreon supporters Thank You snappiest so create Thank You Stanley Morris Thank You synthetic aka Haydn Thank You Timothy Gibbons and Thank You alchemic so anyways there it's actually quite a lot more that can be done here for example the person has very high strength then they could have the ability to swim across oceans or maybe a dirt so there's multiple more deadly disease types so yeah I might make you part two of this eventually if you want me to anyways once again thank you for watching and you bye [Music]
Info
Channel: Hopson
Views: 281,514
Rating: undefined out of 5
Keywords: Unity, Unreal, Engine, MineCraft, How, To, Tutorial, C++, SFML, Programming, Game, Dev, Sky, does, minecraft, pewdiepie, Multithreaded, tut, how, to, make, games, android, ios, apple, lwjgl, java, C#, rust, language, do, learn, program, game, for, cellula automaton, cellula, auto
Id: 3mgGQR6oGxI
Channel Id: undefined
Length: 9min 23sec (563 seconds)
Published: Mon Aug 28 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.