From 8c2a3f2bffa5cd15af6b83f1a6aae6e8744a5279 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sat, 16 May 2020 22:36:42 +0200 Subject: [PATCH] Fixed bug, where the game would crash if there are no pikcupable entities left --- src/AI/GA.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/AI/GA.py b/src/AI/GA.py index 6b12523..dea1a50 100644 --- a/src/AI/GA.py +++ b/src/AI/GA.py @@ -25,7 +25,7 @@ def geneticAlgorithm(map, iter, solutions, mutationAmount=0.05, multithread=Fals initialPopulation = numpy.random.uniform(low=0.0, high=1.0, size=(solutions, weightsCount)) population = initialPopulation for i in range(iter): - print("\nRunning {} generation...".format(i)) + print("\nRunning {} generation...".format(i + 1)) fitness = [] if not multithread: for player in population: @@ -168,4 +168,7 @@ def pickEntity(player, map): finalEntities = foods + waters + rests finalWeights = foodsWeights + watersWeights + restsWeights + if not finalEntities: + # If all items are gone, pick random one + finalEntities = map.getInteractablesByClassifier() return random.choices(finalEntities, finalWeights)[0]