[Tutorial] Genetic Algorithm C#

Hey everyone, I wrote this Genetic Algorithm in C# for a college project, and I thought the implementation turned out pretty nice, figured someone might find it useful, so I decided to make a few videos explaining how to implement it from scratch :slight_smile:

The code is also available on this repository: Bitbucket

Part 1 - Base Implementation:

Part 2 - Fitness Function and Optimizations:

Part 3 - Adding Individuals on New Generations (and usage in a game)

Part 4 - Serialization and Saving/Loading to files

Feel free to use it however you like!
This is licensed under “The Unlicense”, which basically states you can do whatever you want with it, commercial or not, no attribution required. License file is in the repository :slight_smile:

7 Likes

Awesome .The generics part is neat.

1 Like

Thanks! Glad you liked it. Feel free to ask questions if you have any :slight_smile:

Really help me for starting to learn genetic algorithm!! Thank you very much.

Just to let everyone know (the 4 people that are interested xD) that the 3rd video has been released. Edited the original post to include the link.

Good game developings everyone!

This is awesome! Thanks a lot!

1 Like

exactly what i needed, can’t thank you enough.

1 Like

Very interesting! I really appreciate it, keep up the good work.

1 Like

Hello…
I know im late, but I could not figure out how to use your code for, as an example, input three different booleans and receive one float and other two booleans.

There is an erro or it’s me?
In GeneticAlgorithm.NewGeneration
here:
else if (i < Population.Count || crossoverNewDNA)

for me it have to be
else if (i < Population.Count && crossoverNewDNA)

other way we will never create a new child without crossoverNewDNA, do you agree?