def sample_nearby_position(self, position, exclude_locations=None):
    """Sample an available position that is next to the given position."""
    actual_available_positions = self.get_nearby_positions(
        position, exclude_locations=exclude_locations)
    if actual_available_positions:
      sampled_position = random.sample(
          list(actual_available_positions), 1
      ).pop()
      return world.Position(column=sampled_position[0], row=sampled_position[1])
    return None
Sample an available position that is next to the given position.
language/gscan/data/world.py