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.

78 lines
2.8 KiB
Python

from typing import Tuple
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]