Skip to content

Sebastian-Schuchmann/Genetic-Algorithm-in-Unity3D

Repository files navigation

Genetic Algorithm in Unity3D

Maze 2D Example

Gif

The goal in this game is for the blue cubes to reach the green goal line. They have a preset amount of moves which gets optimized over time by the genetic algorithm.

If you like this repo make sure to follow me @seppischuchmann 👋.

Prerequisites

The Project was made using Unity 2018.2.3f1 but prior versions should work fine, too.

Goal

This Project is supposed to lay the groundwork for anyone who wants to experiment with Genetic Algorithms in Unity. The main classes DNA and Population are generic so they can work with any type. The Selection, Crossover and Mutate functions are easy to swap out.

Unity is a great platform for rapid prototyping on any platform.

Setup

First, you need to create a population with the type you want to evolve. You may need to write your own functions for Selection, Crossover and Mutation, because they are different for each datatype (functions for Vector2 and Vector3 and supplied).

Second, you need to update the Fitness for each DNA via the UpdateFitness function (you can do this as many times as you want):

Check out the Maze Example to see this in action!

Releases

No releases published

Packages

No packages published