Advertisement
Guest User

tali optimiser

a guest
Oct 25th, 2019
5,759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.10 KB | None | 0 0
  1. # notnotmelon 10/17/19
  2. # talisman calcuator aka maximise the damage function with 11 inpus
  3.  
  4. from math import *
  5.  
  6. # The heruistic algoithm is a wip, don't use for now
  7. heruistic = False
  8. heruistic_weighting = [2, 10, 3, 2, 10]
  9.  
  10. # This class is a bit confusing ngl
  11. # It defines one route of one rarity
  12. # For example, if you have 5 rare talisman than one possiblity for this class's data would be (1, 2, 3, 0, 0)
  13. # It's confusing since I use a seperate construct to define the route for all rarities
  14. # That seperate construct is actually just a list of these routes
  15. class route:
  16.     def __init__(self, counts, rarity):
  17.         self.counts = counts
  18.         self.rarity = rarity
  19.         self.rarity_str = ["common", "uncommon", "rare", "epic"][rarity]
  20.         self.stats = [sum(talismans_raw[y][rarity][x] * counts[y] if talismans_raw[y][rarity] else 0 for y in range(5)) for x in range(3)]
  21.         self.strength, self.crit_chance, self.crit_dmg = self.stats
  22.     def __repr__(self):
  23.         result = ""
  24.         for name, c in zip(talismans.keys(), self.counts):
  25.             if c > 0:
  26.                 result += "{} {} {}{}, ".format(c, name, self.rarity_str, "" if c == 1 else "s")
  27.         return result[:-2]
  28.     def strength(self):
  29.         return self.stats[0]
  30.     def crit_damage(self):
  31.         return self.stats[2]
  32.     def heruistic_weight(self):
  33.         result = 0
  34.         for x, y in zip(self.stats, heruistic_weighting):
  35.             result += x * y
  36.         return result
  37.  
  38. def bump(lst, idx, x):
  39.     lst = lst.copy()
  40.     lst[idx] += x
  41.     return lst
  42.  
  43. def routes(count, size, rarity):
  44.     main = []
  45.  
  46.     def helper(count, idx, current):
  47.         if count == 0:
  48.             main.append(current)
  49.         elif idx == size - 1:
  50.             main.append(bump(current, idx, count))
  51.         else:
  52.             if talismans_raw[idx][rarity]:
  53.                 helper(count - 1, idx, bump(current, idx, 1))
  54.             helper(count, idx + 1, current)
  55.  
  56.     helper(count, 0, [0] * size)
  57.     return [route(x, rarity) for x in main]
  58.  
  59. def heruistic_filter(routes):
  60.     sum = 0.0
  61.     for route in routes:
  62.         sum += route.heruistic_weight()
  63.     average = sum / len(routes)
  64.     return filter(lambda stat: route.heruistic_weight() > average, routes)
  65.  
  66.  
  67. # Format is (common X, unc X, rare X, epic X), with X substutied with (str, chance, crit dmg)
  68. # Areas with "None" have direct upgrades in other reforges
  69.  
  70. talismans = {
  71.     'forceful': ((2, 0, 0), (4, 0, 0), (7, 0, 0), (10, 0, 0)),
  72.     'itchy': ((1, 0, 3), (2, 0, 5), (2, 0, 8), (3, 0, 12)),
  73.     'unpleasnt': ((0, 1, 1), None, (0, 3, 2), (0, 6, 3)),
  74.     'strong': (None, None, (4, 0, 4), (7, 0, 7)),
  75.     'godly': ((1, 1, 1), (2, 2, 2), (4, 2, 3), (7, 3, 6)),
  76.     }
  77.  
  78. talismans_raw = list(talismans.values())
  79.  
  80. weapon_dmg = int(input("Put all your talismans away, make sure you don't have any potion effects, and use /sbmenu while holding your sword for accurate stats.\nWhat is your weapon's raw damage?"))
  81. (strength, chance, crit_dmg) = [int(input('What is your ' + stat + '?')) for stat in ['strength', 'crit chance', 'crit damage']]
  82. counts = [int(input('How many ' + rarity + ' talisman do you have?')) for rarity in ['common', 'uncommon', 'rare', 'epic']]
  83. combat = int(input('What is your combat level?'))
  84. crit_goal = int(input('Do you want 80 or 100 crit chance?')) - chance
  85. ench_modifer = int(input('''What is your mob specfic enchant modifer?
  86. Note: You can find this by adding your sword's sharpness level * 5 with the amount of extra damage from other enchantments.
  87. For example, if you are focusing on damaging endermen and you have sharpness V but also have ender slayer V1 then this value would be (V * 5) + (VI * 12) = 25 + 72 = 97''')) + combat * 4 + 25
  88. ench_modifer += (100 if input('Are you trying to oneshot lots of enemies or are you fighting a boss? (For first strike and execute) valid inputs are: ONESHOT or BOSS').lower() == 'oneshot' else 50)
  89.  
  90. def raw_damage(bouns_str):
  91.     return (5 + weapon_dmg + floor(strength + bouns_str) / 5) * (1 + (bouns_str + strength) / 100.0)
  92.  
  93. def ench_damage(bouns_str):
  94.     return raw_damage(bouns_str) * (1 + ench_modifer / 100.0)
  95.  
  96.  
  97. def damage(bouns_str, bonus_crit_dmg):
  98.     return ench_damage(bouns_str) * (1 + (bonus_crit_dmg + crit_dmg) / 100.0)
  99.  
  100. def final_damage(routes):
  101.     return damage(routes[0].strength + routes[1].strength + routes[2].strength + routes[3].strength,
  102.                   routes[0].crit_dmg + routes[1].crit_dmg + routes[2].crit_dmg + routes[3].crit_dmg)
  103.  
  104. if heruistic:
  105.     route_set = [heruistic_filter(routes(counts[i], len(talismans), i)) for i in range(4)]
  106. else:
  107.     route_set = [routes(counts[i], len(talismans), i) for i in range(4)]
  108.  
  109. #all_routes_to_max_crit = [x for x in product(*route_set) if crit_goal == x[0].crit_chance + x[1].crit_chance + x[2].crit_chance + x[3].crit_chance]
  110. all_routes_to_max_crit = []
  111. progress = len(route_set[0])
  112. # This is the most time consuming part of the algorithim, it sifts through millions of possible routes and pulls out the few that manage to reach the crit goal
  113. for i, r1 in enumerate(route_set[0]):
  114.     print(i * 100 // progress, "%")
  115.     cc1 = r1.crit_chance
  116.     for r2 in route_set[1]:
  117.         cc2 = r2.crit_chance + cc1
  118.         for r3 in route_set[2]:
  119.             cc3 = r3.crit_chance + cc2
  120.             for r4 in route_set[3]:
  121.                 if cc3 + r4.crit_chance == crit_goal:
  122.                     all_routes_to_max_crit.append([r1, r2, r3, r4])
  123.                    
  124. if len(all_routes_to_max_crit) == 0:
  125.     print("There is no possible combination that reaches the desired crit chance, try to get more talismen or level up your combat skill")
  126. else:
  127.     max1 = [0, None]
  128.     max2 = [0, None]
  129.     max3 = [0, None]
  130.     for routes in all_routes_to_max_crit:
  131.         d = final_damage(routes)
  132.         if max1[0] < d:
  133.             max3 = max2
  134.             max2 = max1
  135.             max1 = [d, routes]
  136.         elif max2[0] < d:
  137.             max3 = max2
  138.             max2 = [d, routes]
  139.         elif max3[0] < d:
  140.             max3 = [d, routes]
  141.     print("The 3 best sets of talisman reforges are:")
  142.     print(*max1)
  143.     print(*max2)
  144.     print(*max3)
  145.  
  146. print("\nUsing the current meta (itchy on rares, epics, and commons) (godly on uncommons until 80%cc) would give you:")
  147. cc_needed = crit_goal
  148. # You could either use all of your crit goal or all of your unc talismans
  149. unc_needed = counts[1] if counts[1] * 2 < crit_goal else counts[1] - ceil(crit_goal / 2)
  150. com_needed = min(counts[0], crit_goal - unc_needed * 2)
  151. meta_routes = [route((0, counts[0] - com_needed, 0, 0, com_needed), 0),
  152.                route((0, counts[1] - unc_needed, 0, 0, unc_needed), 1),
  153.                route((0, counts[2], 0, 0, 0), 2),
  154.                route((0, counts[3], 0, 0, 0), 3)]
  155. print(final_damage(meta_routes), meta_routes)
  156. cc_boost = com_needed + unc_needed * 2
  157. if cc_boost != crit_goal:
  158.     print("This setup would also only give ", cc_boost + chance, "% crit chance", sep = "")
  159.  
  160. print("\nYou should be doing", damage(0, 0), "without any talismen")
  161.  
  162. print("\nKeep in mind that zealous and godly are the exact same for common and uncommon talismen")
  163. # Yeah the current meta is trash lol
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement