From 25f234dff080d4e9ee06a44217abbe0b05cac6fb Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Fri, 26 Mar 2021 13:23:17 +0100 Subject: [PATCH] Reduce chance that shop_slot_shuffle produces empty slots, at the cost of cpu time. --- Shops.py | 19 ++++++++----------- Utils.py | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Shops.py b/Shops.py index 4272524b..f67d1c2d 100644 --- a/Shops.py +++ b/Shops.py @@ -196,20 +196,21 @@ def ShopSlotFill(world): del locations_per_sphere - total_spheres = len(candidates_per_sphere) - for i, current_shop_slots in enumerate(shops_per_sphere): if current_shop_slots: - candidate_sphere_ids = list(range(i, total_spheres)) + # getting all candidates and shuffling them feels cpu expensive, there may be a better method + candidates = [(location, i) for i, candidates in enumerate(candidates_per_sphere[i:], start=i) + for location in candidates] + world.random.shuffle(candidates) for location in current_shop_slots: shop: Shop = location.parent_region.shop - swapping_sphere_id = world.random.choices(candidate_sphere_ids, - cum_weights=cumu_weights[i:])[0] - swapping_sphere: list = candidates_per_sphere[swapping_sphere_id] - for c in swapping_sphere: # chosen item locations + for index, (c, swapping_sphere_id) in enumerate(candidates): # chosen item locations if c.item_rule(location.item) and location.item_rule(c.item): swap_location_item(c, location, check_locked=False) logger.debug(f'Swapping {c} into {location}:: {location.item}') + # remove candidate + candidates_per_sphere[swapping_sphere_id].remove(c) + candidates.pop(index) break else: @@ -218,10 +219,6 @@ def ShopSlotFill(world): location.shop_slot_disabled = True continue - # remove candidate - swapping_sphere.remove(c) - cumu_weights[swapping_sphere_id] -= 1 - item_name = location.item.name if any(x in item_name for x in ['Compass', 'Map', 'Single Bomb', 'Single Arrow', 'Piece of Heart']): price = world.random.randrange(1, 7) diff --git a/Utils.py b/Utils.py index e7490b89..afda1693 100644 --- a/Utils.py +++ b/Utils.py @@ -13,7 +13,7 @@ class Version(typing.NamedTuple): micro: int -__version__ = "420.69.0" +__version__ = "4.1.2" _version_tuple = tuplize_version(__version__) import os