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 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 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}"
fossil_to_percent[frozenset(fossil_subset)] = ( (1 / odds) * (price + resonator_socket_to_price[socket_count]) if odds != 0 else float("inf") ) def sort_dict_by_value(x): return { k: v for k, v in sorted(x.items(), key=lambda item: item[1], reverse=True) } return sort_dict_by_value(fossil_to_percent) if __name__ == "__main__": bow = ExplictlessItem("Recurve Bow", quality=30, ilvl=84, influences=[]) def annul_item(item_roller): # Given an item with n mods of which we want to annul until we have k specific we have: # 1 / (n choose k) chance of getting it in n-k orbs # 1 - 1 / (n choose k) chance of not getting it with expected orbs # 1 + 2 * (n-k)_1 / n_1 + 3 * (n-k)_2 / (n)_2 + ... + (k-1) (n-k)_{k-1} / (n)_{k-1} def kyle_criteria(item_roller): c1 = "DelveWeaponSocketedSpellsDamageFinal2h1" in item_roller.affix_keys_current c2 = "DelveWeaponVaalSoulCost2h1" in item_roller.affix_keys_current return c1 and c2 odds = get_best_fossil_combos( ["Aetheric Fossil", "Bloodstained Fossil"], bow, kyle_criteria
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:
# "Hubris Circlet", quality=30, ilvl=86, influences=[Influence.REDEEMER] # ) # def double_mana_criteria(item_roller): # top_influence = ( # "ReducedManaReservationInfluence2" in item_roller.affix_keys_current # ) # top_delve = "DelveHelmetReducedManaReserved1" in item_roller.affix_keys_current # return top_influence and top_delve # print( # get_best_fossil_combos(["Lucent Fossil", "Bound Fossil"], hubris_circlet_item, double_mana_criteria) # ) astral_item = ExplictlessItem("Astral Plate", quality=30, ilvl=86, influences=[Influence.CRUSADER]) vaal_regalia = ExplictlessItem("Vaal Regalia", quality=30, ilvl=86, influences=[Influence.HUNTER]) bow = ExplictlessItem("Recurve Bow", quality=30, ilvl=84, influences=[]) def explode_criteria(item_roller): explode = "HolyPhysicalExplosionInfluence1" in item_roller.affix_keys_current top_delve = "DelveHelmetReducedManaReserved1" in item_roller.affix_keys_current return explode def double_crit_criteria(item_roller): top_attack = ("AdditionalCritWithAttacksInfluence2_"
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)
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"] if __name__ == "__main__": mod_name = "HolyPhysicalExplosionInfluence1" astral_item = ExplictlessItem( "Astral Plate", quality=30, ilvl=86, influences=[Influence.CRUSADER] ) print(get_alt_prices(mod_name, astral_item)) # alt 100000000 aug 28373602 # 270.5354074635609
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}")
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 return alt, aug, count if __name__ == "__main__": mod_name = "HolyPhysicalExplosionInfluence1" magic_astral_item = ExplictlessItem( "Astral Plate", quality=30, ilvl=86, influences=[Influence.CRUSADER], max_pre=1, max_suf=1, ) print(get_alt_prices(mod_name, magic_astral_item)) # alt 100000000 aug 28373602 # 270.5354074635609