Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import math
- import numpy as np
- from matplotlib import pyplot as plt
- def getRandomList():
- # 4 - shuffle, 5 - key, 15 - daily, 20 - double
- l = [3,14,4,5,15,20,0,0,0,0,0,0,0,0,0,0,0,0]
- random.shuffle(l)
- return l
- def pickPresent(l,l2,i2,dsFound,s,d,ds,k):
- i = 0
- t = False
- if(len(l2) > 0):
- if sum(l2) > 0:
- if (dsFound and not keys) and 4 in l2:
- i = l2.index(4)
- t = True
- elif 4 in l2:
- if sum(l2) == 4:
- i = random.choice(range(len(l)))
- else:
- i = l2.index(sum(l2)-4)
- t = True
- else:
- i = l2.index(max(l2))
- t = True
- else:
- i = random.choice(range(len(l)))
- else:
- i = random.choice(range(len(l)))
- if t:
- res = l2[i]
- del l2[i]
- del i2[i]
- else:
- res = l[i]
- del l[i]
- if res == 0:
- # nothing
- #print(0)
- d = 1
- elif res == 3:
- i2 = random.sample(range(len(l)),min(2,len(l)))
- l2 = [l[i2[x]] for x in range(len(i2))]
- del l[max(i2)]
- if len(i2) > 1:
- del l[min(i2)]
- s += 3*d
- #print(3*d,"stars + show 2:",l2)
- elif res == 4:
- l2 = []
- i2 = []
- l = getRandomList()
- dsFound = False
- s += 10*d
- #print(10*d,"stars + shuffle:",l)
- return l,l2,i2,dsFound,s,d,ds,k
- elif res == 5:
- k += 1
- if d == 2:
- k += 0.2
- s += 10
- if keys:
- l2 = []
- i2 = []
- l = getRandomList()
- dsFound = False
- else:
- s += 10
- #print(d,"key(s) +",d*10,"stars")
- elif res == 14:
- s += 14*d
- #print(d*14,"stars")
- elif res == 15:
- ds += 1*d
- dsFound = True
- #print(d,"Daily Special(s)")
- elif res == 20:
- d = 2
- #print("Double")
- if res == 20:
- d = 2
- else:
- d = 1
- return l,l2,i2,dsFound,s,d,ds,k
- keys = False
- # Stars
- results = []
- for x in range(1):
- if x % 10000 == 0:
- print(x)
- starting = 1355
- s = starting
- ds = 0
- k = 0
- l = getRandomList()
- l2 = []
- i2 = []
- dsFound = False
- d = 1
- c = 0
- while s >= 10:
- s -= 10
- c += 1
- l,l2,i2,dsFound,s,d,ds,k = pickPresent(l,l2,i2,dsFound,s,d,ds,k)
- if keys:
- results.append(math.floor(k))
- else: #daily specials
- results.append(ds)
- # a histogram returns 3 objects : n (i.e. frequncies), bins, patches
- showplot = False
- if showplot:
- label = "Keys" if keys else "Daily Specials"
- freq, bins, patches = plt.hist(results,edgecolor='white', label=label, bins=range(0,50,1))
- for x in range(len(freq)):
- print(freq[x])
- # x coordinate for labels
- bin_centers = np.diff(bins)*0.5 + bins[:-1]
- n = 0
- for fr, x, patch in zip(freq, bin_centers, patches):
- height = (freq[n]/len(results))
- plt.annotate("{}".format(height),
- xy = (x, height*len(results)), # top left corner of the histogram bar
- xytext = (0,0.2), # offsetting label position above its bar
- textcoords = "offset points", # Offset (in points) from the *xy* value
- ha = 'center', va = 'bottom'
- )
- n = n+1
- plt.legend()
- plt.show()
- # For last game
- printStats = True
- if printStats:
- print("---------")
- print("Totals")
- print("Starting stars:",starting,"Stars spent:",c*10,"( 10 ->",c*100/starting,")")
- print("Stars Back per Turn:",(c*10-starting)/c)
- print("Candles:",c)
- print("(Starting) Stars per Candle:",starting/c)
- print("Daily Specials:",ds)
- print("(Starting) Stars per Daily Special",starting/ds)
Add Comment
Please, Sign In to add comment