From c4809373a070b49221ff33a7b84a1587ce7c0168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sat, 23 May 2020 22:20:14 +0200 Subject: [PATCH] Add method converting interactable to object representing it that can be used in dt --- .../DTEntities/DTSurvivalInteractable.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py b/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py index fadadb2..d5c153b 100644 --- a/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py +++ b/src/AI/DecisionTrees/projectSpecificClasses/DTEntities/DTSurvivalInteractable.py @@ -1,5 +1,7 @@ from src.AI.DecisionTrees.projectSpecificClasses.DistFromObject import DistFromObject from src.AI.DecisionTrees.projectSpecificClasses.SurvivalClassification import SurvivalClassification +from src.entities.Enums import Classifiers +from src.entities.Interactable import Interactable class DTSurvivalInteractable: @@ -8,3 +10,30 @@ class DTSurvivalInteractable: def __init__(self, distanceFromPlayer: DistFromObject, classification: SurvivalClassification): self.classification = classification self.distanceFromPlayer = distanceFromPlayer + + @staticmethod + def dtInteractableFromInteractable(interactable: Interactable, playerX: int, playerY: int): + classification = None + distanceFromPlayer = None + + if interactable.classifier == Classifiers.FOOD: + classification = SurvivalClassification.FOOD + elif interactable.classifier == Classifiers.WATER: + classification = SurvivalClassification.WATER + elif interactable.classifier == Classifiers.REST: + classification = SurvivalClassification.REST + else: + return None + + distance = abs(playerX - interactable.x) + abs(playerY - interactable.y) + + if distance < 3: + distanceFromPlayer = DistFromObject.LT_3 + elif 3 <= distance < 8: + distanceFromPlayer = DistFromObject.GE_3_LT_8 + elif distance >= 8: + distanceFromPlayer = DistFromObject.GE_8 + else: + return None + + return DTSurvivalInteractable(distanceFromPlayer, classification)