def sample_non_nearby_position(self, position):
    """Sample an available position that is not next to the given position."""
    all_positions = set(
        itertools.product(
            list(range(self.grid_size)), list(range(self.grid_size))))
    available_positions = all_positions - self._occupied_positions
    nearby_positions = set([(position.column - dir[0], position.row - dir[1])
                            for dir in DIR_TO_DIR_VEC.values()])
    actual_available_positions = available_positions - nearby_positions
    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 not next to the given position.
language/gscan/data/world.py