예제 #1
0
 def _is_robot_on_same_edge_and_not_too_far(self,
                                            goal: Coordinates) -> bool:
     robot_edge_side = self.robot_coordinates.get_edge_side(
         width=self.width, height=self.height)
     goal_edge_side = goal.get_edge_side(width=self.width,
                                         height=self.height)
     if robot_edge_side != goal_edge_side:
         return False
     moving_direction = self.spin.get_edge_move_direction(robot_edge_side)
     # distance <0 means we already are too far from source and need to make another lap
     return self.robot_coordinates.get_straight_distance_to_other(
         moving_direction, goal) >= 0
 def __init__(self,
              robot: Robot,
              shared_grid_access: SharedGridAccess,
              goal_building: GoalBuilding,
              goal_to_edges_splitter: GoalToEdgesSplitter,
              spin: Spin,
              sleep_tick_seconds: float = None,
              robot_coordinates: Coordinates = None,
              start_offset: int = 0,
              start_edge_index: int = None):
     super().__init__(robot, shared_grid_access, goal_building, robot_coordinates=robot_coordinates,
                      sleep_tick_seconds=sleep_tick_seconds)
     self.private_grid.add_tile_to_grid(self.robot, self.robot_coordinates.copy())
     self.start_offset = start_offset
     self.robot_coordinates = self.private_grid.get_coord_from_tile(robot)
     self.spin = spin
     self.highway_executor = HighwayExecutor(
         shared_actions_executor=self.shared_actions_executor,
         spin=spin
     )
     self.line_scanner_executor = LineScannerExecutor(
         shared_actions_executor=self.shared_actions_executor
     )
     self.edges: List[GridEdge] = goal_to_edges_splitter.get_edges()
     if start_edge_index is None:
         edge_side = robot_coordinates.get_edge_side(width=goal_building.width, height=goal_building.height)
         next_side = spin.get_edge_move_direction(edge_side)
         for i in range(0, 4):
             self.edge_index = i
             self.edge = self.edges[self.edge_index]
             if next_side == self.edge.edge_side:
                 print(f"robot: {robot} got side {next_side}")
                 break
     else:
         self.edge_index = start_edge_index
         self.edge = self.edges[self.edge_index % 4]