def test_single_tag(): roller = ExplicitModRoller(ExplictlessItem("Searching Eye Jewel")) bow_idx = roller.affix_key_pool.index("AbyssAddedLightningDamageWithBowsJewel4") print(bin(roller.tags_current)) roller.add_affix(bow_idx) print(bin(roller.tags_current)) print(roller.cached_weight_draw.spawn_tags_to_spawn_weight[roller.tags_current]) wand_idx = roller.affix_key_pool.index("AbyssAddedFireDamageWithWandsJewel4") assert roller.cached_weight_draw.spawn_tags_to_spawn_weight[roller.tags_current][wand_idx] == 0, "wands and bows should block" print("REMOVED MODS:") base = roller.cached_weight_draw.weights_cummulative[roller.tags_current] last = 0 for idx, weight in enumerate(base): if last == weight: print(roller.affix_key_pool[idx]) last = weight diff = roller.cached_weight_draw.group_diff_prefix_cummulative[roller.tags_current][bow_idx] last = 0 for idx, weight in enumerate(diff): if last != weight: print(roller.affix_key_pool[idx]) last = weight diff = roller.cached_weight_draw.group_diff_suffix_cummulative[roller.tags_current][bow_idx] last = 0 for idx, weight in enumerate(diff): if last != weight: print(roller.affix_key_pool[idx]) last = weight
def test_single_generation_tag(): roller = ExplicitModRoller(ExplictlessItem("Driftwood Sceptre")) cast_mod = roller.affix_key_pool.index("ColdDamageOverTimeMultiplier1h5") attack_mod = roller.affix_key_pool.index("LocalAddedColdDamage10__") cast_before = roller.cached_weight_draw.spawn_tags_to_spawn_weight[ roller.tags_current][cast_mod] attack_before = roller.cached_weight_draw.spawn_tags_to_spawn_weight[ roller.tags_current][attack_mod] roller.add_affix(cast_mod) cast_after = roller.cached_weight_draw.spawn_tags_to_spawn_weight[ roller.tags_current][cast_mod] attack_after = roller.cached_weight_draw.spawn_tags_to_spawn_weight[ roller.tags_current][attack_mod] roller.clear_item() assert cast_before == cast_after, "caster shouldnt change" assert attack_before > attack_after, "attack should change" cast_before = roller.cached_weight_draw.spawn_tags_to_spawn_weight[ roller.tags_current][cast_mod] attack_before = roller.cached_weight_draw.spawn_tags_to_spawn_weight[ roller.tags_current][attack_mod] roller.add_affix(attack_mod) cast_after = roller.cached_weight_draw.spawn_tags_to_spawn_weight[ roller.tags_current][cast_mod] attack_after = roller.cached_weight_draw.spawn_tags_to_spawn_weight[ roller.tags_current][attack_mod] roller.clear_item() assert attack_before == attack_after, "attack shouldnt change" assert cast_before > cast_after, "cast should change"
def test_single_tag(): roller = ExplicitModRoller(ExplictlessItem("Searching Eye Jewel")) bow_idx = roller.affix_key_pool.index( "AbyssAddedLightningDamageWithBowsJewel4") default_tags = roller.tags_current roller.add_affix(bow_idx) assert roller.tags_current != default_tags, "should get different tags" print(roller.cached_weight_draw.spawn_tags_to_spawn_weight[ roller.tags_current]) wand_idx = roller.affix_key_pool.index( "AbyssAddedFireDamageWithWandsJewel4") assert (roller.cached_weight_draw.spawn_tags_to_spawn_weight[ roller.tags_current][wand_idx] == 0), "wands and bows should block" base = roller.cached_weight_draw.weights_cumulative[roller.tags_current] for removed_mod in removed_mods(base, roller, True): assert ("DamageWithWands" in removed_mod or "WhileDualWielding" in removed_mod or "HoldingAShield" in removed_mod), f"bad removed_mod {removed_mod}" diff = roller.cached_weight_draw.group_diff_prefix_cumulative[ roller.tags_current][bow_idx] for removed_mod in removed_mods(diff, roller): assert ("AbyssAddedLightningDamageWithBows" in removed_mod), f"bad removed_mod {removed_mod}" diff = roller.cached_weight_draw.group_diff_suffix_cumulative[ roller.tags_current][bow_idx] assert len(removed_mods(diff, roller)) == 0
def test_smoke_tags(trial_N = 10**6): roller = ExplicitModRoller(ExplictlessItem("Searching Eye Jewel")) for trial_idx in tqdm(range(trial_N)): roller.roll_item() keys = roller.affix_keys_current bow_in = True in [ "Bow" in key for key in keys] wand_in = True in [ "Wand" in key for key in keys] assert not bow_in or not wand_in, "cant have both bow and wand"
def affix_counter_simulation(item_roller: ExplicitModRoller, trial_N=10**6): mod_counter = Counter() for trial_idx in tqdm(range(trial_N)): item_roller.roll_item() for affix_key in item_roller.affix_keys_current: if affix_key not in mod_counter: mod_counter[affix_key] = 0 mod_counter[affix_key] += 1 return mod_counter
def get_odds_from_fossils(fossils, item, criteria, trial_N=10 ** 6): # Now we set up the roller with the dense fossil: roller = ExplicitModRoller( item, fossil_names=fossils # essence_names=["Deafening Essence of Loathing"] ) count = 0 for _ in range(trial_N): # roll the item roller.roll_item() if criteria(roller): # top_redeemer and top_delve: count += 1 return count / trial_N
def simulator_grab_label_counts(item_roller: ExplicitModRoller, trial_N = 10 ** 6): affix_combo_counter = {} for trial_idx in tqdm(range(trial_N)): item_roller.roll_item() labels = [] for affix_key in item_roller.affix_keys_current: labels.append(affix_key_to_label[affix_key]) labels.sort() labels = tuple(labels) if labels in affix_combo_counter: affix_combo_counter[labels] += 1 else: affix_combo_counter[labels] = 1 return affix_combo_counter
def test_smoke(trial_N = 10 ** 6): test_item_mod_dictionary = {} for mod_name in test_item_mod_name: test_item_mod_dictionary[mod_name] = mods[mod_name] relevant_start_tags, added_tags, affixes = generate_all_possible_affixes_and_tags(starting_tags=["default", "belt"], mod_pool=test_item_mod_dictionary) roller = ExplicitModRoller(ExplictlessItem("Leather Belt")) roller.setup_cached_weight_draw(affixes,relevant_start_tags,added_tags) print(roller.cached_weight_draw.spawn_tags_to_spawn_weight) print(roller.affix_key_pool) mod_counter = simulator_grab_label_counts(roller, trial_N = trial_N) type_counter = divide_counter(mod_counter, trial_N) exact_counter = exact_type_numbers() for key, value in type_counter.items(): exact_value = exact_counter[key] relative = (exact_value-value)/exact_value assert abs(relative) < .1, f"exact and simulated dont match, {exact_value, value}"
def get_alt_prices(mod_name, item, trial_n=10**7): generation_type = mods[mod_name]["generation_type"] roller = ExplicitModRoller(item) with timer("rust"): alt, aug, count = get_alt_aug_count_rust(roller, mod_name, generation_type, trial_n) with timer("python"): alt, aug, count = get_alt_aug_count(roller, mod_name, generation_type, trial_n) print(f"alt {alt} aug {aug}") return (alt / count) * currency_prices["Orb of Alteration"] + ( aug / count) * currency_prices["Orb of Augmentation"]
def get_alt_prices(mod_name, item, trial_N=10 ** 8): generation_type = mods[mod_name]["generation_type"] roller = ExplicitModRoller(item, max_pre=1, max_suff=1) count = 0 alt = 0 aug = 0 for _ in tqdm(range(trial_N)): roller.roll_item_magic() alt += 1 if mod_name in roller.affix_keys_current: count += 1 else: aug_prefix = generation_type == "prefix" and roller.prefix_N == 0 aug_suffix = generation_type == "suffix" and roller.suffix_N == 0 if aug_prefix or aug_suffix: roller.roll_one_affix() aug += 1 if mod_name in roller.affix_keys_current: count += 1 print(f"alt {alt} aug {aug}") return (alt / count) * currency_prices["Orb of Alteration"] + ( aug / count ) * currency_prices["Orb of Augmentation"]
def test_smoke(trial_N=10**6): test_item_mod_dictionary = { mod_name: mods[mod_name] for mod_name in test_item_mod_name + ["IncreasedLifeImplicitBelt1"] } with monkey_patch_mods_to_test(test_item_mod_dictionary): starting_tags = ["default", "belt"] roller = ExplicitModRoller( ExplictlessItem("Leather Belt", extra_tags=starting_tags)) print(roller.cached_weight_draw.spawn_tags_to_spawn_weight) print(roller.affix_key_pool) mod_counter = simulator_grab_label_counts(roller, trial_N=trial_N) type_counter = divide_counter(mod_counter, trial_N) exact_counter = exact_type_numbers() for key, value in type_counter.items(): exact_value = exact_counter[key] relative = (exact_value - value) / exact_value assert (abs(relative) < 0.1 ), f"exact and simulated dont match, {exact_value, value}"
from PoECraft.item_rollers import ExplictlessItem, ExplicitModRoller from PoECraft.utils.visualizations import statistics, discrete_cdf, plot_show import numpy from collections import Counter from tqdm import tqdm base_item = ExplictlessItem("Stygian Vise", ilvl=25) item_roller = ExplicitModRoller(base_item) def affix_counter_simulation(item_roller: ExplicitModRoller, trial_N=10**6): mod_counter = Counter() for trial_idx in tqdm(range(trial_N)): item_roller.roll_item() for affix_key in item_roller.affix_keys_current: if affix_key not in mod_counter: mod_counter[affix_key] = 0 mod_counter[affix_key] += 1 return mod_counter def divide_counter(counter: Counter, dividend): divided_counter = {} for key, value in counter.items(): divided_counter[key] = value / dividend return divided_counter def counter_to_percentages(counter: Counter):
from PoECraft.item_rollers import ExplictlessItem, ExplicitModRoller from PoECraft.utils.visualizations import statistics, discrete_cdf, plot_show import numpy #Here we generate a base item which is a ilvl 100 vaal regalia with a single synthesis implicit, and 30 quality vaal_regalia_item = ExplictlessItem( "Vaal Regalia", quality=30, implicits=["SynthesisImplicitFlatEnergyShield5_"]) #We view the implicit stats granted from this synthesis implicit print(vaal_regalia_item.implicit_stats) #{'local_energy_shield': [[25, 25]]} #Now we set up the roller with the dense fossil: vaal_regalia_dense_roller = ExplicitModRoller(vaal_regalia_item, fossil_names=["Dense Fossil"]) #before we do a batch craft, we'll do one small craft: #This is the equivalent of using our fossil: vaal_regalia_dense_roller.roll_item() print( f"First roll's affix names: {vaal_regalia_dense_roller.affix_keys_current}" ) print( f"First roll's total stats: {vaal_regalia_dense_roller.get_total_stats()}") #We pick the number of times to use our dense fossil trial_N = 10**4 #define a small helper function to extract the average local energy shield:
from PoECraft.item_rollers import ExplictlessItem, ExplicitModRoller from tqdm import tqdm from poe_craft.rust_scripts import test_roll_batch from PoECraft.utils.performance import timer # Here we generate a base item which is a ilvl 100 vaal regalia with a single synthesis implicit, and 30 quality vaal_regalia_item = ExplictlessItem("Vaal Regalia") # Now we set up the roller with the dense fossil: vaal_regalia_roller = ExplicitModRoller(vaal_regalia_item) def roll(trial_n): for _ in tqdm(range(trial_n)): vaal_regalia_roller.roll_item() trial_n = 10**7 with timer(): roll(trial_n) # we get a 2.6x speed up from writing our simple script in rust with timer(): test_roll_batch(vaal_regalia_roller, trial_n)
from PoECraft.item_rollers import ExplictlessItem, ExplicitModRoller cluster_jewel_item = ExplictlessItem("Medium Cluster Jewel", quality=30, extra_tags=["affliction_aura"], max_affix=2) cluster_jewel_roller = ExplicitModRoller(cluster_jewel_item) # before we do a batch craft, we'll do one small craft: # This is the equivalent of using our fossil: cluster_jewel_roller.roll_item() print(f"First roll's affix names: {cluster_jewel_roller.affix_keys_current}") # We pick the number of times to use our dense fossil trial_N = 10**1 print("starting crafting simulator") # Main loop to roll the item: average_local_energy_shield_results = [] for i in range(trial_N): # roll the item cluster_jewel_roller.roll_item() print( f"First roll's affix names: {cluster_jewel_roller.affix_keys_current}")