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.
This commit is contained in:
Zach Parks 2023-04-05 12:11:34 -05:00 committed by GitHub
parent 25f7413881
commit e778e49574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 10 deletions

22
Fill.py
View File

@ -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']: