JohnSolaris

Genshin Impact average copies of a specific 4* character after N banner pulls

Apr 18th, 2021 (edited)
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. import matplotlib as mpl
  2. mpl.use('Agg')
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5.  
  6. N = 30
  7. memo = np.zeros((N, 10, 2))
  8. done = np.zeros((N, 10, 2))
  9.  
  10. class Node:
  11.  
  12.   win = 0.051
  13.   pityCount = 0
  14.   headGuarantee = False
  15.   winHeadChild = None
  16.   winTailChild = None
  17.   loseChild = None
  18.  
  19.   def avgPulls(self, n):
  20.     if n == 0:
  21.       return 0
  22.    
  23.     if done[n - 1, self.pityCount, int(self.headGuarantee)] == 1:
  24.       return memo[n - 1, self.pityCount, int(self.headGuarantee)]
  25.    
  26.     winHeadAvg = 0
  27.     winTailAvg = 0
  28.     loseAvg = 0
  29.  
  30.     self.winHeadChild = Node()
  31.     if self.pityCount == 9:
  32.       self.win = 1
  33.  
  34.     # Win branch
  35.     if self.headGuarantee:
  36.       winHeadAvg = 1/3 + self.winHeadChild.avgPulls(n - 1)
  37.     else:
  38.       self.winTailChild = Node()
  39.       self.winTailChild.headGuarantee = True
  40.       winHeadAvg = 0.5*(1/3 + self.winHeadChild.avgPulls(n - 1))
  41.       winTailAvg = 0.5*self.winTailChild.avgPulls(n - 1)
  42.       del self.winTailChild
  43.     del self.winHeadChild
  44.  
  45.     # Lose branch
  46.     if self.win != 1:
  47.       self.loseChild = Node()
  48.       self.loseChild.pityCount = self.pityCount + 1
  49.       self.loseChild.headGuarantee = self.headGuarantee
  50.       loseAvg = self.loseChild.avgPulls(n - 1)
  51.       del self.loseChild
  52.    
  53.     ret = self.win*(winHeadAvg + winTailAvg) + (1 - self.win)*loseAvg
  54.     memo[n - 1, self.pityCount, int(self.headGuarantee)] = ret
  55.     done[n - 1, self.pityCount, int(self.headGuarantee)] = 1
  56.     return ret
  57.  
  58. print(Node().avgPulls(N))
  59. x = np.arange(1, N + 1)
  60. y = memo[:, 0, 0]
  61. plt.plot(x, y, ".")
  62. plt.savefig('graph.png')
Add Comment
Please, Sign In to add comment