From e778e49574d286c97c9176821ddaf1acee2fa728 Mon Sep 17 00:00:00 2001 From: Zach Parks Date: Wed, 5 Apr 2023 12:11:34 -0500 Subject: [PATCH] Core: Fix ZeroDivisionError if a world is contained 100% locked locations. (#1659) * Core: Fix divide by zero error if all locations are priority * Core: 100% makes more sense than 0% in this context * Core: Revert a some "autoformatter" damage * Core: Move comparisons a bit earlier. Worlds that are 100% filled with locked locations should now be completely skipped in the progression balancing step now as we filter them out at the very beginning of the stage now. Also skips progression balancing if it turns out all locations are locked early before attempting to balance. --- Fill.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Fill.py b/Fill.py index ef84a23b..6fa5ecb0 100644 --- a/Fill.py +++ b/Fill.py @@ -1,11 +1,10 @@ -import logging -import typing import collections import itertools +import logging +import typing from collections import Counter, deque -from BaseClasses import CollectionState, Location, LocationProgressType, MultiWorld, Item, ItemClassification - +from BaseClasses import CollectionState, Item, Location, LocationProgressType, MultiWorld from worlds.AutoWorld import call_all from worlds.generic.Rules import add_item_rule @@ -526,16 +525,16 @@ def balance_multiworld_progression(world: MultiWorld) -> None: checked_locations: typing.Set[Location] = set() unchecked_locations: typing.Set[Location] = set(world.get_locations()) - reachable_locations_count: typing.Dict[int, int] = { - player: 0 - for player in world.player_ids - if len(world.get_filled_locations(player)) != 0 - } total_locations_count: typing.Counter[int] = Counter( location.player for location in world.get_locations() if not location.locked ) + reachable_locations_count: typing.Dict[int, int] = { + player: 0 + for player in world.player_ids + if total_locations_count[player] and len(world.get_filled_locations(player)) != 0 + } balanceable_players = { player: balanceable_players[player] for player in balanceable_players @@ -552,6 +551,10 @@ def balance_multiworld_progression(world: MultiWorld) -> None: def item_percentage(player: int, num: int) -> float: return num / total_locations_count[player] + # If there are no locations that aren't locked, there's no point in attempting to balance progression. + if len(total_locations_count) == 0: + return + while True: # Gather non-locked locations. # This ensures that only shuffled locations get counted for progression balancing, @@ -825,7 +828,6 @@ def distribute_planned(world: MultiWorld) -> None: for player in worlds: locations += non_early_locations[player] - block['locations'] = locations if not block['count']: