Fixed bug, where the game would crash if there are no pikcupable entities left

This commit is contained in:
Marcin Kostrzewski 2020-05-16 22:36:42 +02:00
parent 1c8b21bf2c
commit 8c2a3f2bff

View File

@ -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]