import random
import numpy as np
from matplotlib import pyplot as plt
import math
# Hey! You might notice that this is "based on" (95% copy of) my forge bowl simulator, so some names come from that :P
def simulation(starting_rations, incidents, active_hero, player_focus, num_iterations):
deC = active_hero.lower() == "default"
yaC = active_hero.lower() == "progress"
dsC = active_hero.lower() == "special"
leC = active_hero.lower() == "league"
if(active_hero.lower() == "diamond"):
deC, yaC, dsC, leC = True, True, True, True
if not (deC or yaC or dsC or leC):
print("Incorrect hero, make sure you spelled the hero correctly:")
print("\"Default\", \"Progress\", \"Special\", \"League\", \"Diamond\"")
return
print("Hero chosen:",active_hero)
if(player_focus.lower() == "daily"):
maxDs = True
print("Focus: Daily Specials")
else:
maxDs = False
print("Focus: Miles")
eggs = starting_rations+incidents
print("Total Travel Rations:",eggs)
print("Total Events Simulated:",num_iterations)
d = 0
y = 0
costs = [49,48,41,60,64,62,74,76,78,104,101,105]
yds = [4,4,4,5,5,5,6,6,6,7,7,7]
ds = [0.05,0.05,0.05,0.08,0.08,0.08,0.1,0.1,0.1,0.12,0.12,0.12]
dailies = []
yards = []
def bestD(ids):
# return random.choice([x for x in range(len(ids))])
dCost = [costs[ids[x]]/(ds[ids[x]]+0.05*int(dsC))
for x in range(len(ids))]
b = min(dCost)
return dCost.index(b)
def bestY(ids):
# return random.choice([x for x in range(len(ids))])
yCost = [costs[ids[x]]/(yds[ids[x]]+1*int(yaC))
for x in range(len(ids))]
b = min(yCost)
return yCost.index(b)
print("Progress:")
for i in range(num_iterations):
if i % int(num_iterations/10) == 0:
print(str(round(100*(i/num_iterations))), end="% ")#end=" %\r")
e = eggs
d = 0
y = 0
while True:
# Pick 3 players
ps = [0,3,6,9]#random.sample([0, 3, 6, 9], 3)
num = [random.choice([0, 1, 2, 4]), random.choice(
[0, 1, 2, 4]), random.choice([0, 1, 2, 4])]
ids = [ps[x]+num[x] for x in range(3)]
# Check if you can afford any of the players, remove the ones you can't or exit if you can't afford any
if e < 150:
for x in range(3):
if e < costs[ids[2-x]]:
del ids[2-x]
if(len(ids) == 0):
break
# Get best choice
if maxDs:
b = bestD(ids)
else:
b = bestY(ids)
b = ids[b]
# Update results based on choice
e -= costs[b]
if(random.random() < ds[b]+0.05*int(dsC)):
d += 2 if (random.random() < 0.03) and deC else 1
y += yds[b] + 1*int(yaC)
dailies.append(d)
yards.append(y)
print()
print()
# Show plots of results
showplot = True
if showplot:
label = "Daily Specials"
rmin = min(dailies)
rmax = max(dailies)
#freq, bins, patches = plt.hist(dailies, edgecolor='white', label=label, bins=range(rmin, rmax, 1))
fig, ax = plt.subplots(2,1,figsize=(10,10))
fig.suptitle("2023 Forge Bowl Estimates\n Total Rations: " + str(eggs) + " | Coach: " + active_hero +" | Focus: " + player_focus + " | Iterations: " + str(num_iterations) )
ax[0].hist(dailies, edgecolor='white', label=label, bins=range(rmin, rmax, 1))
print("Average Daily Specials:", np.average(dailies))
#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(dailies))
ax[0].annotate("{}".format(height),
# top left corner of the histogram bar
xy=(x, height*len(dailies)),
# offsetting label position above its bar
xytext=(0, 0.2),
# Offset (in points) from the *xy* value
textcoords="offset points",
ha='center', va='bottom'
)
n = n+1
'''
ax[0].set_yticklabels([])
ax[0].set_title("Daily Specials")
ax[0].set_ylabel("Probability")
ax[0].set_xlabel("Number")
label1 = "Miles"
rmin1 = min(yards)
rmax1 = max(yards)
#freq, bins, patches = plt.hist(yards,edgecolor='white', label=label1, bins=range(rmin1,rmax1,1))
ax[1].hist(yards, edgecolor='white', label=label1, bins=range(rmin1, rmax1, 1))
print("Average Miles:",round(np.average(yards),2))
print("Grand Prices:",math.floor(np.average(yards)/80),"(+"+str(round(np.average(yards)-80*math.floor(np.average(yards)/80),2))+" miles)")
#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(yards))
ax[1].annotate("{}".format(height),
xy = (x, height*len(yards)), # 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
'''
ax[1].axvline(x = 1040, color = "g",label="Required (with league)")
ax[1].axvline(x = 1200, color = "r",label="Required (w/o league)")
ax[1].set_yticklabels([])
ax[1].set_title("Miles")
ax[1].set_ylabel("Probability")
ax[1].set_xlabel("Number")
ax[1].legend()
ups = []
for i in range(len(yards)):
num = math.floor((yards[i]+80)/160)+3
ups.append(num)
umin = min(ups)
umax = max(ups)
print("\nChance of number of Pergola levels (11 needed):")
for i in range(umin,umax+1):
print(i,"Levels:",round(100*(ups.count(i)/len(ups)),1),"%")
print("Note: does NOT count surprise box or league placement")
plt.show()