diff --git a/overcooked_simulator/counters.py b/overcooked_simulator/counters.py index 7f06b7c7f9022dd919caeae91153f5e00b977d4d..747fd3e500945d3cef9a4a48e36d75a4e6c3267c 100644 --- a/overcooked_simulator/counters.py +++ b/overcooked_simulator/counters.py @@ -10,7 +10,7 @@ import numpy.typing as npt from overcooked_simulator.game_items import ( CuttableItem, - HoldableItem, + Item, ProgressibleItem, Plate, Tomato, @@ -20,9 +20,9 @@ from overcooked_simulator.game_items import ( class Counter: """Simple class for a counter at a specified position (center of counter). Can hold things on top.""" - def __init__(self, pos: npt.NDArray[float]): + def __init__(self, pos: npt.NDArray[float], occupied_by: Optional[Item] = None): self.pos: npt.NDArray[float] = pos - self.occupied_by: Optional[HoldableItem] = None + self.occupied_by: Optional[Item] = occupied_by def pick_up(self): """Gets called upon a player performing the pickup action. If the counter can give something to @@ -35,7 +35,7 @@ class Counter: self.occupied_by = None return give_player - def can_drop_off(self, item: HoldableItem) -> bool: + def can_drop_off(self, item: Item) -> bool: """Checks whether an item by the player can be dropped of. More relevant for example with ingredient dispensers, which should always be occupied and cannot take an item. @@ -47,7 +47,7 @@ class Counter: """ return self.occupied_by is None or self.occupied_by.can_combine(item) - def drop_off(self, item: HoldableItem) -> HoldableItem | None: + def drop_off(self, item: Item) -> Item | None: """Takes the thing dropped of by the player. Args: @@ -71,7 +71,9 @@ class Counter: pass def __repr__(self): - return f"Counter(pos:{str(self.pos)},holds:{self.occupied_by})" + return ( + f"{self.__class__.__name__}(pos={self.pos},occupied_by={self.occupied_by})" + ) class CuttingBoard(Counter): @@ -101,16 +103,13 @@ class CuttingBoard(Counter): """Handles player interaction, stopping to hold key down.""" self.pause_progress() - def __repr__(self): - return f"CuttingBoard({self.occupied_by})" - class ServingWindow(Counter): def __init__(self, pos, game_score: GameScore): self.game_score = game_score super().__init__(pos) - def drop_off(self, item) -> HoldableItem | None: + def drop_off(self, item) -> Item | None: reward = 5 # TODO define rewards self.game_score.increment_score(reward) @@ -120,15 +119,12 @@ class ServingWindow(Counter): if isinstance(item, Plate) and isinstance(item.holds, ProgressibleItem): return item.holds.finished - def can_drop_off(self, item: HoldableItem) -> bool: + def can_drop_off(self, item: Item) -> bool: return self.can_score(item) def pick_up(self): return None - def __repr__(self): - return "ServingWindow" - class PlateReturn(Counter): def __init__(self, pos): @@ -146,7 +142,7 @@ class PlateReturn(Counter): self.occupied_by.append(Plate()) return give_player - def drop_off(self, item: HoldableItem) -> HoldableItem | None: + def drop_off(self, item: Item) -> Item | None: """Takes the ingredient dropped of by the player. Args: @@ -162,7 +158,7 @@ class PlateReturn(Counter): return None return item - def can_drop_off(self, item: HoldableItem) -> bool: + def can_drop_off(self, item: Item) -> bool: """Checks whether an ingredient by the player can be dropped of. Args: @@ -176,9 +172,6 @@ class PlateReturn(Counter): isinstance(self.occupied_by[-1], Plate) and isinstance(item, Plate) ) or self.occupied_by[-1].can_combine(item) - def __repr__(self): - return "PlateReturn" - class TomatoDispenser(Counter): def __init__(self, pos): @@ -187,42 +180,33 @@ class TomatoDispenser(Counter): def pick_up(self): return Tomato() - def drop_off(self, item: HoldableItem) -> HoldableItem | None: + def drop_off(self, item: Item) -> Item | None: return None - def can_drop_off(self, item: HoldableItem) -> bool: + def can_drop_off(self, item: Item) -> bool: return False - def __repr__(self): - return f"{self.occupied_by}Dispenser" - class Trash(Counter): def pick_up(self): pass - def drop_off(self, item: HoldableItem) -> HoldableItem | None: + def drop_off(self, item: Item) -> Item | None: if isinstance(item, Plate): item.holds = None return item return None - def can_drop_off(self, item: HoldableItem) -> bool: + def can_drop_off(self, item: Item) -> bool: return True - def __repr__(self): - return "Trash" - class Stove(Counter): def pick_up(self): - ... + pass - def drop_off(self, item) -> HoldableItem | None: - ... + def drop_off(self, item) -> Item | None: + pass def can_drop_off(self, item) -> bool: return False - - def __repr__(self): - return "Stove" diff --git a/overcooked_simulator/game_items.py b/overcooked_simulator/game_items.py index ac351cac72eb97c0cdc7fe9cde457dea194ac979..09484ca7e542688e7f0c00f1f7871cd346b789bf 100644 --- a/overcooked_simulator/game_items.py +++ b/overcooked_simulator/game_items.py @@ -1,4 +1,4 @@ -class HoldableItem: +class Item: """Base class for game items which can be held by a player.""" def can_combine(self, other): @@ -8,14 +8,14 @@ class HoldableItem: pass -class Plate(HoldableItem): - def __init__(self, holds: HoldableItem = None): +class Plate(Item): + def __init__(self, holds: Item = None): self.clean = True self.holds = holds super().__init__() - def can_combine(self, other: HoldableItem): + def can_combine(self, other: Item): return self.holds is None and not isinstance(other, Plate) def combine(self, other): @@ -25,7 +25,7 @@ class Plate(HoldableItem): return f"Plate({self.holds})" -class ProgressibleItem(HoldableItem): +class ProgressibleItem(Item): """Class for items which need to be processed (cut, cooked, ...)""" def __init__(self, steps_needed): @@ -73,7 +73,21 @@ class Pot(ProgressibleItem): super().__init__(steps_needed=1500) def combine(self, other): - ... + pass + + def __repr__(self): + return f"{self.__class__.__name__}()" + + +class Pan(ProgressibleItem): + def can_combine(self, other): + return False + + def __init__(self): + super().__init__(steps_needed=1500) + + def combine(self, other): + pass def __repr__(self): return f"{self.__class__.__name__}()" diff --git a/overcooked_simulator/player.py b/overcooked_simulator/player.py index ab028d7197c576ecf6d388255d0e929295bd8e24..1213d5ee2beb6e8df1c107578e7829d1e74d4f73 100644 --- a/overcooked_simulator/player.py +++ b/overcooked_simulator/player.py @@ -4,7 +4,7 @@ import numpy as np import numpy.typing as npt from overcooked_simulator.counters import Counter -from overcooked_simulator.game_items import HoldableItem +from overcooked_simulator.game_items import Item class Player: @@ -17,7 +17,7 @@ class Player: def __init__(self, name: str, pos: npt.NDArray[float]): self.name: str = name self.pos: npt.NDArray[float] = np.array(pos, dtype=float) - self.holding: Optional[HoldableItem] = None + self.holding: Optional[Item] = None self.radius: int = 18 self.move_dist: int = 5 diff --git a/overcooked_simulator/pygame_gui/pygame_gui.py b/overcooked_simulator/pygame_gui/pygame_gui.py index a708b0889ff0210166b1601c310a0d54155d9287..667d12d759050472e4b36cbdac6ab10d216f6575 100644 --- a/overcooked_simulator/pygame_gui/pygame_gui.py +++ b/overcooked_simulator/pygame_gui/pygame_gui.py @@ -12,7 +12,7 @@ from overcooked_simulator.counters import ( PlateReturn, ServingWindow, ) -from overcooked_simulator.game_items import ProgressibleItem, Plate, HoldableItem +from overcooked_simulator.game_items import ProgressibleItem, Plate, Item from overcooked_simulator.game_items import Tomato from overcooked_simulator.overcooked_environment import Action from overcooked_simulator.simulation_runner import Simulator @@ -194,7 +194,7 @@ class PyGameGUI: holding_item_pos = player.pos + (20 * player.facing_direction) self.draw_item(holding_item_pos, player.holding) - def draw_item(self, pos, item: HoldableItem): + def draw_item(self, pos, item: Item): """Visualisation of an item at the specified position. On a counter or in the hands of the player.""" if isinstance(item, Tomato): if item.finished: