def select_grids(grids, nearby=False, is_accessible=True, scale=(), genre=(), strongest=False, weakest=False, sort=('weight', 'cost'), ignore=None): """ Args: grids (SelectedGrids): nearby (bool): is_accessible (bool): scale (tuple[int], list[int]): Tuple: select out of order, list: select in order. genre (tuple[str], list[str]): light, main, carrier, treasure. (Case insensitive). strongest (bool): weakest (bool): sort (tuple(str)): ignore (SelectedGrids): Returns: SelectedGrids: """ if nearby: grids = grids.select(is_nearby=True) if is_accessible: grids = grids.select(is_accessible=True) if ignore is not None: grids = grids.delete(grids=ignore) if len(scale): enemy = SelectedGrids([]) for enemy_scale in scale: enemy = enemy.add(grids.select(enemy_scale=enemy_scale)) if isinstance(scale, list) and enemy: break grids = enemy if len(genre): enemy = SelectedGrids([]) for enemy_genre in genre: # enemy_genre should be camel case enemy_genre = enemy_genre[0].upper() + enemy_genre[1:] if enemy_genre[0].islower() else enemy_genre enemy = enemy.add(grids.select(enemy_genre=enemy_genre)) if isinstance(genre, list) and enemy: break grids = enemy if strongest: for scale in [3, 2, 1, 0]: enemy = grids.select(enemy_scale=scale) if enemy: grids = enemy break if weakest: for scale in [1, 2, 3, 0]: enemy = grids.select(enemy_scale=scale) if enemy: grids = enemy break if grids: grids = grids.sort(*sort) return grids
def clear_potential_roadblocks(self, roads, **kwargs): """Avoid roadblock that only has one grid empty. Args: roads(list[RoadGrids]): Returns: bool: True if clear an enemy. """ grids = SelectedGrids([]) for road in roads: grids = grids.add(road.potential_roadblocks()) target = self.config.EnemyPriority_EnemyScaleBalanceWeight if target == 'S3_enemy_first': kwargs['strongest'] = True elif target == 'S1_enemy_first': kwargs['weakest'] = True elif self.config.MAP_CLEAR_ALL_THIS_TIME: kwargs['strongest'] = True grids = self.select_grids(grids, **kwargs) if grids: logger.hr('Avoid potential roadblock') self.show_select_grids(grids, **kwargs) self.clear_chosen_enemy(grids[0]) return True return False
def clear_roadblocks(self, roads, **kwargs): """Clear roadblocks. Args: roads(list[RoadGrids]): Returns: bool: True if clear an enemy. """ grids = SelectedGrids([]) for road in roads: grids = grids.add(road.roadblocks()) target = self.config.EnemyPriority_EnemyScaleBalanceWeight if target == 'S3_enemy_first': grids = self.select_grids(grids, strongest=True, **kwargs) elif target == 'S1_enemy_first': grids = self.select_grids(grids, weakest=True, **kwargs) else: grids = self.select_grids(grids, **kwargs) if grids: logger.hr('Clear roadblock') self.show_select_grids(grids, **kwargs) self.clear_chosen_enemy(grids[0]) return True return False
def clear_first_roadblocks(self, roads, **kwargs): """Ensure every roadblocks have one grid with is_cleared=True. Args: roads(list[RoadGrids]): Returns: bool: True if clear an enemy. """ grids = SelectedGrids([]) for road in roads: grids = grids.add(road.first_roadblocks()) grids = self.select_grids(grids, **kwargs) if grids: logger.hr('Clear first roadblock') self.show_select_grids(grids, **kwargs) self.clear_chosen_enemy(grids[0]) return True return False
def clear_potential_roadblocks(self, roads, **kwargs): """Avoid roadblock that only has one grid empty. Args: roads(list[RoadGrids]): Returns: bool: True if clear an enemy. """ grids = SelectedGrids([]) for road in roads: grids = grids.add(road.potential_roadblocks()) grids = self.select_grids(grids, **kwargs) if grids: logger.hr('Avoid potential roadblock') self.show_select_grids(grids, **kwargs) self.clear_chosen_enemy(grids[0]) return True return False
def clear_roadblocks(self, roads, **kwargs): """Clear roadblocks. Args: roads(list[RoadGrids]): Returns: bool: True if clear an enemy. """ grids = SelectedGrids([]) for road in roads: grids = grids.add(road.roadblocks()) grids = self.select_grids(grids, **kwargs) if grids: logger.hr('Clear roadblock') self.show_select_grids(grids, **kwargs) self.clear_chosen_enemy(grids[0]) return True return False
def select_grids(grids, nearby=False, is_accessible=True, scale=(), genre=(), strongest=False, weakest=False, cost=True, weight=True, ignore=None): """ Args: grids (SelectedGrids): nearby (bool): is_accessible (bool): scale (tuple[int], list[int]): Tuple: select out of order, list: select in order. genre (tuple[str], list[str]): light, main, carrier, treasure. (Case insensitive). strongest (bool): weakest (bool): cost (bool): weight (bool): ignore (SelectedGrids): Returns: SelectedGrids: """ if nearby: grids = grids.select(is_nearby=True) if is_accessible: grids = grids.select(is_accessible=True) if ignore is not None: grids = grids.delete(grids=ignore) if len(scale): enemy = SelectedGrids([]) for enemy_scale in scale: enemy = enemy.add(grids.select(enemy_scale=enemy_scale)) if isinstance(scale, list) and enemy: break grids = enemy if len(genre): enemy = SelectedGrids([]) for enemy_genre in genre: enemy = enemy.add( grids.select(enemy_genre=enemy_genre.capitalize())) if isinstance(genre, list) and enemy: break grids = enemy if strongest: for scale in [3, 2, 1, 0]: enemy = grids.select(enemy_scale=scale) if enemy: grids = enemy break if weakest: for scale in [1, 2, 3, 0]: enemy = grids.select(enemy_scale=scale) if enemy: grids = enemy break if grids: grids = grids.sort(cost=cost, weight=weight) return grids