• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Gacha Probability Calculator

Gnotiak Jul 16th, 2019 120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. class Gacha:
2.     def __init__(self, rate_r, rate_ssr, rate_target, guarantee, pity):
3.         self.rate_r = rate_r
4.         self.rate_ssr = rate_ssr
5.         self.rate_target = rate_target
6.         self.guarantee = guarantee
7.         self.pity = pity
8.         self.limit = -1
9.
10.     def __init__(self):
11.         self.hi3rd_expansion()
12.
13.     def set_limit(self,limit):
14.         self.limit = limit
15.
16.     def prob(self,table,state,pulls):
17.
18.         if state.are_all_targets_acquired():
19.             return [1,0]
20.
21.         if pulls == self.limit:
22.             return [0,0]
23.
24.         if state.get_tuple() in table:
25.             return table[state.get_tuple()]
26.
27.         if self.pity == state.pity_counter+1:
28.             pity_state = state.copy()
29.             pity_state.got_target()
30.             val = self.prob(table,pity_state,pulls+1)
31.             table[state.get_tuple()] = val
32.             return [val[0],val[1]+1]
33.
34.         if self.guarantee == state.guarantee_counter+1:
35.             val = [0,0]
36.
37.             brag_state = state.copy()
38.             brag_state.got_target()
39.             temp_val = self.prob(table,brag_state,pulls+1)
40.             brag_mult = self.rate_target/self.rate_ssr
41.             val[0] += temp_val[0]*brag_mult
42.             val[1] += (temp_val[1]+1)*brag_mult
43.
44.             salt_state = state.copy()
45.             salt_state.got_salt()
46.             temp_val = self.prob(table,salt_state,pulls+1)
47.             salt_mult = 1-brag_mult
48.             val[0] += temp_val[0]*salt_mult
49.             val[1] += (temp_val[1]+1)*salt_mult
50.
51.             table[state.get_tuple()] = val
52.             return val
53.
54.         val = [0,0]
55.
56.         brag_state = state.copy()
57.         brag_state.got_target()
58.         temp_val = self.prob(table,brag_state,pulls+1)
59.         brag_mult = self.rate_target
60.         val[0] += temp_val[0]*brag_mult
61.         val[1] += (temp_val[1]+1)*brag_mult
62.
63.         salt_state = state.copy()
64.         salt_state.got_salt()
65.         temp_val = self.prob(table,salt_state,pulls+1)
66.         salt_mult = self.rate_ssr - self.rate_target
67.         val[0] += temp_val[0]*salt_mult
68.         val[1] += (temp_val[1]+1)*salt_mult
69.
70.         uber_salt_state = state.copy()
71.         uber_salt_state.got_uber_salt()
72.         temp_val = self.prob(table,uber_salt_state,pulls+1)
73.         uber_salt_mult = self.rate_r
74.         val[0] += temp_val[0]*uber_salt_mult
75.         val[1] += (temp_val[1]+1)*uber_salt_mult
76.
77.         table[state.get_tuple()] = val
78.         return val
79.
80.     def hi3rd_expansion(self):
81.         self.rate_r = 0.85
82.         self.rate_ssr = 0.15
83.         self.rate_target = 0.015
84.         self.guarantee = 10
85.         self.pity = 100
86.         self.limit = -1
87.
88.
89. class State:
90.     def __init__(self, guarantee_counter, pity_counter):
91.         self.guarantee_counter = guarantee_counter
92.         self.pity_counter = pity_counter
93.         self.targets_counter = 0
94.         self.targets_goal = 1
95.
96.     def are_all_targets_acquired(self):
97.         return self.targets_counter == self.targets_goal
98.
99.     def reset_counter(self):
100.         self.guarantee_counter = 0
101.         self.pity_counter = 0
102.
103.     def copy(self):
104.         copied_state = State(self.guarantee_counter, self.pity_counter)
105.         copied_state.targets_counter = self.targets_counter
106.         copied_state.targets_goal = self.targets_goal
107.         return copied_state
108.
109.     def got_target(self):
110.         self.targets_counter += 1
111.         self.reset_counter()
112.
113.     def got_salt(self):
114.         self.guarantee_counter = 0
115.         self.pity_counter += 1
116.
117.     def got_uber_salt(self):
118.         self.guarantee_counter += 1
119.         self.pity_counter += 1
120.
121.     def get_tuple(self):
122.         return (self.guarantee_counter, self.pity_counter, self.targets_counter)
123.
124. def prob_table():
125.     gacha = Gacha()
126.     init_state = State(0,0)
127.     table = {}
128.     for i in range(20):
129.         for j in range(5):
130.             table.clear()
131.             gacha.set_limit(i*5+j+1)
132.             val = gacha.prob(table,init_state,0)[0]
133.             print("%3i : %5.4f " % (i*5+j+1,val), end=" ")
134.         print(" ")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top