A Prey and Predator simulation with genetic algorithms powered by Processing and Java.
Due to my recent interest in genetic algorithms, I decided to create my own take on the famous algorithm Game of Life from John Conway.
His idea for generating a life-like pattern for life followed four simple rules
- For a space that is 'populated':
- Each cell with one or no neighbors dies, as if by solitude.
- Each cell with four or more neighbors dies, as if by overpopulation.
- Each cell with two or three neighbors survives.
- For a space that is 'empty' or 'unpopulated'
- Each cell with three neighbors becomes populated.
Those rules alone were capable of creating very interesting patterns as seen in the gif below taken from . If you want to know more about the original game of life (It's a very interesting read). Please follow the link
For my take on the game of life I created a few rules:
- Default Rules
- If you touch another 'life form' the bigger one survives
- If you see someone bigger than you, you run away. (Prey Behaviour)
- If you see someone smaller than you, you hunt. (Predator Behaviour)
- Game Rules
- If there are only 5 life forms available, a new generations is born.
- If More than 2000 cicles were complete, a new generation is born.
- If you touch the wall more than 50 times you die. (Preventing wall exploits)
- Generation Rules
- Each generation is created from the most fit parents chosen using a monte carlo approach.
- The fitness is calculated using the following:
- Each cicle alive wins 2 points
- Each action taken wins 1 Point (Follow or Run)
- F = (Cicle + Action)/10
- Each parent has 50% chance of spreading one of its genes for every gene in the pool
- Each life form has it's own attributes that can be inherited including: size, acceleration, force, velocity, awareness distance and so on.
- Clean the code (There is a lot of unused code in there).
- Improve readbility.
- Create more complex behaviours.
- Use reinforcement learning.