From f0af76520b068c3e2ad41b005df945a4675daea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sat, 23 May 2020 21:57:43 +0200 Subject: [PATCH] Add method converting pl statistics to those that can be used in dt --- .../projectSpecificClasses/DTPlayerStats.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/AI/DecisionTrees/projectSpecificClasses/DTPlayerStats.py b/src/AI/DecisionTrees/projectSpecificClasses/DTPlayerStats.py index e596bcb..f269673 100644 --- a/src/AI/DecisionTrees/projectSpecificClasses/DTPlayerStats.py +++ b/src/AI/DecisionTrees/projectSpecificClasses/DTPlayerStats.py @@ -1,4 +1,5 @@ from src.AI.DecisionTrees.projectSpecificClasses.PlayerStatsValue import PlayerStatsValue +from src.entities.Statistics import Statistics class DTPlayerStats: @@ -10,3 +11,47 @@ class DTPlayerStats: self.staminaAmount = staminaAmount self.thirstAmount = thirstAmount self.hungerAmount = hungerAmount + + @staticmethod + def dtStatsFromPlayerStats(playerStatistics: Statistics): + """ + This method converts player statistics to object representing statistics that can be used in decision tree. + + :param playerStatistics: + """ + + hunger = playerStatistics.hunger / 100 # 100 is max value + thirst = playerStatistics.thirst / 100 + stamina = playerStatistics.stamina / 100 + + hungerAmount = None + if hunger <= 0.25: + hungerAmount = PlayerStatsValue.ZERO_TO_QUARTER + elif 0.25 < hunger < 0.5: + hungerAmount = PlayerStatsValue.QUARTER_TO_HALF + elif 0.5 <= hunger < 0.75: + hungerAmount = PlayerStatsValue.HALF_TO_THREE_QUARTERS + else: # 0.75 <= hunger <= 1 + hungerAmount = PlayerStatsValue.THREE_QUARTERS_TO_FULL + + thirstAmount = None + if thirst <= 0.25: + thirstAmount = PlayerStatsValue.ZERO_TO_QUARTER + elif 0.25 < thirst < 0.5: + thirstAmount = PlayerStatsValue.QUARTER_TO_HALF + elif 0.5 <= thirst < 0.75: + thirstAmount = PlayerStatsValue.HALF_TO_THREE_QUARTERS + else: # 0.75 <= thirst <= 1 + thirstAmount = PlayerStatsValue.THREE_QUARTERS_TO_FULL + + staminaAmount = None + if stamina <= 0.25: + staminaAmount = PlayerStatsValue.ZERO_TO_QUARTER + elif 0.25 < stamina < 0.5: + staminaAmount = PlayerStatsValue.QUARTER_TO_HALF + elif 0.5 <= stamina < 0.75: + staminaAmount = PlayerStatsValue.HALF_TO_THREE_QUARTERS + else: # 0.75 <= stamina <= 1 + staminaAmount = PlayerStatsValue.THREE_QUARTERS_TO_FULL + + return DTPlayerStats(hungerAmount, thirstAmount, staminaAmount)