Package: dinolemma
Dinosaur DilemmaThis is the dinosaur dilemma, my first attempt at a simulation. It will involve
characters, interactions, and variables that control those interactions.
The characters will interact in a basic world and at the end, we will be
interested to know how they turned out (evolved). You can see a verbose
simulation runhere,
or a less verbose run below:UsageInstallYou can install from pip, or directly from the repository here.pipinstalldinolemmaorgitclonehttps://github.com/vsoch/dinosaur-dilemmacddinosaur-dilemma
pythonsetup.pyinstallIf you want to use the GUI you will need pygame. Any of the following will work.pipinstall.[game]pipinstalldinolemma[game]pipinstallpygameCommandYou can run a text simulation (with defaults) from the command line:$dinolemmarun
Todayisday80inthewinterseason.
Thereare5dinosaurs,and13avocadotrees.
Thetemperateis12°F,humidity0.33or a (more fun) graphical simulation (press enter to cycle through days):dinolemmaguiThe gui takes the same input parameters as the run.dinolemmagui--help
usage:dinolemmagui[-h][--ndinosNDINOS][--ntreesNTREES][--grid_sizeGRID_SIZE]optionalarguments:-h,--helpshowthishelpmessageandexit--ndinosNDINOSthenumberofdinosaurstosimulate.--ntreesNTREESthenumberofavocadotreestosimulate.--grid_sizeGRID_SIZEthesizeofthesquaregrid,inunits(onedimension).If you want a more interesting simulation, try adding a lot more dinosaurs
or trees!dinolemmagui--ndinos100--ntrees30What you'll likely see given those ratios are that the dinosaurs (purple) eat one another
(or starve) and then the trees (green) grow to take up the game board.PythonYou can run a simulation from within Python, either using the defaults:from dinolemma.game import DinosaurDilemma                              

simulation = DinosaurDilemma()                                          
Today is day 13 in the summer season.
There are 1 dinosaurs, and 14 avocado trees.
The temperate is 59°F, humidity 0.43or by setting any of the variables (number of dinosaurs or trees, size of grid, etc.)DevelopmentThe way that I'm thinking about this project is in stages.Stage 1: Stateful1. EnvironmentThe first thing to design is the environment, meaning a stateful base that has a set of variables (e.g., temperature, humidity) that will vary
on some regular increment and then influence the entities that live in it downstream. For example, a base environment might
be defined by a season and day that leads to a particular temperature that has downstream influences on the organisms that live
in it. If my environment has a function to cycle through a unit (e.g., a day) then I can update it's state, and
then update the entities in it depending on the new state.2. EntitiesOnce the environment is defined, the next level of stateful objects must be defined, the entities that live within
the environment. The entities should first update themselves based on the changed environment, and then interact.
Interaction comes down to each entity changing location on some grid, and if the location is in the vicinity
of another organism, then the interaction occurs. I thought about whether I wanted all entities to move (and then
interact) versus allowing them to interact as they move, and I chose the latter. The reason is because
we would allow for multiple interactions for any given entity in one turn, and that's more interesting.
To be fair, I have to ensure that the order of movement is randomized. And notably, avocado trees cannot
move.3. InteractionsEvery entity must have defined rules for interaction with other entities. When all entities
in the simulation change location, those that are within some vicinity of one another
are allowed to interact. Interaction can further influence the state of the entity,
or even lead to creation or destruction of said entity.At the end of the design of stage 1, we will have developed essentially a text based, stateful simulation.
We will be able to run it with some set of starting conditions, and then observe the interactions
over a particular number of time steps (days) and some final outcome.Stage 2: GraphicalOnce the stateful simulation is designed, we should strive to visualize it. This
means (possibly) re-implementation in a browser based language that can render
objects on a canvas or via the dom (d3.js). We would want to be able to run
the same text based simulation, and watch it.Stage 3: LiveThe stateful approach works for early design, but what we would really want is essentially
a bunch of entities that are co-existing in an environment, and then reacting to one another.
I think we could try to emulate this with something that looks more like a bunch of
objects that can emit and subscribe to one another's events, and then know how to
respond.CharactersDinosaursDinosaurs are the main character in this world, and we initialize the world
with some number. Specifically, a dinosaur wanders around and has the following
attributes:hunger: each dinosaur is hungry, and gets more hungry as the simulation progresses. If the dinosaur enconuters a ripe avocado, he will eat it and the hunger subside. Each dinosaur has a slightly different threshold for deciding to eat.size: each dinosaur has a randomly set size. A larger dinosaur is obviously requiring more food than a smaller one, and a larger one is also advantaged to be able to eat a smaller dinosaur, if desperate.disease: if a dinosaur is hungry and eats an avocado or another dinosaur with a disease, he can get sick. A sick dinosaur moves less, and thus has a greater chance of dying due to hunger or even being eaten by another dinosaur.gender: A dinosaur has a 45% change of being male or female, and a 10% chance of being a hybrid, which can reproduce without a mate. Only mature dinosaurs (greater than or equal to 80% of their full adult size) can reproduce, and with every interaction, there is only some small percentage of it.The dinosaur has the following actions:move: for each turn of the game, the dinosaur moves, and then interacts with whatever he finds in his new spot.eat: a dinosaur can choose to eat an avocado, or even another dinosaur, depending on the size and level of hunger.sleepa dinosaur can choose to sleep (with some probability) if he is sick to increase the chance of getting better.reproducea dinosaur that encounters another dinosaur (mature of the opposite gender) has some percent change of reproduction.AvocadosAvocados are grown on trees that are scattered in the environment. For any given tree, it must be a certain age to produce avocados, and once it's old enough, it can only generate a certain number of avocados over a period of time. This gives us the following attributes:mature: a mature tree cannot be eaten by a dinosaur, and can produce avocados. An immature tree can be eaten entirely and removed from the game.avocados: once a tree is mature, it holds a certain number of avocadosdisease: any tree can get a disease with a small probability. Getting a disease puts the tree at risk for dying, or getting a dinosaur sick.VariablesFor each of the scenarios above, there must be probabilities generated within some range (set when the game starts) and then allocated to randomly generated entities, which are also randomly placed on a game board of some size.DinosaursThe game starts with a certain number of dinosaurs (number of total dinosaurs), with the following randomly set values (within some ranges):sizehungerThe game itself (an instance of DinosaurDilemma) underdinolemma/game.pycreates
some number of dinosaurs in the following way:fromdinolemma.dinosaursimportDinosaursdinosaurs=Dinosaurs()dinosaurs[14dinosaurs]fordinoindinosaurs:print(dino.name)persnickety-muffinpodusloopy-tacopodusgassy-poodledocusfrigid-nalgasasaurushanky-dogdocusdirty-blackbeanpodusastute-truffleusloopy-knifeuschocolate-noodleisauruspsycho-chipiraptormuffled-lizardusstinky-underoosdocusrainbow-cattywampusisaurusbuttery-saladiraptorEach is guaranteed to have a unique name, and we check that there are enough
spaces on the game board to support the dinosaurs and trees created. We
can also grab a random dinosaur:dino=dinosaurs.random()dino.name'bricky-eagleraptor'AvocadosThe game also starts with a certain number of avocado saplings.fromdinolemma.avocadosimportAvocadoTreestrees=AvocadoTrees()fortreeintrees:print(tree.name)hanky-egg-treegoodbye-poo-treereclusive-sundae-treemuffled-squidward-treeor grab a random tree:tree=trees.random()tree<dinolemma.avocados.AvocadoTreeat0x7f25347e7860>