-
Notifications
You must be signed in to change notification settings - Fork 2
Fitness Function
The fitness function is used to measure the quality of the current T-Rex. Through that we are able to select the fittest ones and use them to reproduce the next population.
The easiest approach would be to rate the dinosaurs by their travelled distance, meaning the highscore. We could think of penalizing the fitness function by the current distance to the closest cactus, because the T-Rex might be to close to be able to make the jump. On first sight it doesn't seem to make a difference. The cactuses hitboxes are quite small and the T-Rex jump is a pretty strong upward movement.
On the other side the cactuses spawn randomly in different sizes of a maximum of three in a row. This means the later the jump, the better. So in this case the pure highscore can be used as the fitness function.
The levels are generated randomly, so two T-Rex that ran on different tracks aren't really comparable. A better highscore could have been achieved in an easier level. Consequently an other idea is to count the obstacles over which the T-Rex jumped. There are small and big cactuses which can appear together in a group of maximum of three:
Later there will be birds approaching you in three different heights, so the T-Rex has to either jump, duck or du nothing at all:
Depending on the difficulty of passing the different obstacles, we should rate them to get a better fitness function.
To apply a natural evolution on our T-Rex population, we have to breed children out of the best surviving units. As a first approach I suggest following the Flappy Bird tutorial. After that we can have a look how small changes affect our results. We always create a population of 10 dinosaurs:
- sort the units of the current population by their fitness ranking
- select the top 4 units (winners) and pass them directly on to the next population
- create 1 offspring as a crossover product of two best winners
- create 3 offsprings as a crossover products of two random winners
- create 2 offsprings as a direct copy of two random winners
- apply random mutations on each offspring to add some variations