Changed formulas back to original

This commit is contained in:
Marcin Kostrzewski 2020-05-17 10:16:56 +02:00
parent d31e03050e
commit b6312df9f3

View File

@ -40,12 +40,13 @@ def geneticAlgorithm(map, iter, solutions, mutationAmount=0.05, multithread=Fals
f.write("\n") f.write("\n")
# Set the RNG seed for this GA # Set the RNG seed for this GA
random.seed(random.randint(0, 100)) # 5 is good for weak start
random.seed(5)
# Begin # Begin
for i in range(iter): for i in range(iter):
print("\nRunning {} generation...".format(i + 1)) print("\nRunning {} generation...".format(i + 1))
# random.seed(random.randrange(0, 100000))
fitness = [] fitness = []
if not multithread: if not multithread:
for player in population: for player in population:
@ -178,19 +179,22 @@ def pickEntity(player, map):
hunger = player.statistics.hunger hunger = player.statistics.hunger
for food in foods: for food in foods:
typeWeight = weights[0] typeWeight = weights[0]
foodsWeights.append(typeWeight * hunger) distance = abs(player.x - food.x) + abs(player.x - food.y)
foodsWeights.append(typeWeight / (distance * walkingAffinity) * hunger * 0.01)
watersWeights = [] watersWeights = []
thirst = player.statistics.thirst thirst = player.statistics.thirst
for water in waters: for water in waters:
typeWeight = weights[1] typeWeight = weights[1]
watersWeights.append(typeWeight * thirst) distance = abs(player.x - water.x) + abs(player.x - water.y)
watersWeights.append(typeWeight / (distance * walkingAffinity) * thirst * 0.01)
restsWeights = [] restsWeights = []
stamina = player.statistics.stamina stamina = player.statistics.stamina
for rest in rests: for rest in rests:
typeWeight = weights[2] typeWeight = weights[2]
restsWeights.append(typeWeight * stamina) distance = abs(player.x - rest.x) + abs(player.x - rest.y)
restsWeights.append(typeWeight / (distance * walkingAffinity) / (stamina * 0.02))
finalEntities = foods + waters + rests finalEntities = foods + waters + rests
finalWeights = foodsWeights + watersWeights + restsWeights finalWeights = foodsWeights + watersWeights + restsWeights