import copy from src.obj.Object import Object class Waiter(Object): def __init__(self, position, orientation, square_size, square_count, basket=[]): super().__init__("waiter", position, orientation, square_size, square_count) self.basket_size = 2 self.basket = basket self.prev_position = copy.deepcopy(self.position) self.prev_orientation = copy.copy(self.orientation) def dampState(self): self.prev_position = copy.deepcopy(self.position) self.prev_orientation = copy.copy(self.orientation) def rollbackState(self): self.position = copy.deepcopy(self.prev_position) self.orientation = copy.copy(self.prev_orientation) def take_order(self, table) -> bool: if table.agent_role == "order": if len(self.basket) < self.basket_size: table.next_role(self) self.basket.append(table) return True return False def drop_order(self, table) -> bool: if table.agent_role == "done": self.basket.remove(table) table.next_role(self) return True return False def orders_in_basket(self) -> bool: return self.basket 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) def collide_test(self, obj) -> bool: out_of_range = [ self.position[0] >= self.square_count, self.position[1] >= self.square_count, self.position[0] < 0, self.position[1] < 0 ] return any(out_of_range) def goal_test(self, engine): return any([o.goal_test(self) for o in engine.objects])