A simple simulation in Unity, which uses genetic algorithm to optimize forces applied to cubes
A simple simulation in Unity, which uses genetic algorithm to optimize forces applied to cubes.
Unity game build:
https://github.com/hobogalaxy/EvOLuTIoN/releases/download/v1.0/GenAlgBuild.zip
Each cube spawns with an instance of Player.cs
script that contains his array of 3D vectors. Those vectors are applied to player as forces over time.
The genetic algorithm optimises those vectors.
What it means is players don't learn how to navigate in the environment, they only memorise the vectors that enable them to get closer to the goal.
You can find the algorithm scripts in Assets>>Scripts>>AlgorithmScripts
Population.cs
contains the Genetic Algorithm applied by NaturalSelection() function.
void NaturalSelection()
{
SetChampion(); //finds the best player from generation
CalculateFitness();
CalculateFitnessSum(); //needed for selecting parents
CopyBrain(Players[0], champion); //best player is always reborn in next generation
//unchanged as player0
for (int i = 1; i < playerNum; i++)
{
GameObject parent = SelectParent();
CopyBrain(Players[i], parent);
Mutate(Players[i]);
}
}
Each player has only one parent, no crossover is used.