If there are is no food left, then make decision tree return water.

This commit is contained in:
Michał Czekański 2020-05-25 01:24:17 +02:00
parent 29ba3d23c0
commit 04e3b29c21

View File

@ -30,15 +30,6 @@ class SurvivalDT:
playerStats = DTPlayerStats.dtStatsFromPlayerStats(player.statistics) playerStats = DTPlayerStats.dtStatsFromPlayerStats(player.statistics)
# Get foods sorted by distance from player
dtFoods: List[DTSurvivalInteractable] = []
for food in foods:
dtFood = DTSurvivalInteractable.dtInteractableFromInteractable(food, player.x, player.y)
dtFoods.append(dtFood)
dtFoods.sort(key=lambda x: x.accurateDistanceFromPlayer)
nearestDtFood = dtFoods[0]
# 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:
@ -47,6 +38,19 @@ class SurvivalDT:
dtWaters.sort(key=lambda x: x.accurateDistanceFromPlayer) dtWaters.sort(key=lambda x: x.accurateDistanceFromPlayer)
nearestDtWater = dtWaters[0] nearestDtWater = dtWaters[0]
# Get foods sorted by distance from player
dtFoods: List[DTSurvivalInteractable] = []
for food in foods:
dtFood = DTSurvivalInteractable.dtInteractableFromInteractable(food, player.x, player.y)
dtFoods.append(dtFood)
dtFoods.sort(key=lambda x: x.accurateDistanceFromPlayer)
# If there is no food on map return nearest water.
try:
nearestDtFood = dtFoods[0]
except IndexError:
return nearestDtWater.interactable
# 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: