def update_required_items(spoiler): worlds = spoiler.worlds # get list of all of the progressive items that can appear in hints # all_locations: all progressive items. have to collect from these # item_locations: only the ones that should appear as "required"/WotH all_locations = [ location for world in worlds for location in world.get_filled_locations() ] # Set to test inclusion against item_locations = { location for location in all_locations if location.item.majoritem and not location.locked and location.item.name != 'Triforce Piece' } # if the playthrough was generated, filter the list of locations to the # locations in the playthrough. The required locations is a subset of these # locations. Can't use the locations directly since they are location to the # copied spoiler world, so must compare via name and world id if spoiler.playthrough: translate = lambda loc: worlds[loc.world.id].get_location(loc.name) spoiler_locations = set( map( translate, itertools.chain.from_iterable( spoiler.playthrough.values()))) item_locations &= spoiler_locations required_locations = [] search = Search([world.state for world in worlds]) for location in search.iter_reachable_locations(all_locations): # Try to remove items one at a time and see if the game is still beatable if location in item_locations: old_item = location.item location.item = None # copies state! This is very important as we're in the middle of a search # already, but beneficially, has search it can start from if not search.can_beat_game(): required_locations.append(location) location.item = old_item search.state_list[location.item.world.id].collect(location.item) # Filter the required location to only include location in the world required_locations_dict = {} for world in worlds: required_locations_dict[world.id] = list( filter(lambda location: location.world.id == world.id, required_locations)) spoiler.required_locations = required_locations_dict
def find_light_arrows(spoiler): search = Search([world.state for world in spoiler.worlds]) for location in search.iter_reachable_locations( search.progression_locations()): search.collect(location.item) maybe_set_light_arrows(location)