How it works...

The EvolEnemy class works as a template for defining the individual phenotype. We start by using mu and lambda for defining the size of the population, and a first wave is created at random.

Then, after each wave is defeated, the evaluation function takes place, sorting the enemies from least to best fit. The first mu number of individuals are eradicated, and offspring are created by copying the surviving population. This is called a generation.

The algorithm stops after the defined number of generations are created.

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.