Skip to content

Commit

Permalink
Preparation for 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
spinerak committed Jun 1, 2024
1 parent b51dcfb commit 67fb4fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
7 changes: 4 additions & 3 deletions worlds/yachtdice/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ def percentile_distribution(dist, percentile):
return prev_val if prev_val is not None else sorted_values[0]


percReturn = [0, 0.30, 0.45, 0.53, 0.7, 0.9][diff]
diffDivide = [0, 9, 8, 4, 2, 1][diff]
percReturn = [[0], [0.1, 0.5], [0.3, 0.7], [0.5, 0.85], [0.85, 0.95]][diff]
diffDivide = [0, 9, 7, 3, 1][diff]


#calculate total distribution
total_dist = {0: 1}
Expand All @@ -197,7 +198,7 @@ def percentile_distribution(dist, percentile):
total_dist = add_distributions(total_dist, dist)

#save result into the cache, then return it
yachtdice_cache[tup] = math.floor(percentile_distribution(total_dist, percReturn))
yachtdice_cache[tup] = math.floor(sum([percentile_distribution(total_dist, perc) for perc in percReturn]) / len(percReturn))
return yachtdice_cache[tup]

# Returns the feasible score that one can reach with the current state, options and difficulty.
Expand Down
26 changes: 17 additions & 9 deletions worlds/yachtdice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class YachtDiceWorld(World):

item_name_groups = ITEM_GROUPS

ap_world_version = "1.2"
ap_world_version = "2.0"

def _get_yachtdice_data(self):
return {
Expand All @@ -49,7 +49,7 @@ def _get_yachtdice_data(self):
"race": self.multiworld.is_race,
}

def generate_early(self):
def generate_early(self):
self.itempool = []
self.precollected = []

Expand Down Expand Up @@ -152,21 +152,29 @@ def generate_early(self):
self.options.weight_of_points.value
]

#if the player wants extra rolls or dice, fill the pool with fragments until close to an extra roll/dice
if weights[0] > 0 and amDiceF > 1:
self.itempool += ["Dice Fragment"] * (amDiceF - 1)
if weights[1] > 0 and amRollsF > 1:
self.itempool += ["Roll Fragment"] * (amRollsF - 1)

#calibrate the weights, since the impact of each of the items is different
weights[0] = weights[0] / 5 * amDiceF
weights[1] = weights[1] / 5 * amRollsF

extraPointsAdded = 0

while diceSimulation(self.itempool + self.precollected, "state_is_a_list", self.options) < 1000:
allitems = self.itempool + self.precollected
dice_fragments_in_pool = allitems.count("Dice") * amDiceF + allitems.count("Dice Fragment")
if dice_fragments_in_pool + 1 >= 9 * amDiceF:
weights[0] = 0 #can't have 9 dice
roll_fragments_in_pool = allitems.count("Roll") * amDiceF + allitems.count("Roll Fragment")
roll_fragments_in_pool = allitems.count("Roll") * amRollsF + allitems.count("Roll Fragment")
if roll_fragments_in_pool + 1 >= 6 * amRollsF:
weights[1] = 0 # can't have 6 rolls

if extraPointsAdded > 300:
weights[5] = 0

#if all weights are zero, allow to add fixed score multiplier, double category, points.
if sum(weights) == 0:
Expand All @@ -181,21 +189,23 @@ def generate_early(self):
self.itempool += ["Dice"]
else:
self.itempool += ["Dice Fragment"]
weights[0] /= (1+amDiceF)
weights[0] /= (1 + amDiceF)
elif which_item_to_add == 1:
if amRollsF == 1:
self.itempool += ["Roll"]
else:
self.itempool += ["Roll Fragment"]
weights[1] /= (1+amRollsF)
weights[1] /= (1 + amRollsF)
elif which_item_to_add == 2:
self.itempool += ["Fixed Score Multiplier"]
weights[2] /= 1.1
weights[2] /= 1.05
elif which_item_to_add == 3:
self.itempool += ["Step Score Multiplier"]
weights[3] /= 1.1
elif which_item_to_add == 4:
self.itempool += self.multiworld.random.choices(possible_categories)
#increase chances of "free-score categories"
cat_weights = [2, 2, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1]
self.itempool += self.multiworld.random.choices(possible_categories, weights = cat_weights)
weights[4] /= 1.1
elif which_item_to_add == 5:
score_dist = self.options.points_size.value
Expand Down Expand Up @@ -223,8 +233,6 @@ def generate_early(self):
weights[5] /= 2
else:
raise Exception("Unknown point value (Yacht Dice)")
if extraPointsAdded > 300:
weights[5] = 0
else:
raise Exception("Invalid index when adding new items in Yacht Dice")

Expand Down

0 comments on commit 67fb4fb

Please sign in to comment.