Skip to content

Instantly share code, notes, and snippets.

@IntegerMan
Created November 16, 2019 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IntegerMan/31c2637588662578950a74fe9cc81128 to your computer and use it in GitHub Desktop.
Save IntegerMan/31c2637588662578950a74fe9cc81128 to your computer and use it in GitHub Desktop.
let getChildGenes (random: System.Random) parent1 parent2 mutationChance =
// Map from one parent to another, choosing a point to switch from one parent as the source
// to the other. Being an identical copy to either parent is also possible
let crossoverIndex = random.Next(Array.length parent1 + 1)
Array.mapi2 (fun i m f -> if i <= crossoverIndex then
m
else
f
) parent1 parent2
// Next allow each gene to be potentially mutated
|> mutateGenes random mutationChance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment