From c09194313beab2742311bf5b72b311998ee2a88f Mon Sep 17 00:00:00 2001
From: Paul Straberger
Date: Fri, 16 Apr 2021 17:00:41 +0200
Subject: [PATCH] fix evaluate_generation() being called twice
---
src/demos/cars/car_main.gd | 18 +++++++++---------
src/demos/xor/xor_main.gd | 7 +++----
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/src/demos/cars/car_main.gd b/src/demos/cars/car_main.gd
index e3105a1..4445260 100644
--- a/src/demos/cars/car_main.gd
+++ b/src/demos/cars/car_main.gd
@@ -74,16 +74,16 @@ func _physics_process(delta) -> void:
# check if the best agent exceeded the fitness threshold
ga.evaluate_generation()
if ga.curr_best.fitness > fitness_threshold:
+ # either resume with next generation or switch to demo-choosing scene
end_car_demo()
- else:
- # go to the next gen
- ga.next_generation()
- place_bodies(ga.get_curr_bodies())
- # every x gens, increase the generation_step
- if ga.curr_generation % 2 == 0:
- generation_step += 6
- print("increased step to " + str(generation_step))
- total_time = 0
+ # go to the next gen
+ ga.next_generation()
+ place_bodies(ga.get_curr_bodies())
+ # every x gens, increase the generation_step
+ if ga.curr_generation % 2 == 0:
+ generation_step += 6
+ print("increased step to " + str(generation_step))
+ total_time = 0
func place_bodies(bodies: Array) -> void:
diff --git a/src/demos/xor/xor_main.gd b/src/demos/xor/xor_main.gd
index 760a9f8..2cb7e54 100644
--- a/src/demos/xor/xor_main.gd
+++ b/src/demos/xor/xor_main.gd
@@ -66,10 +66,9 @@ func _process(_delta):
# if the fittest network reached the fitness threshold, end this test
if ga.curr_best.fitness > fitness_threshold:
end_xor_test()
- # else start a new generation
- else:
- ga.next_generation()
- place_testers(ga.get_curr_bodies())
+ # start a new generation
+ ga.next_generation()
+ place_testers(ga.get_curr_bodies())
func place_testers(testers: Array) -> void: