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.
This commit is contained in:
parent
9825cd9b7d
commit
da119fca37
@ -7,11 +7,13 @@ from src.entities.Interactable import Interactable
|
|||||||
class DTSurvivalInteractable:
|
class DTSurvivalInteractable:
|
||||||
DistFromObjectFromPlayer: DistFromObject
|
DistFromObjectFromPlayer: DistFromObject
|
||||||
|
|
||||||
def __init__(self, distanceFromPlayer: DistFromObject, classification: SurvivalClassification,
|
def __init__(self, dtDistanceFromPlayer: DistFromObject, classification: SurvivalClassification,
|
||||||
interactable: Interactable):
|
interactable: Interactable, accurateDistanceFromPlayer: int):
|
||||||
self.interactable = interactable
|
self.interactable = interactable
|
||||||
self.classification = classification
|
self.classification = classification
|
||||||
self.distanceFromPlayer = distanceFromPlayer
|
self.dtDistanceFromPlayer = dtDistanceFromPlayer
|
||||||
|
self.accurateDistanceFromPlayer = accurateDistanceFromPlayer
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def dtInteractableFromInteractable(interactable: Interactable, playerX: int, playerY: int):
|
def dtInteractableFromInteractable(interactable: Interactable, playerX: int, playerY: int):
|
||||||
@ -40,8 +42,8 @@ class DTSurvivalInteractable:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return DTSurvivalInteractable(distanceFromPlayer, classification, interactable)
|
return DTSurvivalInteractable(distanceFromPlayer, classification, interactable, distance)
|
||||||
|
|
||||||
def getDescription(self):
|
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
|
return dsc
|
||||||
|
@ -35,26 +35,26 @@ class SurvivalDT:
|
|||||||
dtFood = DTSurvivalInteractable.dtInteractableFromInteractable(food, player.x, player.y)
|
dtFood = DTSurvivalInteractable.dtInteractableFromInteractable(food, player.x, player.y)
|
||||||
dtFoods.append(dtFood)
|
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
|
# Get waters sorted by distance from player
|
||||||
dtWaters: List[DTSurvivalInteractable] = []
|
dtWaters: List[DTSurvivalInteractable] = []
|
||||||
for water in waters:
|
for water in waters:
|
||||||
dtWater = DTSurvivalInteractable.dtInteractableFromInteractable(water, player.x, player.y)
|
dtWater = DTSurvivalInteractable.dtInteractableFromInteractable(water, player.x, player.y)
|
||||||
dtWaters.append(dtWater)
|
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
|
# Get rest places sorted by distance from player
|
||||||
dtRestPlaces: List[DTSurvivalInteractable] = []
|
dtRestPlaces: List[DTSurvivalInteractable] = []
|
||||||
for rest in rests:
|
for rest in rests:
|
||||||
dtRest = DTSurvivalInteractable.dtInteractableFromInteractable(rest, player.x, player.y)
|
dtRest = DTSurvivalInteractable.dtInteractableFromInteractable(rest, player.x, player.y)
|
||||||
dtRestPlaces.append(dtRest)
|
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,
|
currentSituation = SurvivalDTExample(None, playerStats.hungerAmount, playerStats.thirstAmount,
|
||||||
playerStats.staminaAmount,
|
playerStats.staminaAmount,
|
||||||
dtFoods[0].distanceFromPlayer, dtWaters[0].distanceFromPlayer,
|
dtFoods[0].dtDistanceFromPlayer, dtWaters[0].dtDistanceFromPlayer,
|
||||||
dtRestPlaces[0].distanceFromPlayer)
|
dtRestPlaces[0].dtDistanceFromPlayer)
|
||||||
|
|
||||||
treeDecision, choice = self.__pickEntityAfterTreeDecision__(currentSituation,
|
treeDecision, choice = self.__pickEntityAfterTreeDecision__(currentSituation,
|
||||||
dtFoods,
|
dtFoods,
|
||||||
@ -72,8 +72,8 @@ class SurvivalDT:
|
|||||||
|
|
||||||
currentSituation = SurvivalDTExample(None, playerStats.hungerAmount, playerStats.thirstAmount,
|
currentSituation = SurvivalDTExample(None, playerStats.hungerAmount, playerStats.thirstAmount,
|
||||||
playerStats.staminaAmount,
|
playerStats.staminaAmount,
|
||||||
dtFoods[0].distanceFromPlayer, dtWaters[0].distanceFromPlayer,
|
dtFoods[0].dtDistanceFromPlayer, dtWaters[0].dtDistanceFromPlayer,
|
||||||
dtRestPlaces[0].distanceFromPlayer)
|
dtRestPlaces[0].dtDistanceFromPlayer)
|
||||||
|
|
||||||
treeDecision, choice = self.__pickEntityAfterTreeDecision__(currentSituation, dtFoods,
|
treeDecision, choice = self.__pickEntityAfterTreeDecision__(currentSituation, dtFoods,
|
||||||
dtRestPlaces, dtWaters)
|
dtRestPlaces, dtWaters)
|
||||||
|
Loading…
Reference in New Issue
Block a user