From a1acff3a8bd087ead784c9bee2cf708fad7e53aa Mon Sep 17 00:00:00 2001 From: spinerak Date: Mon, 10 Jun 2024 18:33:31 +0200 Subject: [PATCH] Comments to docstrings --- worlds/yachtdice/Locations.py | 12 +++++++--- worlds/yachtdice/Rules.py | 44 +++++++++++++++++++++++------------ worlds/yachtdice/__init__.py | 12 +++++++--- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/worlds/yachtdice/Locations.py b/worlds/yachtdice/Locations.py index ce24f0d39d..5265a4323f 100644 --- a/worlds/yachtdice/Locations.py +++ b/worlds/yachtdice/Locations.py @@ -21,14 +21,20 @@ all_locations = {} starting_index = 16871244500 # 500 more than the starting index for items -# Function that is called when this file is loaded, which loads in ALL possible locations, score 1 to 1000 + def all_locations_fun(max_score): + """ + Function that is called when this file is loaded, which loads in ALL possible locations, score 1 to 1000 + """ return {f"{i} score": LocData(starting_index + i, "Board", i) for i in range(max_score + 1)} -# function that loads in all locations necessary for the game, so based on options. -# will make sure that goal_score and max_score are included locations + def ini_locations(goal_score, max_score, num_locs, dif): + """ + function that loads in all locations necessary for the game, so based on options. + will make sure that goal_score and max_score are included locations + """ scaling = 2 # parameter that determines how many low-score location there are. # need more low-score locations or lower difficulties: if dif == 1: diff --git a/worlds/yachtdice/Rules.py b/worlds/yachtdice/Rules.py index a39602b95e..d6355ccf0c 100644 --- a/worlds/yachtdice/Rules.py +++ b/worlds/yachtdice/Rules.py @@ -8,6 +8,15 @@ from worlds.generic.Rules import set_rule from .YachtWeights import yacht_weights + +# This module adds logic to the apworld. +# In short, we ran a simulation for every possible combination of dice and rolls you can have, per category. +# This simulation has a good strategy for locking dice. +# This gives rise to an approximate discrete distribution per category. +# We calculate the distribution of the total score. +# We then pick a correct percentile to reflect the correct score that should be in logic. +# The score is logic is *much* lower than the actual maximum reachable score. + # List of categories, and the name of the logic class associated with it category_mappings = { "Category Ones": "Ones", @@ -44,14 +53,6 @@ category_mappings = { "Category 4&5 Full House": "FourAndFiveFullHouse", } -# This class adds logic to the apworld. -# In short, we ran a simulation for every possible combination of dice and rolls you can have, per category. -# This simulation has a good strategy for locking dice. -# This gives rise to an approximate discrete distribution per category. -# We calculate the distribution of the total score. -# We then pick a correct percentile to reflect the correct score that should be in logic. -# The score is logic is *much* lower than the actual maximum reachable score. - class Category: def __init__(self, name, quantity=1): @@ -77,9 +78,11 @@ class ListState: def extract_progression(state, player, options): - # method to obtain a list of what items the player has. - # this includes categories, dice, rolls and score multiplier etc. - # First, we convert the state if it's a list, so we can use state.count(item, player) + """ + method to obtain a list of what items the player has. + this includes categories, dice, rolls and score multiplier etc. + First, we convert the state if it's a list, so we can use state.count(item, player) + """ if isinstance(state, list): state = ListState(state=state) @@ -117,8 +120,10 @@ def extract_progression(state, player, options): yachtdice_cache = {} -# Function that returns the feasible score in logic based on items obtained. def dice_simulation_strings(categories, num_dice, num_rolls, fixed_mult, step_mult, diff): + """ + Function that returns the feasible score in logic based on items obtained. + """ tup = tuple( [ tuple(sorted([c.name + str(c.quantity) for c in categories])), @@ -213,8 +218,11 @@ def dice_simulation_strings(categories, num_dice, num_rolls, fixed_mult, step_mu return yachtdice_cache[tup] -# Returns the feasible score that one can reach with the current state, options and difficulty. + def dice_simulation(state, player, 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) @@ -238,8 +246,12 @@ def dice_simulation(state, player, options): 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): + """ + Sets rules on entrances and advancements that are always applied + """ + for location in world.get_locations(player): set_rule( location, @@ -248,6 +260,8 @@ def set_yacht_rules(world: MultiWorld, player: int, options): ) -# Sets rules on completion condition def set_yacht_completion_rules(world: MultiWorld, player: int): + """ + Sets rules on completion condition + """ world.completion_condition[player] = lambda state: state.has("Victory", player) diff --git a/worlds/yachtdice/__init__.py b/worlds/yachtdice/__init__.py index 8dd0c7f3ba..fef7b31e81 100644 --- a/worlds/yachtdice/__init__.py +++ b/worlds/yachtdice/__init__.py @@ -57,8 +57,10 @@ class YachtDiceWorld(World): "race": self.multiworld.is_race, } - # In generate early, we fill the item-pool, then determine the number of locations, and add filler items. def generate_early(self): + """ + In generate early, we fill the item-pool, then determine the number of locations, and add filler items. + """ self.itempool = [] self.precollected = [] @@ -397,12 +399,16 @@ class YachtDiceWorld(World): self.multiworld.regions += [menu, board] def set_rules(self): - # set rules per location, and add the rule for beating the game + """ + set rules per location, and add the rule for beating the game + """ set_yacht_rules(self.multiworld, self.player, self.options) set_yacht_completion_rules(self.multiworld, self.player) def fill_slot_data(self): - # make slot data, which consists of yachtdice_data, options, and some other variables. + """ + make slot data, which consists of yachtdice_data, options, and some other variables. + """ yacht_dice_data = self._get_yachtdice_data() yacht_dice_options = self.options.as_dict( "game_difficulty",