From dc5dc756cbd61bd4e59b9f875b76cb03ff71f7bf Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Mon, 18 May 2020 14:28:48 +0200 Subject: [PATCH] Removed randomness from entity picking --- src/AI/GA.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/AI/GA.py b/src/AI/GA.py index d6352ff..26169ab 100644 --- a/src/AI/GA.py +++ b/src/AI/GA.py @@ -207,15 +207,23 @@ def pickEntity(player, map): # Pick best weighted entities bestIdxs = (numpy.where(finalWeights == numpy.max(finalWeights)))[0] - bestEntities = [] - for i in bestIdxs: - bestEntities.append(finalEntities[i]) + # bestEntities = [] + # for i in bestIdxs: + # 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()): - 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 # choice = random.choices(finalEntities, finalWeights)[0]