diff --git a/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py b/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py index 8a3eef3..5bed7b1 100644 --- a/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py +++ b/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py @@ -14,7 +14,6 @@ class DTSurvivalInteractable: self.dtDistanceFromPlayer = dtDistanceFromPlayer self.accurateDistanceFromPlayer = accurateDistanceFromPlayer - @staticmethod def dtInteractableFromInteractable(interactable: Interactable, playerX: int, playerY: int): classification = None @@ -47,3 +46,22 @@ class DTSurvivalInteractable: def getDescription(self): dsc = "Classification: {}, Distance from player: {}".format(self.classification, self.dtDistanceFromPlayer) return dsc + + def getDtDistanceFromOtherInteractable(self, otherInteractable: Interactable): + """ + Returns distance of this interactable from other interactable as enum, that can be used in decision tree + learning. + + :param otherInteractable: + """ + accurateDistance = abs(self.interactable.x - otherInteractable.x) + \ + abs(self.interactable.y - otherInteractable.y) + + if accurateDistance < 3: + return DistFromObject.LT_3 + elif 3 <= accurateDistance < 8: + return DistFromObject.GE_3_LT_8 + elif 8 <= accurateDistance < 15: + return DistFromObject.GE_8_LT_15 + elif accurateDistance > 15: + return DistFromObject.GE_15 \ No newline at end of file diff --git a/src/AI/SurvivalDT.py b/src/AI/SurvivalDT.py index f5416b8..0c42133 100644 --- a/src/AI/SurvivalDT.py +++ b/src/AI/SurvivalDT.py @@ -36,6 +36,7 @@ class SurvivalDT: dtFoods.append(dtFood) dtFoods.sort(key=lambda x: x.accurateDistanceFromPlayer) + nearestDtFood = dtFoods[0] # Get waters sorted by distance from player dtWaters: List[DTSurvivalInteractable] = [] @@ -43,6 +44,7 @@ class SurvivalDT: dtWater = DTSurvivalInteractable.dtInteractableFromInteractable(water, player.x, player.y) dtWaters.append(dtWater) dtWaters.sort(key=lambda x: x.accurateDistanceFromPlayer) + nearestDtWater = dtWaters[0] # Get rest places sorted by distance from player dtRestPlaces: List[DTSurvivalInteractable] = [] @@ -50,11 +52,14 @@ class SurvivalDT: dtRest = DTSurvivalInteractable.dtInteractableFromInteractable(rest, player.x, player.y) dtRestPlaces.append(dtRest) dtRestPlaces.sort(key=lambda x: x.accurateDistanceFromPlayer) + nearestDtRest = dtRestPlaces[0] + + currentSituation = SurvivalDTExample(None, playerStats.hungerAmount, playerStats.thirstAmount, playerStats.staminaAmount, - dtFoods[0].dtDistanceFromPlayer, dtWaters[0].dtDistanceFromPlayer, - dtRestPlaces[0].dtDistanceFromPlayer) + nearestDtFood.dtDistanceFromPlayer, nearestDtWater.dtDistanceFromPlayer, + nearestDtRest.dtDistanceFromPlayer) treeDecision, choice = self.__pickEntityAfterTreeDecision__(currentSituation, dtFoods,