import random
import numpy as np
from matplotlib import pyplot as plt
import math
simnum = 10000
chestsOnBoard = 14
startingMoney = 9000
goldDice = 4
# In practice the boost will cost 1 gold dice, so just set number of gold dice to one less than you have, it's a good enough approximation.
# When starting you should roll dice until you can get to the first gold dice with one of your gold dice. Then from there use the gold dice you
# just gained to get to the +5% spot. So you use 2 gold dice, but gain 1. The gold dice spot is replaced with +125 money from now on that day.
boost = True
# Chances unboosted, weighted for 2/3 small, 1/2 big chests
chances = [0.05,0.06,0.07,0.05,0.06,0.07,0.12,0.13,0.14]
if boost:
chances = [x + 0.05 for x in chances]
res = []
res2 = []
for _ in range(simnum):
ds = 0
m = startingMoney
# Set up board
slots = [0]*28
for i in range(chestsOnBoard):
slots[i] = random.choice(chances)
random.shuffle(slots)
slots.insert(0,0)
slots.insert(11,2)
slots.insert(16,0)
slots.insert(27,0)
pos = 16 #Starting at +5% spot
rolls = 0
while True:
m -= 100
if m < 0:
break
rolls += 1
roll = random.randint(1,6)
pos += roll
pos = pos % 32
if slots[pos] == 0:
continue
if slots[pos] == 2:
m += 125
continue
ds += 1 if random.random() <= slots[pos] else 0
slots[pos] = random.choice(chances)
res.append(ds)
rem = 0
for _ in range(simnum):
ds = 0
m = startingMoney
slots = [0]*28
for i in range(chestsOnBoard):
slots[i] = random.choice(chances)
random.shuffle(slots)
slots.insert(0,0)
slots.insert(11,2)
slots.insert(16,0)
slots.insert(27,0)
pos = 16
rolls = 0
g = goldDice
while True:
if g > 0 and slots[(pos+6) % 32] > (0.1+boost*0.05):
g -= 1
roll = 6
else:
m -= 100
if m < 0:
break
rolls += 1
roll = random.randint(1,6)
pos += roll
pos = pos % 32
if slots[pos] == 0:
continue
if slots[pos] == 2:
m += 125
continue
ds += 1 if random.random() <= slots[pos] else 0
slots[pos] = random.choice(chances)
res2.append(ds)
rem += g
print(np.average(res)," - Average Daily Specials (just rolls)")
print(np.average(res2)," - Average Daily Specials (rolling gold dice when big chest is 6 slots away)")
showplot = True
if showplot:
label = "Daily Specials"
rmin = min(res)
rmax = max(res)+1
freq, bins, patches = plt.hist(res, edgecolor='white', label=label, bins=range(rmin, rmax, 1))
plt.close()
fig, ax = plt.subplots(2,1,figsize=(10,10))
fig.suptitle("Tenth Anniversary")
ax[0].hist(res, edgecolor='white', label=label, bins=range(rmin, rmax, 1))
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(res))
ax[0].annotate("{}".format(height),
# top left corner of the histogram bar
xy=(x, height*len(res)),
# 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 Only Rolls")
ax[0].set_ylabel("Probability")
ax[0].set_xlabel("Number")
label1 = "Distribution"
rmin1 = min(res2)
rmax1 = max(res2)+1
freq, bins, patches = plt.hist(res2,edgecolor='white', label=label1, bins=range(rmin1,rmax1,1))
ax[1].hist(res2, edgecolor='white', label=label1, bins=range(rmin1, rmax1, 1))
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(res2))
ax[1].annotate("{}".format(height),
xy = (x, height*len(res2)), # 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].set_yticklabels([])
ax[1].set_title("Daily Specials w/ Gold Dice (roll when big chest is 6 tiles away)")
ax[1].set_ylabel("Probability")
ax[1].set_xlabel("Daily Specials")
plt.show()