Skip to content
Snippets Groups Projects
counters.py 2.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • from overcooked_simulator.game_items import CuttableItem
    
    
    Fabian Heinrich's avatar
    Fabian Heinrich committed
        """Simple class for a counter at a specified position (center of counter). Can hold things on top."""
    
    
        def __init__(self, pos: np.array):
            self.pos = pos
            self.occupied_by = None
    
    
        def pick_up(self):
            """Gets called upon a player performing the pickup action. If the counter can give something to
            the player, it does so. In the standard counter this is when an item is on the counter.
    
            Returns: The item which the counter is occupied by. None if nothing is there.
    
            """
            give_player = self.occupied_by
            self.occupied_by = None
            return give_player
    
        def drop_off(self, item):
            """Takes the thing dropped of by the player.
    
            Args:
                item: The item to be placed on the counter.
    
            Returns: TODO Return information, wether the score is affected (Serving Window?)
    
            """
            if self.occupied_by is None:
                self.occupied_by = item
    
        def can_drop_off(self, item):
            """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.
    
            Args:
                item: The item for which to check, if it can be placed on the counter.
    
            Returns: True if the item can be placed on the counter, False if not.
    
            """
            return self.occupied_by is None
    
        def interact_start(self):
            """Starts an interaction by the player. Nothing happens for the standard counter."""
            pass
    
        def interact_stop(self):
            """Stops an interaction by the player. Nothing happens for the standard counter."""
            pass
    
    
            return f"Counter(pos:{str(self.pos)},holds:{self.occupied_by})"
    
    
    
    class CuttingBoard(Counter):
        def __init__(self, pos):
            self.progressing = False
            super().__init__(pos)
    
        def progress(self):
            """Called by environment step function for time progression"""
            if self.progressing:
                if isinstance(self.occupied_by, CuttableItem):
                    self.occupied_by.progress()
    
        def start_progress(self):
    
            """Starts the cutting process."""
    
            self.progressing = True
    
        def pause_progress(self):
    
            """Pauses the cutting process"""
    
            self.progressing = False
    
        def interact_start(self):
    
            """Handles player interaction, starting to hold key down."""
    
            self.start_progress()
    
        def interact_stop(self):
    
            """Handles player interaction, stopping to hold key down."""
    
            self.pause_progress()
    
        def __repr__(self):
            return f"CuttingBoard({self.occupied_by})"