Evolutionary Algorithm Enemies
This is a personal project that uses an evolutionary algorithm in Unity to control the attributes and behaviour of the enemies in a game. as the player fights enemies the evolutionary algorithm will produce new enemies that are better adapted to hunt the player.
Menus
There is a main menu and options menu for changing the master volume and background music volume. When the game is running press escape to return to the options menu. No progress is saved when going from the game to the menu. There is a button to quit the game in both menus.
Objectives
There are several objectives that are around the map the player is navigated towards. The objective that is currently active alters which spawn points will allow enemies to spawn. There are health and ammo pick-ups at these locations that the player will need to find to be able to fight their way through to the next objective. The more the player fights the enemies the better they become at fighting against the player.
Enemies
The enemies all use the same script to control their behaviour, there is another object which tracks how many enemies there are close to each other which is used in the finite state machine. The finite state machine has states: idle, wander, chase, attack and flee. Whether the enemy will try to attack the player is based on a confidence value which is calculated when the player moves within range. The confidence value considers percentage of health, aggressiveness and how many other enemies are nearby.
Evolutionary Algorithm
The game has an object that controls the evolutionary algorithm (EA manager) and generates and handles the populations and genomes. At the start of the game the EA manager generates an initial population of genomes randomly. As the initial population of enemies is spawned they will get a genome from the EA manager which will modify each enemy’s attributes. This genome will be drawn from the starting population until more than two enemies have been defeated by the player. When an enemy is defeated by the player its genome is given a fitness score and then stored in the tested population.
Once two or more enemies have been defeated when a genome is requested by an enemy the EA manager produces child offspring by performing tournament selection on the tested population. The tournament will initially be carried out using the two tested genomes in the tested population but will expand to choose two individuals from a given number of the fittest individuals in the tested population which is controlled with an adjustable selection pressure. Once the two parents have been selected uniform crossover is applied to produce a child genome. Following this swap insertion and inversion mutations can be applied to the child genome using a percentage chance.