Fixed a bug in the balancing algorithm in non keysanity modes and increased the threshold

This commit is contained in:
Bonta-kun 2019-12-09 13:43:30 +01:00
parent 7a6c22c452
commit fe6a032f09
1 changed files with 6 additions and 8 deletions

14
Fill.py
View File

@ -338,8 +338,7 @@ def balance_multiworld_progression(world):
reachable_locations_count[location.player] += 1 reachable_locations_count[location.player] += 1
if checked_locations: if checked_locations:
average_reachable_locations = sum(reachable_locations_count.values()) / world.players threshold = max(reachable_locations_count.values()) - 20
threshold = ((average_reachable_locations + max(reachable_locations_count.values())) / 2) * 0.8 #todo: probably needs some tweaking
balancing_players = [player for player, reachables in reachable_locations_count.items() if reachables < threshold] balancing_players = [player for player, reachables in reachable_locations_count.items() if reachables < threshold]
if balancing_players: if balancing_players:
@ -386,13 +385,12 @@ def balance_multiworld_progression(world):
items_to_replace.append(testing) items_to_replace.append(testing)
replaced_items = False replaced_items = False
locations_for_replacing = [l for l in checked_locations if not l.event and not l.locked] replacement_locations = [l for l in checked_locations if not l.event and not l.locked]
while locations_for_replacing and items_to_replace: while replacement_locations and items_to_replace:
new_location = locations_for_replacing.pop() new_location = replacement_locations.pop()
old_location = items_to_replace.pop() old_location = items_to_replace.pop()
new_location.item, old_location.item = old_location.item, new_location.item new_location.item, old_location.item = old_location.item, new_location.item
new_location.event = True new_location.event, old_location.event = True, False
old_location.event = False
state.collect(new_location.item, True, new_location) state.collect(new_location.item, True, new_location)
replaced_items = True replaced_items = True
if replaced_items: if replaced_items:
@ -402,7 +400,7 @@ def balance_multiworld_progression(world):
sphere_locations.append(location) sphere_locations.append(location)
for location in sphere_locations: for location in sphere_locations:
if location.event: if location.event and (world.keysanity or not location.item.key):
state.collect(location.item, True, location) state.collect(location.item, True, location)
checked_locations.extend(sphere_locations) checked_locations.extend(sphere_locations)