def __init__(self, input_dict): self.search = aStarSearch() ''' Create a new FeatureExtractor from a dict object.''' new_type = input_dict['_type'] if new_type == BasicFeatures.type_name: self.__class__ = BasicFeatures elif new_type == QualifyingFeatures.type_name: self.__class__ = QualifyingFeatures elif new_type == CompositingFeatures.type_name: self.__class__ = CompositingFeatures elif new_type == AdvancedFeatures.type_name: self.__class__ = AdvancedFeatures else: raise Exception("Invalid feature class %s" + new_type) self.feature_names = [] self.feature_id = {} # Call class-specific initialization. self.init_from_dict(input_dict) fid = 0 for name in self.feature_names: self.feature_id[name] = fid fid += 1
def moving_towards_on_astar(self, world, loc, new_loc, target, state): """ Returns true, if the new_loc is the next step to go towards the target on an aStar Path. """ if self.pathfinder is None: self.pathfinder = aStarSearch(world, use_cache=self.use_astar_cache) if self.pathfinder.lookup(loc, target) and self.pathfinder.lookup(new_loc, target): return self.pathfinder.lookup(loc, target) elif state.a_star_counter < 0: state.a_star_counter += 1 # Generate an a*-path cur_path_len = self.pathfinder.get_path(loc, target) next_path_len = self.pathfinder.get_path(new_loc,target) if cur_path_len: return next_path_len and next_path_len < cur_path_len else: # Food not near enough for this ant return False else: # Fall back to greedy approximation return self.moving_towards(world, loc, new_loc, target, state)
def __init__(self): FeatureExtractor.__init__(self, {'_type': AdvancedFeatures.type_name}) self.search = aStarSearch()