{"id":17030238,"url":"https://github.com/vsoch/dinosaur-dilemma","last_synced_at":"2025-04-12T12:11:54.054Z","repository":{"id":57418202,"uuid":"233279823","full_name":"vsoch/dinosaur-dilemma","owner":"vsoch","description":"attempt at a fun simulation to evolve avocado eating dinosaurs","archived":false,"fork":false,"pushed_at":"2020-01-25T17:00:24.000Z","size":11019,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T06:51:12.198Z","etag":null,"topics":["avocados","dinosaurs","simulation"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vsoch.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-11T18:41:03.000Z","updated_at":"2023-07-06T09:02:48.000Z","dependencies_parsed_at":"2022-09-03T09:51:17.056Z","dependency_job_id":null,"html_url":"https://github.com/vsoch/dinosaur-dilemma","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fdinosaur-dilemma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fdinosaur-dilemma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fdinosaur-dilemma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fdinosaur-dilemma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vsoch","download_url":"https://codeload.github.com/vsoch/dinosaur-dilemma/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103869,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avocados","dinosaurs","simulation"],"created_at":"2024-10-14T08:05:21.849Z","updated_at":"2025-04-12T12:11:54.033Z","avatar_url":"https://github.com/vsoch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dinosaur Dilemma\n\n[![PyPI version](https://badge.fury.io/py/dinolemma.svg)](https://pypi.org/project/dinolemma/)\n[![GitHub actions status](https://github.com/vsoch/dinosaur-dilemma/workflows/ci/badge.svg?branch=master)](https://github.com/vsoch/dinosaur-dilemma/actions?query=branch%3Amaster+workflow%3Aci)\n\n![https://raw.githubusercontent.com/vsoch/dinosaur-dilemma/master/img/dinosaur-dilemma.gif](https://raw.githubusercontent.com/vsoch/dinosaur-dilemma/master/img/dinosaur-dilemma.gif)\n\nThis is the dinosaur dilemma, my first attempt at a simulation. It involves\ncharacters, interactions, and variables that control those interactions.\nThe characters interact in a basic world and at the end, we are\ninterested to know how they turned out (evolved) given the parameters of the simulation. \nYou can see a verbose text simulation run \u003ca href=\"https://asciinema.org/a/293693\" target=\"_blank\"\u003e\u003cimg src=\"https://asciinema.org/a/293693.svg\" /\u003ehere\u003c/a\u003e,\nor a less verbose (text) run below:\n\n[![asciicast](https://asciinema.org/a/293703.svg)](https://asciinema.org/a/293703)\n\nA gif of the graphical interface to run the same simulation is shown above, and a static image below!\n\n![https://raw.githubusercontent.com/vsoch/dinosaur-dilemma/master/img/dinosaur-dilemma.png](https://raw.githubusercontent.com/vsoch/dinosaur-dilemma/master/img/dinosaur-dilemma.png)\n\n## Usage\n\n### Install\n\nYou can install from pip, or directly from the repository here.\n\n```bash\npip install dinolemma\n```\nor\n\n```bash\ngit clone https://github.com/vsoch/dinosaur-dilemma\ncd dinosaur-dilemma\npython setup.py install\n```\n\nIf you want to use the GUI you will need pygame. Any of the following will work.\n\n```bash\npip install .[game]\npip install dinolemma[game]\npip install pygame\n```\n\nI find it very appropriate and lovely that the ubuntu icon for the pygame \nwindow is a tiny dinosaur :)\n\n![https://raw.githubusercontent.com/vsoch/dinosaur-dilemma/master/img/pygame.png](https://raw.githubusercontent.com/vsoch/dinosaur-dilemma/master/img/pygame.png)\n\n### Command\n\nYou can run a text simulation (with defaults) from the command line:\n\n```bash\n$ dinolemma run\nToday is day 80 in the winter season.\nThere are 5 dinosaurs, and 13 avocado trees.\nThe temperate is 12°F, humidity 0.33\n```\n\nor a (more fun) graphical simulation (press enter to cycle through days):\n\n```bash\ndinolemma gui\n```\n\nThe gui takes the same input parameters as the run.\n\n```bash\ndinolemma gui --help\nusage: dinolemma gui [-h] [--ndinos NDINOS] [--ntrees NTREES]\n                     [--grid_size GRID_SIZE]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --ndinos NDINOS       the number of dinosaurs to simulate.\n  --ntrees NTREES       the number of avocado trees to simulate.\n  --grid_size GRID_SIZE\n                        the size of the square grid, in units (one dimension).\n```\n\nIf you want a more interesting simulation, try adding a lot more dinosaurs\nor trees!\n\n```bash\ndinolemma gui --ndinos 100 --ntrees 30\n```\n\nWhat you'll likely see given those ratios are that the dinosaurs (purple) eat one another \n(or starve) and then the trees (green) grow to take up the game board.\n\n### Python\n\nYou can run a simulation from within Python, either using the defaults:\n\n```\nfrom dinolemma.game import DinosaurDilemma                              \n\nsimulation = DinosaurDilemma()                                          \nToday is day 13 in the summer season.\nThere are 1 dinosaurs, and 14 avocado trees.\nThe temperate is 59°F, humidity 0.43\n```\n\nor by setting any of the variables (number of dinosaurs or trees, size of grid, etc.)\n\n## Development\n\nThe way that I'm thinking about this project is in stages. \n\n### Stage 1: Stateful\n\n#### 1. Environment\n\nThe first thing to design is the environment, meaning a stateful base that has a set of variables (e.g., temperature, humidity) that will vary\non some regular increment and then influence the entities that live in it downstream. For example, a base environment might \nbe defined by a season and day that leads to a particular temperature that has downstream influences on the organisms that live\nin it. If my environment has a function to cycle through a unit (e.g., a day) then I can update it's state, and\nthen update the entities in it depending on the new state.\n\n#### 2. Entities\n\nOnce the environment is defined, the next level of stateful objects must be defined, the entities that live within\nthe environment. The entities should first update themselves based on the changed environment, and then interact.\nInteraction comes down to each entity changing location on some grid, and if the location is in the vicinity\nof another organism, then the interaction occurs. I thought about whether I wanted all entities to move (and then \ninteract) versus allowing them to interact as they move, and I chose the latter. The reason is because\nwe would allow for multiple interactions for any given entity in one turn, and that's more interesting.\nTo be fair, I have to ensure that the order of movement is randomized. And notably, avocado trees cannot\nmove.\n\n#### 3. Interactions\n\nEvery entity must have defined rules for interaction with other entities. When all entities\nin the simulation change location, those that are within some vicinity of one another\nare allowed to interact. Interaction can further influence the state of the entity,\nor even lead to creation or destruction of said entity.\n\nAt the end of the design of stage 1, we will have developed essentially a text based, stateful simulation.\nWe will be able to run it with some set of starting conditions, and then observe the interactions\nover a particular number of time steps (days) and some final outcome.\n\n### Stage 2: Graphical\n\nOnce the stateful simulation is designed, we should strive to visualize it. This\nmeans (possibly) re-implementation in a browser based language that can render\nobjects on a canvas or via the dom (d3.js). We would want to be able to run\nthe same text based simulation, and watch it.\n\n### Stage 3: Live\n\nThe stateful approach works for early design, but what we would really want is essentially\na bunch of entities that are co-existing in an environment, and then reacting to one another.\nI think we could try to emulate this with something that looks more like a bunch of\nobjects that can emit and subscribe to one another's events, and then know how to\nrespond.\n\n\n## Characters\n\n### Dinosaurs\n\nDinosaurs are the main character in this world, and we initialize the world\nwith some number. Specifically, a dinosaur wanders around and has the following\nattributes:\n\n - **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.\n - **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.\n - **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.\n - **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.\n\nThe dinosaur has the following actions:\n\n - **move**: for each turn of the game, the dinosaur moves, and then interacts with whatever he finds in his new spot.\n - **eat**: a dinosaur can choose to eat an avocado, or even another dinosaur, depending on the size and level of hunger.\n - **sleep** a dinosaur can choose to sleep (with some probability) if he is sick to increase the chance of getting better.\n - **reproduce** a dinosaur that encounters another dinosaur (mature of the opposite gender) has some percent change of reproduction.\n\n### Avocados\n\nAvocados 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:\n\n - **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.\n - **avocados**: once a tree is mature, it holds a certain number of avocados\n - **disease**: 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.\n\n## Variables\n\nFor 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.\n\n### Dinosaurs\n\nThe game starts with a certain number of dinosaurs (number of total dinosaurs), with the following randomly set values (within some ranges):\n\n - size\n - hunger\n\nThe game itself (an instance of DinosaurDilemma) under [dinolemma/game.py](dinolemma/game.py) creates\nsome number of dinosaurs in the following way:\n\n```python\nfrom dinolemma.dinosaurs import Dinosaurs\n\ndinosaurs = Dinosaurs()\n\ndinosaurs\n[14 dinosaurs]\n\nfor dino in dinosaurs: \n    print(dino.name) \n\npersnickety-muffinpodus\nloopy-tacopodus\ngassy-poodledocus\nfrigid-nalgasasaurus\nhanky-dogdocus\ndirty-blackbeanpodus\nastute-truffleus\nloopy-knifeus\nchocolate-noodleisaurus\npsycho-chipiraptor\nmuffled-lizardus\nstinky-underoosdocus\nrainbow-cattywampusisaurus\nbuttery-saladiraptor\n```\n\nEach is guaranteed to have a unique name, and we check that there are enough\nspaces on the game board to support the dinosaurs and trees created. We\ncan also grab a random dinosaur:\n\n```python\ndino = dinosaurs.random()\ndino.name\n'bricky-eagleraptor'\n```\n\n### Avocados\nThe game also starts with a certain number of avocado saplings.\n\n```python\nfrom dinolemma.avocados import AvocadoTrees\n\ntrees = AvocadoTrees()\nfor tree in trees:\n    print(tree.name)\n\nhanky-egg-tree\ngoodbye-poo-tree\nreclusive-sundae-tree\nmuffled-squidward-tree\n```\n\nor grab a random tree:\n\n```python\ntree = trees.random()\ntree\n\u003cdinolemma.avocados.AvocadoTree at 0x7f25347e7860\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsoch%2Fdinosaur-dilemma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvsoch%2Fdinosaur-dilemma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsoch%2Fdinosaur-dilemma/lists"}