import copy from src.obj.Object import Object class Waiter(Object): def __init__(self, position, orientation, square_size, screen_size, basket=[], memory=[], battery=300): super().__init__("waiter", position, orientation, square_size, screen_size) self.battery = battery self.basket_size = 4 self.memory_size = 4 self.basket = basket self.memory = memory self.prev_position = copy.deepcopy(self.position) self.prev_orientation = copy.copy(self.orientation) def changeState(self, state): self.position = copy.deepcopy(state.position) self.orientation = copy.copy(state.orientation) self.basket = copy.copy(state.basket) self.battery -= state.cost return state def dish_in_basket(self, table) -> bool: return table in self.basket def basket_is_full(self) -> bool: return self.basket_size == 0 def combine_orders(self): while not self.basket_is_full() and not self.memory_is_empty(): dish = self.memory.pop() dish.set_done() self.basket.append(dish) self.basket_size -= 1 self.memory_size += 1 def deliver_dish(self, table): if table in self.basket: table.reset() self.basket.remove(table) self.basket_size += 1 def order_in_memory(self, table) -> bool: return table in self.memory def memory_is_empty(self) -> bool: return not self.memory def memory_is_full(self) -> bool: return self.memory_size == 0 def collect_order(self, table): if self.memory_is_full(): return if table.agent_role == "order": table.set_wait() self.memory.append(table) self.memory_size -= 1 def battary_status(self) -> str: if self.battery >= 200: return (2, "hight") elif self.battery >= 100: return (1, "medium") else: return (0, "low") def recharge(self): self.battery = 300 def left(self): self.orientation = (self.orientation + 1) % 4 def right(self): self.orientation = (self.orientation - 1) % 4 def front(self): if self.orientation % 2: # x (1 or 3) self.position[0] += self.orientation - 2 # x (-1 or +1) else: # y (0 or 2) self.position[1] += self.orientation - 1 # y (-1 or +1)