def test_single_robot_finish_single_block_goal(self):
     goal_building = GoalBuilding2D("""
     0 0 0 0 0 0 0 0 0 0 0
     0 0 0 0 0 0 0 0 0 0 0
     0 0 0 0 0 0 0 0 0 0 0
     0 0 0 0 1 0 0 0 0 0 0
     0 0 0 0 0 0 0 0 0 0 0
     0 0 0 0 0 0 0 0 0 0 0
     0 0 0 0 0 0 0 0 0 0 0
     """)
     robot = Robot(Direction.UP)
     robot.take_block(Tile(TileType.BLOCK))
     line_start_coordinates = Coordinates(0, 3)
     base_grid = BaseGrid(goal_building.width, goal_building.height)
     base_grid.add_tile_to_grid(robot, line_start_coordinates)
     shared_grid_access = SharedGridAccess(base_grid, manager=Manager())
     shared_actions_executor = RobotSharedActionsExecutor(
         robot=robot,
         shared_grid_access=shared_grid_access,
         private_grid=shared_grid_access.get_private_copy(),
         robot_coordinates=line_start_coordinates.copy())
     line_scanner_executor = LineScannerExecutor(
         shared_actions_executor=shared_actions_executor)
     line_to_middle = LineToMiddle(
         start_coordinates=line_start_coordinates.copy(),
         direction=Direction.RIGHT,
         block_line=map(bool, [0, 0, 0, 0, 1]))
     line_scanner_executor.scan_line(line=line_to_middle)
     grid = shared_grid_access.get_private_copy()
     assert line_to_middle.is_finished()
     assert goal_building.validate_grid(grid)
     assert grid.get_coord_from_tile(robot) == line_start_coordinates
Beispiel #2
0
 def move_tile_on_grid(self, tile: Tile, coordinates: Coordinates):
     if self.tiles_from_index.get(tile.get_id()) is None:
         raise TileNotExistsException("tile: (" + str(tile) +
                                      ") was not added")
     tile_on_coordinates = self.get_tile_from_grid(coordinates)
     if tile_on_coordinates is not None:
         if tile_on_coordinates.id != tile.id:
             raise TileTakenException(
                 tile_on_coordinates,
                 f"there is already tile: ({str(tile)}) on {str(coordinates)}"
             )
         # else it means we move to same tile we were on
     previous_coordinates = self.coordinates_from_index.get(tile.get_id())
     if previous_coordinates is None:
         raise TileNotExistsException("tile: (" + str(tile) +
                                      ") did not have coordinates")
     self.coordinates_from_index[tile.get_id()] = coordinates.copy()
     self.tile_grid[
         previous_coordinates.get_array_index()] = BaseGrid.empty_tile_id
     self.tile_grid[coordinates.get_array_index()] = tile.get_id()
     self.tiles_from_index[tile.get_id()] = tile
     if tile.get_type() == TileType.BLOCK:
         self.block_tile_grid[
             previous_coordinates.get_array_index()] = False
         self.block_tile_grid[coordinates.get_array_index()] = True
 def go_to_goal(self, goal: Coordinates):
     goal = goal.copy()
     while not self._is_robot_on_same_edge_and_not_too_far(goal):
         robot_edge_side = self.robot_coordinates.get_edge_side(
             width=self.width, height=self.height)
         next_corner = self.spin.get_edge_next_corner(robot_edge_side,
                                                      width=self.width,
                                                      height=self.height)
         pre_corner_pos = self.spin.get_pre_corner_coordinates(next_corner)
         moving_direction = self.spin.get_edge_move_direction(
             robot_edge_side)
         if self.robot_coordinates != pre_corner_pos:
             self.shared_actions_executor.try_rotate_robot(moving_direction)
         while self.robot_coordinates != pre_corner_pos:
             hit_information = self.shared_actions_executor.try_move_robot(
                 moving_direction)
             if hit_information.hit_type != HitType.NO_HIT:
                 self.shared_actions_executor.wait_action()
         # robot is on pre_corner_coordinates
         self._go_around_corner(moving_direction)
     # here robot is on same edge as goal
     moving_direction = self.robot_coordinates.get_to_other_direction(goal)
     if self.robot.rotation != moving_direction:
         self.shared_actions_executor.try_rotate_robot(moving_direction)
     while self.robot_coordinates != goal:
         hit_information = self.shared_actions_executor.try_move_robot(
             moving_direction)
         if hit_information.hit_type != HitType.NO_HIT:
             self.shared_actions_executor.wait_action()
 def __init__(self, start_coordinates: Coordinates, direction: Direction,
              block_line: Iterable[bool]):
     self.block_line = copy.deepcopy(block_line)
     self.block_positions = LineToMiddle.get_block_positions_from_block_line(
         block_line)
     self.direction = direction
     self.start_coordinates = start_coordinates.copy()
     self.blocks_placed = 0
     self.blocks_to_place = len(self.block_positions)
Beispiel #5
0
 def __init__(self, start_coordinates: Coordinates, direction: Direction,
              block_line: Iterable[bool]):
     self.block_line = copy.deepcopy(block_line)
     self.block_positions = LineToMiddle.get_block_positions_from_block_line(
         block_line)
     self.direction = direction
     self.start_coordinates = start_coordinates.copy()
     self.blocks_placed = 0
     self.blocks_to_place = len(self.block_positions)
     # last position where block could be placed or not
     if not self.is_finished():
         self.last_position = self.start_coordinates.create_moved_coordinate(
             self.direction, self.block_positions[0])
     else:
         self.last_position = self.start_coordinates