diff --git a/overcooked_simulator/counters.py b/overcooked_simulator/counters.py index aa372ed9d4beb57dda8a34097fa967497eca375c..28265ccdb1030c8e6608f7e059cb37c1391aa626 100644 --- a/overcooked_simulator/counters.py +++ b/overcooked_simulator/counters.py @@ -122,13 +122,37 @@ class PlateReturn(Counter): self.occupied_by = Plate() def pick_up(self): - return Plate() + """Gets called upon a player performing the pickup action. Gives back a plate (possibly with ingredient. - def drop_off(self, item): - return 0 + Returns: A plate possibly with an ingredient on it. - def can_drop_off(self, item): - return False + """ + give_player = self.occupied_by + self.occupied_by = Plate() + return give_player + + def drop_off(self, item: HoldableItem): + """Takes the ingredient dropped of by the player. + + Args: + item: The ingredient to be placed on the counter. + """ + if item is Plate() and self.occupied_by is Plate(): + self.occupied_by = None + + def can_drop_off(self, item: HoldableItem): + """Checks whether an ingredient by the player can be dropped of. + + Args: + item: The ingredient for which to check, if it can be placed on the counter. + + Returns: True if the ingredient can be placed on the counter, False if not. + + """ + # possibility to drop off empty plate on empty plate return + return ( + isinstance(self.occupied_by, Plate) and isinstance(item, Plate) + ) or self.occupied_by.can_combine(item) def __repr__(self): return "PlateReturn" diff --git a/overcooked_simulator/game_items.py b/overcooked_simulator/game_items.py index b713fbfdab08d1e5cd666e4cd0fac8c79327753c..0740bdc92a8bca6d237979a1c53a5d7d2e4a73b7 100644 --- a/overcooked_simulator/game_items.py +++ b/overcooked_simulator/game_items.py @@ -18,7 +18,7 @@ class Plate(HoldableItem): super().__init__() def can_combine(self, other: HoldableItem): - return self.holds is None + return self.holds is None and not isinstance(other, Plate) def combine(self, other): self.holds = other