From 3e8d89f2e0cedae2a68be018f20ad51ecbf6275d Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:49:24 +0200 Subject: [PATCH 1/4] Improve performance of Yacht Dice --- worlds/yachtdice/Rules.py | 26 +++++++++++++++++++------- worlds/yachtdice/__init__.py | 16 +++++++++++++++- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/worlds/yachtdice/Rules.py b/worlds/yachtdice/Rules.py index a81e17bb56..e5e8e768b6 100644 --- a/worlds/yachtdice/Rules.py +++ b/worlds/yachtdice/Rules.py @@ -205,17 +205,29 @@ def dice_simulation_strings(categories, num_dice, num_rolls, fixed_mult, step_mu # Returns the feasible score that one can reach with the current state, options and difficulty. def dice_simulation(state, player, options): - 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 + 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 + if state.prog_items[player]["state_is_fresh"] == 0: + state.prog_items[player]["state_is_fresh"] = 1 + categories, num_dice, num_rolls, fixed_mult, step_mult, expoints = extract_progression(state, player, options) + state.prog_items[player]["maximum_achievable_score"] = dice_simulation_strings( + categories, num_dice, num_rolls, fixed_mult, step_mult, options.game_difficulty.value + ) + expoints + + return state.prog_items[player]["maximum_achievable_score"] + + # Sets rules on entrances and advancements that are always applied def set_yacht_rules(world: MultiWorld, player: int, options): for l in world.get_locations(player): - set_rule(l, - lambda state, - curscore=l.yacht_dice_score, - player=player: + set_rule(l, + lambda state, + curscore=l.yacht_dice_score, + player=player: dice_simulation(state, player, options) >= curscore) # Sets rules on completion condition diff --git a/worlds/yachtdice/__init__.py b/worlds/yachtdice/__init__.py index 162b8e0832..e5fedd57ba 100644 --- a/worlds/yachtdice/__init__.py +++ b/worlds/yachtdice/__init__.py @@ -395,4 +395,18 @@ class YachtDiceWorld(World): def create_item(self, name: str) -> Item: item_data = item_table[name] item = YachtDiceItem(name, item_data.classification, item_data.code, self.player) - return item \ No newline at end of file + return item + + def collect(self, state, item: Item) -> bool: + change = super().collect(state, item) + if change and item.advancement: + state.prog_items[self.player]["state_is_fresh"] = 0 + + return change + + def remove(self, state, item: Item) -> bool: + change = super().remove(state, item) + if change and item.advancement: + state.prog_items[self.player]["state_is_fresh"] = 0 + + return change \ No newline at end of file From 3d7f23b26df33fbb086e3e00e608a27b884629cb Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 7 Jun 2024 22:02:45 +0200 Subject: [PATCH 2/4] newline --- worlds/yachtdice/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worlds/yachtdice/__init__.py b/worlds/yachtdice/__init__.py index e5fedd57ba..43e8244a69 100644 --- a/worlds/yachtdice/__init__.py +++ b/worlds/yachtdice/__init__.py @@ -409,4 +409,4 @@ class YachtDiceWorld(World): if change and item.advancement: state.prog_items[self.player]["state_is_fresh"] = 0 - return change \ No newline at end of file + return change From a3c9fb7b55eb915f5e98dfe9f8e847f58fab2c20 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 7 Jun 2024 22:10:36 +0200 Subject: [PATCH 3/4] Improve typing --- worlds/yachtdice/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worlds/yachtdice/__init__.py b/worlds/yachtdice/__init__.py index 43e8244a69..cf541c9f59 100644 --- a/worlds/yachtdice/__init__.py +++ b/worlds/yachtdice/__init__.py @@ -1,7 +1,7 @@ import math import logging -from BaseClasses import Region, Entrance, Item, Tutorial +from BaseClasses import Region, Entrance, Item, Tutorial, CollectionState from .Items import YachtDiceItem, item_table, item_groups from .Locations import YachtDiceLocation, all_locations, ini_locations from .Options import YachtDiceOptions @@ -397,14 +397,14 @@ class YachtDiceWorld(World): item = YachtDiceItem(name, item_data.classification, item_data.code, self.player) return item - def collect(self, state, item: Item) -> bool: + def collect(self, state: CollectionState, item: Item) -> bool: change = super().collect(state, item) if change and item.advancement: state.prog_items[self.player]["state_is_fresh"] = 0 return change - def remove(self, state, item: Item) -> bool: + def remove(self, state: CollectionState, item: Item) -> bool: change = super().remove(state, item) if change and item.advancement: state.prog_items[self.player]["state_is_fresh"] = 0 From 676e876392330ed2079694bb23143b99d75d059f Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 7 Jun 2024 22:18:36 +0200 Subject: [PATCH 4/4] This is actually just slower lol --- worlds/yachtdice/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worlds/yachtdice/__init__.py b/worlds/yachtdice/__init__.py index cf541c9f59..9bcabd9dcf 100644 --- a/worlds/yachtdice/__init__.py +++ b/worlds/yachtdice/__init__.py @@ -399,14 +399,14 @@ class YachtDiceWorld(World): def collect(self, state: CollectionState, item: Item) -> bool: change = super().collect(state, item) - if change and item.advancement: + if change: state.prog_items[self.player]["state_is_fresh"] = 0 return change def remove(self, state: CollectionState, item: Item) -> bool: change = super().remove(state, item) - if change and item.advancement: + if change: state.prog_items[self.player]["state_is_fresh"] = 0 return change