Evolution is a survival sandbox environment about creatures competing over food. Players need to implement their brain classes in order to control creatures. The objective of players is to create a brain model that can make creatures to survive the longest in the environment. Everyone can upload their model and challenge their creatures in the simulation. The main aim of this project is to create a suitable environment for students to create their machine learning models feasibly.
Before starting to develop your own brain model and playing the game, the only thing interests you about 'evolution simulation' is brain interface. You just basically need to create a brain class in the brains directory by implementing brain interface. You can find the details of the brain interface and the game in the details section.
Is to create a brain model that can make creatures to survive the longest in the environment by performing perfect actions.
While you are starting to implement your model, if you want, you can check our example brain class implementations. It will be a great help for you.
1-) First of all, you need to create a file in the brains directory and create your brain class. You can give any name you want to your brain.
2-) After this step, you need to implement the necessary methods from brain interface. You can create your own methods independently.
- You should keep in mind that in every round, every creature calls its brain's methods before making an action. If its newborn at that round, it calls birth. If if it dies at that round, it calls the death method of its brain.
Examples of calls of creatures:
- When a creature is born
creature.brain.birth(np.copy(self.creatureStats), worldViewOfCreature = np.copy(worldmap.getEnvironmentOfCreature(self)), parentBrain = parentBrain)
- When a creature is performing an action
action = creature.brain.act(np.copy(self.creatureStats),np.copy(worldViewOfCreature))
- When a creature dies
creature.death(creatureStats = np.copy(creature.creatureStats), worldViewOfCreature = np.copy(self.worldmap.getEnvironmentOfCreature(creature)), score = copy.copy(creature.creatureStats[creature.POS_ALIVECOUNTER]))
And you are ready to test your model. You can run the simulation by executing run.py file.
The game consists of 4 components:
- World map
- Creature
- Brain
- Zoo
The map consists of 3 components:
- Food
- Humidity
- Height
In the beginning, the world is automatically generated. The humidity and height map is generated by applying a Gaussian filter over random noise. Depending on the chosen percentage of water coverage, a specific height is chosen to be the actually water level height. Everywhere with height level below to that water level become the sea. Then, the simulation starts.
After simulation started, at the beginning of every turn, a specific number of creatures are released to the environment and vegetation level on the map is initialized. Each turn restarts when there are no more creatures on the map.
Each round, the vegetation grows depending on the water level at that spot. It cannot exceed 1.0 in value. After that, every create in the list can perform exactly one action.
The edges of the map are not borders. When a creature passes an edge, it comes up from opposite edge. Therefore the world map is like a sphere.
The creature consists of 5 features:
The brain is the control unit of every creature. Every creature belongs to one specific brain and actions of the creatures in every round of game are decided by the brains of the creatures. The brain is set immediately after the creature's birth.
- Creatures' lifespan is 0 and 1. Its health cannot exceed 1 without looking at how much it eats.
- Creatures become dead when their health is equal or below to 0, the creature is declared dead an will not be updated anymore.
- Creatures have an X and Y positions and the world map. This feature decides the place of creatures on the map.
- Its shows whether the creature is alive or not.
Creatures can perform 6 different actions:
-
Movement by one tile up/left/down/right
-
Eat (Vegetation level at the current location is added to own health, and vegetation becomes 0 at that location)
-
Reproduce (Create a copy of itself, dividing its health over both. After that, the health of the creature is reduced by a fixed amount.)
Creatures can only see a limited amount of the map. They can only see their close surroundings.
It's an interface that you should follow while you are implementing your machine learning model.
It consists of a constructor and 5 abstract methods;
parameters:
- numberOfActions (int, the number of possible actions that creatures can perform)
- creatureStatsShape (int, the shape of the creature stats array)
- worldViewShape (tuple, shape of the creature view array)
It returns nothing.
- It has no parameters.
- It returns string as the ID of the brain implementation.
- It has no parameters.
- It returns float as the brightness of the brain's creatures' image.
This method is called by the game whenever a creature of this brain is created.
Parameters;
- creatureStats (stats of the creature, its a 1D np array and consists of creature's position X, position Y, health, alive and alive counter)
- worldViewOfCreature (stats of the creature's environment, its a 3D np array and consists of 4 layers. Layers are respectively height, water depth, humidity and vegatiation. First two dimensions represents the tiles.)
- parentBrain (its the brain object of the parent of the creature. If there is no parent of the creature, its null)
It returns nothing.
This method is called by the game whenever a creature needs to perform an action.
Parameters;
- creatureStats (stats of the creature, its a 1D np array and consists of creature's position X, position Y, health, alive and alive counter)
- worldViewOfCreature (stats of the creature's environment, its a 3D np array and consists of 4 layers. Layers are respectively height, water depth, humidity, and vegetation. First two dimensions represents the tiles.)
It returns int as action;
- 0 - move left
- 1 - move up
- 2 - move right
- 3 = move down
- 5 - eat
- 6 - reproduce
This method is called by the game whenever a creature dies.
Parameters;
- creatureStats (stats of the creature, its a 1D np array and consists of creature's position X, position Y, health, alive and alive counter)
- worldViewOfCreature (stats of the creature's environment, its a 3D np array and consists of 4 layers. Layers are respectively height, water depth, humidity and vegetation. First two dimensions represents the tiles.)
- score (its the number of live rounds of the creature as int)
It returns nothing.
The best ten creatures are kept in the zoo in order to print the rank in the game.
The output is like this;
1. 3b73104c51224ee4b9b06a7cf9ee400d_MySimpleBrain score: 64.0
2. 944a614dc72f49abbdb7e9b8f6bd99f0_MySimpleBrain score: 46.0
3. c7936638266f4ac09086105e0f529d47_MySimpleBrain score: 42.0
4. 4a4e41a0670440d7965c51084aee4354_MyBrainV2 score: 37.0
5. 8b1c09e36537413bb7e41e63328ee603_MyBrainV2 score: 37.0
6. 6a11f15f672d4392b5b90db9b09554e1_MyBrainV2 score: 36.0
7. dae85b275cad4771b2acb4e9e85ee394_MyBrainV2 score: 36.0
8. 903c2152841148f5b401c8cae7db8d41_MyBrainV2 score: 35.0
9. 96ce86ef1889442f99ff110c61222176_MySimpleBrain score: 34.0
10. 251d0e233e8f40658bc152cb8f7ff2eb_MyBrainV2 score: 32.0
Make sure the following packages are available:
- Python 3.x
- pip install opencv-python
- pip install pygame