Removed randomness from entity picking

This commit is contained in:
Marcin Kostrzewski 2020-05-18 14:28:48 +02:00
parent de68c5e991
commit dc5dc756cb

View File

@ -207,15 +207,23 @@ def pickEntity(player, map):
# Pick best weighted entities # Pick best weighted entities
bestIdxs = (numpy.where(finalWeights == numpy.max(finalWeights)))[0] bestIdxs = (numpy.where(finalWeights == numpy.max(finalWeights)))[0]
bestEntities = [] # bestEntities = []
for i in bestIdxs: # for i in bestIdxs:
bestEntities.append(finalEntities[i]) # bestEntities.append(finalEntities[i])
choice = random.choice(bestEntities) choice = finalEntities[bestIdxs[0]]
# Keeps the player from standing still # If the choice happens to be the same as the last one
if choice == map.getEntityOnCoord(player.getFacingCoord()): if choice == map.getEntityOnCoord(player.getFacingCoord()):
choice = random.choice(finalEntities) del finalWeights[bestIdxs[0]]
del finalEntities[bestIdxs[0]]
secondBestIdxs = (numpy.where(finalWeights == numpy.max(finalWeights)))[0]
# bestEntities = []
# for i in secondBestIdxs:
# bestEntities.append(finalEntities[i])
choice = finalEntities[secondBestIdxs[0]]
# Old method using RNG # Old method using RNG
# choice = random.choices(finalEntities, finalWeights)[0] # choice = random.choices(finalEntities, finalWeights)[0]