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:
|
||||
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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user