MooingCat

2021 Winter Event Simulation

Nov 10th, 2021 (edited)
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.98 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. for x in range(1):
  99.     if x % 10000 == 0:
  100.         print(x)
  101.     starting = 1355
  102.     s = starting
  103.     ds = 0
  104.     k = 0
  105.     l = getRandomList()
  106.     l2 = []
  107.     i2 = []
  108.     dsFound = False
  109.     d = 1
  110.     c = 0
  111.     while s >= 10:
  112.         s -= 10
  113.         c += 1
  114.         l,l2,i2,dsFound,s,d,ds,k = pickPresent(l,l2,i2,dsFound,s,d,ds,k)
  115.     if keys:
  116.         results.append(math.floor(k))
  117.     else: #daily specials  
  118.         results.append(ds)
  119.  
  120. # a histogram returns 3 objects : n (i.e. frequncies), bins, patches
  121. showplot = False
  122. if showplot:
  123.     label = "Keys" if keys else "Daily Specials"
  124.     freq, bins, patches = plt.hist(results,edgecolor='white', label=label, bins=range(0,50,1))
  125.  
  126.     for x in range(len(freq)):
  127.         print(freq[x])
  128.  
  129.     # x coordinate for labels
  130.     bin_centers = np.diff(bins)*0.5 + bins[:-1]
  131.  
  132.     n = 0
  133.     for fr, x, patch in zip(freq, bin_centers, patches):
  134.         height = (freq[n]/len(results))
  135.         plt.annotate("{}".format(height),
  136.                     xy = (x, height*len(results)),             # top left corner of the histogram bar
  137.                     xytext = (0,0.2),             # offsetting label position above its bar
  138.                     textcoords = "offset points", # Offset (in points) from the *xy* value
  139.                     ha = 'center', va = 'bottom'
  140.                     )
  141.         n = n+1
  142.  
  143.     plt.legend()
  144.     plt.show()
  145.  
  146. # For last game
  147. printStats = True
  148. if printStats:
  149.     print("---------")
  150.     print("Totals")
  151.     print("Starting stars:",starting,"Stars spent:",c*10,"( 10 ->",c*100/starting,")")
  152.     print("Stars Back per Turn:",(c*10-starting)/c)
  153.     print("Candles:",c)
  154.     print("(Starting) Stars per Candle:",starting/c)
  155.     print("Daily Specials:",ds)
  156.     print("(Starting) Stars per Daily Special",starting/ds)
Add Comment
Please, Sign In to add comment