Projekt_Sztuczna_Inteligencja/objects/mines/disarming/hash_function.py

106 lines
3.1 KiB
Python
Raw Normal View History

from enum import Enum
class Wire(Enum):
BLUE = 1, "blue"
GREEN = 2, "green"
RED = 3, "red"
class TypeHash(Enum):
TIME = 90, "time"
CHAINED = 45, "chained"
STANDARD = 0, "standard"
class DangerClassHash(Enum):
BIG_BANG = 64, "big bang"
WEAPON_OF_MASS_DESTRUCTION = 48, "weapon of mass destruction"
RADIOACTIVE = 36, "radioactive"
CASUAL_DEVASTATOR = 20, "casual devastator"
ALMOST_PIERCES_THROUGH_PAPER = 10, "almost pierces through paper"
CHERRY_BOMB = 0, "cherry bomb"
class SeriesHash(Enum):
TCH_2990TONER = 128, "TCH 2990toner"
TCH_2990INKJET = 110, "TCH 2990inkjet"
TVY_2400H = 100, "TVY 2400h"
SWX_5000 = 80, "SWX 5000"
SWX_4000 = 50, "SWX 4000"
WORKHORSE_3200 = 30, "WORKHORSE 3200"
FX_500 = 15, "FX 500"
TVY_2400 = 0, "TVY 2400"
class IndicatorHash(Enum):
RED = 10, "red"
YELLOW = 8, "yellow"
BLUE = 5, "blue"
GREEN = 2, "green"
WHITE = 0, "white"
class SpecificityHash(Enum):
ANTI_AIRCRAFT = 55, "anti aircraft"
ANTI_PERSONNEL = 43, "anti personnel"
DEPTH_MINE = 37, "depth mine"
ANTI_TANK = 26, "anti tank"
PROXIMITY_MINE = 18, "proximity mine"
PRESSURE_MINE = 9, "pressure mine"
FRAGMENTATION_MINE = 0, "fragmentation mine"
class WeightHash(Enum):
GINORMOUS = 32, "ginormous"
EXTRA_LARGE = 24, "extra large"
TOTAL_AVERAGE = 16, "total average"
SLIM_FIT = 8, "slim fit"
BREAD_CRUMB = 0, "bread crumb"
MAX_VALUE = max([elem.value[0] for elem in TypeHash]) \
+ max([elem.value[0] for elem in DangerClassHash]) \
+ max([elem.value[0] for elem in SeriesHash]) \
+ max([elem.value[0] for elem in IndicatorHash]) \
+ max([elem.value[0] for elem in SpecificityHash]) \
+ max([elem.value[0] for elem in WeightHash])
def _get_wire_color(hash_sum):
if hash_sum < 0.43 * MAX_VALUE:
return Wire.BLUE
elif hash_sum <= 0.56 * MAX_VALUE:
return Wire.GREEN
else:
return Wire.RED
# STRING ARGUMENTS
def get_wire_from_str(mine_type: str, danger_cls: str, series: str, indicator: str, specificity: str, weight: str):
type_hash = TypeHash[mine_type.upper().replace(" ", "_")].value[0]
danger_cls_hash = DangerClassHash[danger_cls.upper().replace(" ", "_")].value[0]
series_hash = SeriesHash[series.upper().replace(" ", "_")].value[0]
indicator_hash = IndicatorHash[indicator.upper().replace(" ", "_")].value[0]
specificity_hash = SpecificityHash[specificity.upper().replace(" ", "_")].value[0]
weight_hash = WeightHash[weight.upper().replace(" ", "_")].value[0]
hash_sum = type_hash + danger_cls_hash + series_hash + indicator_hash + specificity_hash + weight_hash
return _get_wire_color(hash_sum)
# ENUM ARGUMENTS
def get_wire_from_enums(
mine_type: TypeHash,
danger_cls: DangerClassHash,
series: SeriesHash,
indicator: IndicatorHash,
specificity: SpecificityHash,
weight: WeightHash):
hash_list = [mine_type, danger_cls, series, indicator, specificity, weight]
hash_sum = sum([enum.value[0] for enum in hash_list])
return _get_wire_color(hash_sum)