Newer
Older

Fabian Heinrich
committed
from typing import Optional
from overcooked_simulator.game_items import (
CuttableItem,
HoldableItem,
ProgressibleItem,
Plate,
Tomato,
)
"""Simple class for a counter at a specified position (center of counter). Can hold things on top."""

Fabian Heinrich
committed
def __init__(self, pos: np.ndarray):
self.pos: np.ndarray = pos
self.occupied_by: Optional[HoldableItem] = None

Fabian Heinrich
committed
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

Fabian Heinrich
committed
def can_drop_off(self, item: HoldableItem):
"""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.

Fabian Heinrich
committed
Args:

Fabian Heinrich
committed
item: The item for which to check, if it can be placed on the counter.

Fabian Heinrich
committed

Fabian Heinrich
committed
Returns: True if the item can be placed on the counter, False if not.

Fabian Heinrich
committed
"""

Fabian Heinrich
committed
return self.occupied_by is None or self.occupied_by.can_combine(item)

Fabian Heinrich
committed

Fabian Heinrich
committed
def drop_off(self, item: HoldableItem):
"""Takes the thing dropped of by the player.

Fabian Heinrich
committed
Args:

Fabian Heinrich
committed
item: The item to be placed on the counter.

Fabian Heinrich
committed

Fabian Heinrich
committed
Returns: TODO Return information, wether the score is affected (Serving Window?)

Fabian Heinrich
committed
"""

Fabian Heinrich
committed
if self.occupied_by is None:
self.occupied_by = item
elif self.occupied_by.can_combine(item):
self.occupied_by.combine(item)

Fabian Heinrich
committed
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})"

Fabian Heinrich
committed
def __init__(self, pos: np.ndarray):
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):
self.progressing = True
def pause_progress(self):
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})"
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
class ServingWindow(Counter):
def drop_off(self, item):
return 5
def can_score(self, item):
if isinstance(item, Plate) and isinstance(item.holds, ProgressibleItem):
return item.holds.finished
def can_drop_off(self, item: HoldableItem):
return self.can_score(item)
def pick_up(self):
return None
def __repr__(self):
return "ServingWindow"
class PlateReturn(Counter):
def __init__(self, pos):
super().__init__(pos)
self.occupied_by = Plate()
def pick_up(self):
return Plate()
def drop_off(self, item):
return 0
def can_drop_off(self, item):
return False
def __repr__(self):
return "PlateReturn"
class TomatoDispenser(Counter):
def __init__(self, pos):
super().__init__(pos)
def pick_up(self):
return Tomato()
def drop_off(self, item: HoldableItem):
return 0
def can_drop_off(self, item: HoldableItem):
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):
if isinstance(item, Plate):
item.holds = None
return -1
def can_drop_off(self, item: HoldableItem):
return True
def __repr__(self):
return "Trash"