def update_task_influence(self, influence): 'update dynamic goal values depending on current situation' # assess situation my_tiles = [loc for loc in influence.map if math.fabs(influence.map[loc]) > 0.01] total_tile_count = self.gamestate.cols * self.gamestate.rows self.winning_percentage = float(len(my_tiles))/total_tile_count debug_logger.debug('currently owning %d in %d tiles, ratio: %f' % (len(my_tiles), total_tile_count, self.winning_percentage)) debug_logger.debug('my ant_hill is at %s' % str(self.gamestate.my_hills())) debug_logger.debug('known enemy hill: %s' % str(self.gamestate.enemy_hills())) # alter aggressiveness as situation changes self.my_fighter_value = 0 - 1 - (self.winning_percentage / 0.3 % 1) self.enemy_ant_value = 0 - (self.winning_percentage / 0.3 % 1) * 2 # hill defense if len(self.gamestate.my_hills()) == 1: my_hill = self.gamestate.my_hills()[0] for enemy_ninja in [ant for ant, owner in self.gamestate.enemy_ants() if self.gamestate.manhattan_distance(my_hill, ant) < 8]: influence.map[my_hill] += self.enemy_ninja_value ## create route task # find area with highest ant density high_dense_loc = max(influence.map, key=influence.map.get) high_dense_val = influence.map[high_dense_loc] # find closest desirable area using bfs route = path.bfs_findtask(self.gamestate, influence, high_dense_loc, 500) # setup task, only long distance ones count if len(route) > 8: self.route_task = (route, high_dense_val) debug_logger.debug('found route_task: %s' % str(self.route_task))
def update_task_influence(self, influence): 'update dynamic goal values depending on current situation' # assess situation my_tiles = [loc for loc in influence.map if math.fabs(influence.map[loc]) > 0.01] total_tile_count = self.gamestate.cols * self.gamestate.rows self.winning_percentage = len(my_tiles), total_tile_count, float(len(my_tiles))/total_tile_count logging.debug('currently owning %d in %d tiles, ratio: %f' % self.winning_percentage) logging.debug('my ant_hill is at %s' % str(self.gamestate.my_hills())) logging.debug('known enemy hill: %s' % str(self.gamestate.enemy_hills())) # if winning # if losing # unsure ## create route task # find area with highest ant density high_dense_loc = max(influence.map, key=influence.map.get) high_dense_val = influence.map[high_dense_loc] # find closest desirable area using bfs route = path.bfs_findtask(self.gamestate, influence, high_dense_loc, 500) # setup task if len(route) > 3: self.route_task = (route, high_dense_val) logging.debug('found route_task: %s' % str(self.route_task))