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)