You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.9 KiB
Python

from typing import Tuple, List
from entities.items.item import Item
from entities.items.food import Food
from rockpaperscissor.file.guide_list import RPS
class Elf:
"""
The absolute overkill, because I can.
"""
ELF_COUNT = 0
def __init__(self):
self.__number = Elf.ELF_COUNT
Elf.ELF_COUNT += 1
self.__name = Elf.fetch_elf_name(self.__number)
self.__inventory = []
@staticmethod
def fetch_elf_name(i: int) -> str:
name_list = ["Dash", "Evergreen", "Sugarplum", "Pixie", "Pudding", "Perky", "Candycane", "Glitter-toes",
"Happy", "Angel-Eyes", "Sugar-Socks", "McJingles", "Frost", "Tinsel", "Twinkle", "Jingle", "Ginger",
"Joy", "Merry", "Pepper", "Sparkle", "Tinsel", "Winter", "Trinket", "Buddy", "Noel", "Snowball",
"Tiny", "Elfin", "Candy", "Carol", "Angel", "Nick", "Plum", "Holly", "Snow", "Pine", "Garland",
"Joseph", "Gabriel", "Hope", "Cedar"]
return name_list[i % len(name_list)]
def __str__(self):
return f"#{self.__number} {self.__name}"
def get_inventory(self) -> list:
return self.__inventory
def add_to_inventory(self, item: Item):
self.__inventory.append(item)
def remove_from_inventory(self, slot: int):
"""
Removes item of the given slot number from the inventory using pop().
That means there are no empty spaces.
Starts with 0.
:param slot:
:return:
"""
self.__inventory.pop(slot)
def get_inventory_calories(self) -> int:
return sum([x.calorie_value for x in list(filter(lambda x: isinstance(x, Food), self.get_inventory()))])
def evaluate_RPS_round(self, other: str, own: str) -> Tuple[bool, int]:
"""
Evaluates a rock paper scissor round according to day 2 puzzle 1.
:param other: What the opponent played
:param own: what you played
:return:
"""
round_score = None
was_win = None
if other == own:
round_score = RPS.DRAW_SCORE
else:
if (other == RPS.PAPER and own == RPS.ROCK) or \
(other == RPS.SCISSOR and own == RPS.PAPER) or \
(other == RPS.ROCK and own == RPS.SCISSOR):
round_score = RPS.LOSS_SCORE
was_win = False
elif (other == RPS.PAPER and own == RPS.SCISSOR) or \
(other == RPS.SCISSOR and own == RPS.ROCK) or \
(other == RPS.ROCK and own == RPS.PAPER):
round_score = RPS.WIN_SCORE
was_win = True
else:
raise Exception(f"Something went terribly wrong! Other: {other} Own: {own}")
return was_win, round_score + RPS.RPS_SHAPE_TO_SCORE[own]
@staticmethod
def check_rucksacks_for_duplicates(rucksack1: Tuple[List[str], List[str]], rucksack2: Tuple[List[str], List[str]]) -> List[str]:
"""
Check if rucksack1 and rucksack2 have an item in common. This will merge the compartments in each rucksack.
:param rucksack1:
:param rucksack2:
:return: list of the duplicate item (as a character) or None if there is no duplicate
"""
r1 = list(set(rucksack1[0] + rucksack1[1]))
r2 = list(set(rucksack2[0] + rucksack2[1]))
dups = []
for a in r1:
if a in r2:
dups.append(a)
return dups
@staticmethod
def check_compartments_for_duplicates(compartment_1: List[str], compartment_2: List[str]) -> str:
"""
Check two given compartment for the duplicate item according to day 3 puzzle 1
:return: the duplicate item (as a character) or None if there is no duplicate
"""
for a in compartment_1:
if a in compartment_2:
return a
return False