There's more...

We used EvolEnemy as a base class for defining the individuals in the population and a simple rule for sorting them. This algorithm can be improved further by defining more complex templates and phenotype definitions to take mutations into account, such as speed, color, size, and strength.

Also, the enemy controller is separated from the template, given the example created to illustrate the algorithm, and to give you more room for experimentation. However, the idea is to give you the tools to grasp the algorithm, so you can apply it in your own game, once it's well understood.

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.