Skip to content

Instantly share code, notes, and snippets.

@g-leech

g-leech/dnd4.py Secret

Created Apr 7, 2021
Embed
What would you like to do?
import pandas as pd
import matplotlib.pyplot as plt
import os
df = pd.read_csv("../../scraps/dnd/dset.csv", parse_dates=["month of departure"])
df = df.drop(["Unnamed: 0"], axis=1)
df = df.replace("100%+", 100)
df["damage taken"] = df["damage taken"].replace(r'\D+', "", regex=True)
df["damage taken"] = df["damage taken"].astype(int) / 100
enc = df.groupby("encounter").mean().join(
df.groupby("encounter").std(),
rsuffix="_"
).sort_values(ascending=False, by="damage taken") \
.reset_index()
enc.columns = ['encounter', "mu", "std"]
enc.plot.bar(x='encounter', y='mu')
plt.errorbar(enc.encounter, enc["mu"], yerr=1.96*enc["std"], color="red", linestyle='None')
plt.plot(enc.encounter, [1]*len(enc.encounter), linestyle="--")
enc["safety"] = (1 - enc["mu"]) / enc["std"]
enc["risk"] = 1/enc["safety"]
risk = enc[["encounter", "risk"]].set_index("encounter")
cnt = df.groupby("encounter").count()[["damage taken"]]
cnt["prob"] = cnt["damage taken"] / sum(cnt["damage taken"])
cnt = cnt[["prob"]].sort_values(by="prob")
j = cnt.join(risk)
# Doctor it
j.loc["kraken"]["prob"] += 0.05
j.loc["nessie"]["prob"] += 0.05
j["ev"] = j["prob"] * j["risk"]
j["exp_ev"] = j["risk"] / j[~j["risk"].isna()]["risk"].sum()
#j["exp_ev"] = -np.log(j["prob"]) * j["risk"]
ev_gold = 20
evs = j.sort_values(by="ev", ascending=False)[["ev"]].iloc[:4]
evs["%"] = evs["ev"] / sum(evs["ev"])
evs["spend"] = round(evs["%"] * ev_gold)
exp_gold = 80
exps = j.sort_values(by="exp_ev", ascending=False)[["exp_ev"]].iloc[:5]
exps["%"] = exps["exp_ev"] / sum(exps["exp_ev"])
exps["spend"] = round(exps["%"] * exp_gold)
display(evs)
# ev % spend
# kraken 0.049114 0.248997 5.0
# merpeople 0.043793 0.222019 4.0
# pirates 0.043164 0.218834 4.0
# nessie 0.041141 0.208578 4.0
# crabmonsters 0.020035 0.101572 2.0
exps
# exp_ev % spend
# kraken 0.281701 0.346746 28.0
# crabmonsters 0.167990 0.206779 17.0
# nessie 0.163477 0.201223 16.0
# merpeople 0.133342 0.164131 13.0
# demon whale 0.065903 0.081120 6.0
k = 39 # including demon whale
c = 20
m = 17
n = 24 # including pirates
print("oar benefit:", k * 0.02/1)
print("carpenter benefit:", c * 0.5/20)
print("tribute benefit:", m * 100/45)
print("cannon benefit:", n * 0.1/10)
["Oar", "Krakens and Demon Whales", 1, 0.02] # max 20 = 0.02 pg
["Carpenters", "Crabmonster", 20, 0.5] # = 0.025 pg
["Tribute", "Merpeople", 45, 100] # 2.2 pg
["Cannon", "Nessie and Pirate", 10, 0.1] # max 3 = 0.01 pg
# In[76]:
df.groupby("direction").mean().join(
df.groupby("direction").std(),
rsuffix="_"
).sort_values(ascending=False, by="direction")
df.groupby(["encounter", "direction"]).mean()
# ## shark repellent
# In[91]:
time = df.groupby(["encounter", "month of departure"]).mean().reset_index()
plt.figure(figsize=(20,10))
for monster in enc.encounter.unique():
timem = time[time["encounter"] == monster]
plt.plot(timem["month of departure"], timem["damage taken"], label=monster)
plt.legend()
plt.show()
# In[95]:
df["month"] = df["month of departure"].str[:2]
time = df.groupby(["encounter", "month"]).mean().reset_index()
plt.figure(figsize=(20,10))
for monster in enc.encounter.unique():
timem = time[time["encounter"] == monster]
plt.plot(timem["month"], timem["damage taken"], label=monster)
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment