Merge pull request #3 from NewSoupVi/pr/3482

Improve performance of Yacht Dice
This commit is contained in:
Spineraks
2024-06-07 22:25:56 +02:00
committed by GitHub
2 changed files with 35 additions and 9 deletions

View File

@@ -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

View File

@@ -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
@@ -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
return item
def collect(self, state: CollectionState, item: Item) -> bool:
change = super().collect(state, item)
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:
state.prog_items[self.player]["state_is_fresh"] = 0
return change