From da119fca37262cb363655e15f1ae993b3e4fb61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 24 May 2020 22:21:10 +0200 Subject: [PATCH] Add new field for accurate dst from player in dt interactable class This will be used to sort foods more precisely when looking for nearest food, water, etc. --- .../DTEntities/DTSurvivalInteractable.py | 12 +++++++----- src/AI/SurvivalDT.py | 14 +++++++------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py b/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py index db3b28b..8a3eef3 100644 --- a/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py +++ b/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py @@ -7,11 +7,13 @@ from src.entities.Interactable import Interactable class DTSurvivalInteractable: DistFromObjectFromPlayer: DistFromObject - def __init__(self, distanceFromPlayer: DistFromObject, classification: SurvivalClassification, - interactable: Interactable): + def __init__(self, dtDistanceFromPlayer: DistFromObject, classification: SurvivalClassification, + interactable: Interactable, accurateDistanceFromPlayer: int): self.interactable = interactable self.classification = classification - self.distanceFromPlayer = distanceFromPlayer + self.dtDistanceFromPlayer = dtDistanceFromPlayer + self.accurateDistanceFromPlayer = accurateDistanceFromPlayer + @staticmethod def dtInteractableFromInteractable(interactable: Interactable, playerX: int, playerY: int): @@ -40,8 +42,8 @@ class DTSurvivalInteractable: else: return None - return DTSurvivalInteractable(distanceFromPlayer, classification, interactable) + return DTSurvivalInteractable(distanceFromPlayer, classification, interactable, distance) def getDescription(self): - dsc = "Classification: {}, Distance from player: {}".format(self.classification, self.distanceFromPlayer) + dsc = "Classification: {}, Distance from player: {}".format(self.classification, self.dtDistanceFromPlayer) return dsc diff --git a/src/AI/SurvivalDT.py b/src/AI/SurvivalDT.py index e76f580..f5416b8 100644 --- a/src/AI/SurvivalDT.py +++ b/src/AI/SurvivalDT.py @@ -35,26 +35,26 @@ class SurvivalDT: dtFood = DTSurvivalInteractable.dtInteractableFromInteractable(food, player.x, player.y) dtFoods.append(dtFood) - dtFoods.sort(key=lambda x: x.distanceFromPlayer.value) + dtFoods.sort(key=lambda x: x.accurateDistanceFromPlayer) # Get waters sorted by distance from player dtWaters: List[DTSurvivalInteractable] = [] for water in waters: dtWater = DTSurvivalInteractable.dtInteractableFromInteractable(water, player.x, player.y) dtWaters.append(dtWater) - dtWaters.sort(key=lambda x: x.distanceFromPlayer.value) + dtWaters.sort(key=lambda x: x.accurateDistanceFromPlayer) # Get rest places sorted by distance from player dtRestPlaces: List[DTSurvivalInteractable] = [] for rest in rests: dtRest = DTSurvivalInteractable.dtInteractableFromInteractable(rest, player.x, player.y) dtRestPlaces.append(dtRest) - dtRestPlaces.sort(key=lambda x: x.distanceFromPlayer.value) + dtRestPlaces.sort(key=lambda x: x.accurateDistanceFromPlayer) currentSituation = SurvivalDTExample(None, playerStats.hungerAmount, playerStats.thirstAmount, playerStats.staminaAmount, - dtFoods[0].distanceFromPlayer, dtWaters[0].distanceFromPlayer, - dtRestPlaces[0].distanceFromPlayer) + dtFoods[0].dtDistanceFromPlayer, dtWaters[0].dtDistanceFromPlayer, + dtRestPlaces[0].dtDistanceFromPlayer) treeDecision, choice = self.__pickEntityAfterTreeDecision__(currentSituation, dtFoods, @@ -72,8 +72,8 @@ class SurvivalDT: currentSituation = SurvivalDTExample(None, playerStats.hungerAmount, playerStats.thirstAmount, playerStats.staminaAmount, - dtFoods[0].distanceFromPlayer, dtWaters[0].distanceFromPlayer, - dtRestPlaces[0].distanceFromPlayer) + dtFoods[0].dtDistanceFromPlayer, dtWaters[0].dtDistanceFromPlayer, + dtRestPlaces[0].dtDistanceFromPlayer) treeDecision, choice = self.__pickEntityAfterTreeDecision__(currentSituation, dtFoods, dtRestPlaces, dtWaters)