From 57a712f1408383b3884cedae7464b02faedb6e56 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Mon, 28 Oct 2019 13:47:26 +0100 Subject: [PATCH] Adds mutation --- CreatureLab.gd | 3 +++ Spatial.tscn | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CreatureLab.gd b/CreatureLab.gd index 374844f..b9653b4 100644 --- a/CreatureLab.gd +++ b/CreatureLab.gd @@ -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() diff --git a/Spatial.tscn b/Spatial.tscn index a68a40b..835c09d 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -30,7 +30,7 @@ background_sky = SubResource( 5 ) [sub_resource type="World" id=7] environment = SubResource( 6 ) -[sub_resource type="ProceduralSky" id=10] +[sub_resource type="ProceduralSky" id=8] sky_top_color = Color( 0, 0, 0, 1 ) sky_horizon_color = Color( 0, 0, 0, 1 ) ground_bottom_color = Color( 0, 0, 0, 1 ) @@ -38,14 +38,14 @@ ground_horizon_color = Color( 0, 0, 0, 1 ) sun_latitude = 137.19 sun_energy = 14.21 -[sub_resource type="Environment" id=11] +[sub_resource type="Environment" id=9] background_mode = 2 -background_sky = SubResource( 10 ) +background_sky = SubResource( 8 ) -[sub_resource type="World" id=12] -environment = SubResource( 11 ) +[sub_resource type="World" id=10] +environment = SubResource( 9 ) -[sub_resource type="ProceduralSky" id=8] +[sub_resource type="ProceduralSky" id=11] sky_top_color = Color( 0, 0, 0, 1 ) sky_horizon_color = Color( 0, 0, 0, 1 ) sky_curve = 1.44 @@ -57,9 +57,9 @@ sun_color = Color( 0.835294, 0.462745, 0.462745, 1 ) sun_latitude = 11.29 sun_energy = 20.16 -[sub_resource type="Environment" id=9] +[sub_resource type="Environment" id=12] background_mode = 2 -background_sky = SubResource( 8 ) +background_sky = SubResource( 11 ) background_color = Color( 0.803922, 0.54902, 0.333333, 0.196078 ) tonemap_mode = 2 auto_exposure_speed = 3.15 @@ -161,7 +161,7 @@ rect_scale = Vector2( 0.5, 0.5 ) [node name="Viewport" type="Viewport" parent="GUI/Preview1"] size = Vector2( 640, 480 ) -world = SubResource( 12 ) +world = SubResource( 10 ) handle_input_locally = false render_target_update_mode = 3 gui_disable_input = true @@ -181,7 +181,7 @@ script = ExtResource( 3 ) Creature = ExtResource( 2 ) [node name="WorldEnvironment" type="WorldEnvironment" parent="."] -environment = SubResource( 9 ) +environment = SubResource( 12 ) [connection signal="pressed" from="GUI/Spawn" to="CreatureLab" method="spawn_a_bitch"] [connection signal="pressed" from="GUI/Kill" to="CreatureLab" method="kill_a_bitch"] [connection signal="pressed" from="GUI/Button" to="CreatureLab" method="combine_a_bitch"]