Adds mutation

This commit is contained in:
Mark Hoekveen
2019-10-28 13:47:26 +01:00
parent cc2a677005
commit 57a712f140
2 changed files with 13 additions and 10 deletions
+3
View File
@@ -1,5 +1,6 @@
extends Node
export (PackedScene) var Creature
export (float) var mutation_rate = 0.05
var selected = []
var rng = RandomNumberGenerator.new()
@@ -32,6 +33,8 @@ func combine_a_bitch():
new_dna.append(selected[0].dna[i])
else:
new_dna.append(selected[1].dna[i])
if rng.randf() <= mutation_rate:
new_dna.append(!new_dna.pop_back())
var new_child = spawn_a_bitch()
new_child.dna = new_dna
deselect_all()