MooingCat

2021 Winter Event Simulation v2

Dec 2nd, 2021
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.09 KB | None | 0 0
  1. import random
  2. import math
  3. import numpy as np
  4. from matplotlib import pyplot as plt
  5.  
  6. def getRandomList():
  7.     # 4 - shuffle, 5 - key, 15 - daily, 20 - double
  8.     l = [3,14,4,5,15,20,0,0,0,0,0,0,0,0,0,0,0,0]
  9.     random.shuffle(l)
  10.     return l
  11.  
  12. def pickPresent(l,l2,i2,dsFound,s,d,ds,k):
  13.     i = 0
  14.     t = False
  15.     if(len(l2) > 0):
  16.         if sum(l2) > 0:
  17.             if (dsFound and not keys) and 4 in l2:
  18.                 i = l2.index(4)
  19.                 t = True
  20.             elif 4 in l2:
  21.                 if sum(l2) == 4:
  22.                     i = random.choice(range(len(l)))
  23.                 else:
  24.                     i = l2.index(sum(l2)-4)
  25.                     t = True
  26.             else:
  27.                 i = l2.index(max(l2))
  28.                 t = True
  29.         else:
  30.             i = random.choice(range(len(l)))
  31.     else:
  32.         i = random.choice(range(len(l)))
  33.  
  34.     if t:
  35.         res = l2[i]
  36.         del l2[i]
  37.         del i2[i]
  38.     else:    
  39.         res = l[i]
  40.         del l[i]
  41.  
  42.     if res == 0:
  43.         # nothing
  44.         #print(0)
  45.         d = 1
  46.     elif res == 3:
  47.         i2 = random.sample(range(len(l)),min(2,len(l)))
  48.         l2 = [l[i2[x]] for x in range(len(i2))]
  49.         del l[max(i2)]
  50.         if len(i2) > 1:
  51.             del l[min(i2)]
  52.         s += 3*d
  53.         #print(3*d,"stars + show 2:",l2)
  54.     elif res == 4:
  55.         l2 = []
  56.         i2 = []
  57.         l = getRandomList()
  58.         dsFound = False
  59.         s += 10*d
  60.         #print(10*d,"stars + shuffle:",l)
  61.         return l,l2,i2,dsFound,s,d,ds,k
  62.     elif res == 5:
  63.         k += 1
  64.         if d == 2:
  65.             k += 0.2
  66.             s += 10
  67.         if keys:
  68.             l2 = []
  69.             i2 = []
  70.             l = getRandomList()
  71.             dsFound = False
  72.         else:
  73.             s += 10
  74.         #print(d,"key(s) +",d*10,"stars")
  75.     elif res == 14:
  76.         s += 14*d
  77.         #print(d*14,"stars")
  78.     elif res == 15:
  79.         ds += 1*d
  80.         dsFound = True
  81.         #print(d,"Daily Special(s)")
  82.     elif res == 20:
  83.         d = 2
  84.         #print("Double")
  85.  
  86.     if res == 20:
  87.         d = 2
  88.     else:
  89.         d = 1
  90.  
  91.    
  92.    
  93.     return l,l2,i2,dsFound,s,d,ds,k
  94.  
  95. keys = False
  96. # Stars
  97. results = []
  98. rb = []
  99. for x in range(100000):
  100.     if x % 10000 == 0:
  101.         print(x)
  102.     starting = 1160+1200
  103.     s = starting
  104.     ds = 0
  105.     k = 0
  106.     l = getRandomList()
  107.     l2 = []
  108.     i2 = []
  109.     dsFound = False
  110.     d = 1
  111.     c = 0
  112.     while s >= 10:
  113.         s -= 10
  114.         c += 1
  115.         l,l2,i2,dsFound,s,d,ds,k = pickPresent(l,l2,i2,dsFound,s,d,ds,k)
  116.     mGP = 0
  117.     for i in range(c):
  118.         mGP += random.choice([1,2,3])
  119.     gb = math.floor(mGP/20)
  120.     if keys:
  121.         results.append(math.floor(k))
  122.         rb.append(gb)
  123.     else: #daily specials  
  124.         results.append(ds)
  125.         rb.append(gb)
  126.  
  127. print("Average:",np.average(results))
  128.  
  129. # a histogram returns 3 objects : n (i.e. frequncies), bins, patches
  130. showplot = True
  131. if showplot:
  132.     label = "Keys" if keys else "Daily Specials"
  133.     freq, bins, patches = plt.hist(results,edgecolor='white', label=label, bins=range(5,25,1))
  134.  
  135.     for x in range(len(freq)):
  136.         print(x,":",freq[x])
  137.  
  138.     # x coordinate for labels
  139.     bin_centers = np.diff(bins)*0.5 + bins[:-1]
  140.  
  141.     n = 0
  142.     for fr, x, patch in zip(freq, bin_centers, patches):
  143.         height = (freq[n]/len(results))
  144.         plt.annotate("{}".format(height),
  145.                     xy = (x, height*len(results)),             # top left corner of the histogram bar
  146.                     xytext = (0,0.2),             # offsetting label position above its bar
  147.                     textcoords = "offset points", # Offset (in points) from the *xy* value
  148.                     ha = 'center', va = 'bottom'
  149.                     )
  150.         n = n+1
  151.  
  152.     plt.legend()
  153.     plt.show()
  154.  
  155.     # Second graph will be shown after the first one is closed
  156.     label = "Gand Prizes"# if keys else "Daily Specials"
  157.     freq, bins, patches = plt.hist(rb,edgecolor='white', label=label, bins=range(10,20,1))
  158.  
  159.     for x in range(len(freq)):
  160.         print(x,":",freq[x])
  161.  
  162.     # x coordinate for labels
  163.     bin_centers = np.diff(bins)*0.5 + bins[:-1]
  164.  
  165.     n = 0
  166.     for fr, x, patch in zip(freq, bin_centers, patches):
  167.         height = (freq[n]/len(rb))
  168.         plt.annotate("{}".format(height),
  169.                     xy = (x, height*len(rb)),             # top left corner of the histogram bar
  170.                     xytext = (0,0.2),             # offsetting label position above its bar
  171.                     textcoords = "offset points", # Offset (in points) from the *xy* value
  172.                     ha = 'center', va = 'bottom'
  173.                     )
  174.         n = n+1
  175.  
  176.     plt.legend()
  177.     plt.show()
  178.  
  179. # For last game
  180. printStats = False
  181. if printStats:
  182.     print("---------")
  183.     print("Totals")
  184.     print("Starting stars:",starting,"Stars spent:",c*10,"( 10 ->",c*100/starting,")")
  185.     print("Stars Back per Turn:",(c*10-starting)/c)
  186.     print("Candles:",c)
  187.     print("(Starting) Stars per Candle:",starting/c)
  188.     print("Daily Specials:",ds)
  189.     print("(Starting) Stars per Daily Special",starting/ds)
Advertisement
Add Comment
Please, Sign In to add comment