Add method returning dt distance between two dt interactables

This commit is contained in:
Michał Czekański 2020-05-24 22:32:42 +02:00
parent da119fca37
commit e7cd571d95
2 changed files with 26 additions and 3 deletions

View File

@ -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

View File

@ -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,