From 4a5a79988f8ad24bbe1ab32714f15e546aaf9029 Mon Sep 17 00:00:00 2001 From: spinerak Date: Fri, 14 Jun 2024 20:30:41 +0200 Subject: [PATCH] Adjusted max_dist, split dice_simulation function --- worlds/yachtdice/Rules.py | 36 +++++++++++++++++++----------------- worlds/yachtdice/__init__.py | 8 ++++---- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/worlds/yachtdice/Rules.py b/worlds/yachtdice/Rules.py index 69f6a4bd67..51df560811 100644 --- a/worlds/yachtdice/Rules.py +++ b/worlds/yachtdice/Rules.py @@ -154,18 +154,18 @@ def dice_simulation_strings(categories, num_dice, num_rolls, fixed_mult, step_mu def max_dist(dist1, mults): new_dist = {0: 1} for mult in mults: - c = new_dist.copy() - new_dist = {} - for val1, prob1 in c.items(): + temp_dist = {} + for val1, prob1 in new_dist.items(): for val2, prob2 in dist1.items(): new_val = int(max(val1, val2 * mult)) new_prob = prob1 * prob2 # Update the probability for the new value - if new_val in new_dist: - new_dist[new_val] += new_prob + if new_val in temp_dist: + temp_dist[new_val] += new_prob else: - new_dist[new_val] = new_prob + temp_dist[new_val] = new_prob + new_dist = temp_dist return new_dist @@ -215,20 +215,22 @@ def dice_simulation_strings(categories, num_dice, num_rolls, fixed_mult, step_mu return yachtdice_cache[tup] - -def dice_simulation(state, player, options): +def dice_simulation_fill_pool(state, options): """ Returns the feasible score that one can reach with the current state, options and difficulty. """ - # if the player is called "state_is_a_list", we are filling the itempool and want to calculate anyways. - if player == "state_is_a_list": - categories, num_dice, num_rolls, fixed_mult, step_mult, expoints = extract_progression(state, player, options) - return ( - dice_simulation_strings( - categories, num_dice, num_rolls, fixed_mult, step_mult, options.game_difficulty.value - ) - + expoints + categories, num_dice, num_rolls, fixed_mult, step_mult, expoints = extract_progression(state, "state_is_a_list", options) + return ( + dice_simulation_strings( + categories, num_dice, num_rolls, fixed_mult, step_mult, options.game_difficulty.value ) + + expoints + ) + +def dice_simulation_state_change(state, player, options): + """ + Returns the feasible score that one can reach with the current state, options and difficulty. + """ if state.prog_items[player]["state_is_fresh"] == 0: state.prog_items[player]["state_is_fresh"] = 1 @@ -252,7 +254,7 @@ def set_yacht_rules(world: MultiWorld, player: int, options): for location in world.get_locations(player): set_rule( location, - lambda state, curscore=location.yacht_dice_score, player=player: dice_simulation(state, player, options) + lambda state, curscore=location.yacht_dice_score, player=player: dice_simulation_state_change(state, player, options) >= curscore, ) diff --git a/worlds/yachtdice/__init__.py b/worlds/yachtdice/__init__.py index 5a40713da2..e6e79e76a9 100644 --- a/worlds/yachtdice/__init__.py +++ b/worlds/yachtdice/__init__.py @@ -7,7 +7,7 @@ from worlds.AutoWorld import WebWorld, World from .Items import YachtDiceItem, item_groups, item_table from .Locations import YachtDiceLocation, all_locations, ini_locations from .Options import YachtDiceOptions, yd_option_groups -from .Rules import dice_simulation, set_yacht_completion_rules, set_yacht_rules +from .Rules import dice_simulation_fill_pool, dice_simulation_state_change, set_yacht_completion_rules, set_yacht_rules class YachtDiceWeb(WebWorld): @@ -260,14 +260,14 @@ class YachtDiceWorld(World): for _ in range(17): self.itempool.append(get_item_to_add()) - score_in_logic = dice_simulation(self.itempool + self.precollected, "state_is_a_list", self.options) + score_in_logic = dice_simulation_fill_pool(self.itempool + self.precollected, self.options) # if we overshoot, remove items until you get below 1000, then return the last removed item if score_in_logic > 1000: removed_item = "" while score_in_logic > 1000: removed_item = self.itempool.pop() - score_in_logic = dice_simulation(self.itempool + self.precollected, "state_is_a_list", self.options) + score_in_logic = dice_simulation_fill_pool(self.itempool + self.precollected, self.options) self.itempool.append(removed_item) else: # Keep adding items until a score of 1000 is in logic @@ -281,7 +281,7 @@ class YachtDiceWorld(World): elif item_to_add == "100 Points": score_in_logic += 100 else: - score_in_logic = dice_simulation(self.itempool + self.precollected, "state_is_a_list", self.options) + score_in_logic = dice_simulation_fill_pool(self.itempool + self.precollected, self.options) # count the number of locations in the game. already_items = len(self.itempool) + 1 # +1 because of Victory item