from src.obj.Waiter import Waiter import copy class TemporaryState(Waiter): def __init__(self, parent, action="blank"): super().__init__(copy.deepcopy(parent.position), copy.copy(parent.orientation), copy.copy(parent.square_size), copy.copy(parent.square_count), copy.copy(parent.basket)) self.parent = parent self.change_role(action) self.apply_transformation() def apply_transformation(self): if self.agent_role == "left": self.orientation = (self.orientation + 1) % 4 elif self.agent_role == "right": self.orientation = (self.orientation - 1) % 4 elif self.agent_role == "front": 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 left(self): return TemporaryState(self, "left") def right(self): return TemporaryState(self, "right") def front(self): return TemporaryState(self, "front") def collide_test(self) -> 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 compare(self, state) -> bool: conditions = [ self.position == state.position, self.orientation == state.orientation ] return all(conditions)