示例#1
0
 def do(self, grid: Grid, robot: Robot):
     if robot.is_lost:
         raise Exception('Dead')
     orientation = robot.orientation
     current_pos = robot.position
     # Ignore instruction if known bad place.
     if MoveForward.__to_dropoff(grid, current_pos, orientation):
         return
     next_position = orientation.next_forward_position(current_pos)
     if grid.is_within_grid(next_position):
         robot.set_position(next_position)
     else:
         robot.is_now_lost()
         label = Label(orientation)
         grid.add_scent(current_pos, label)
示例#2
0
 def do(self, grid: Grid, robot: Robot):
     robot.set_state(self.pos, self.orientation)
     if not grid.is_within_grid(robot.position):
         robot.is_now_lost()