Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,10 @@ DEFAULT_ROLLS = 10
|
|
15 |
# Define a function to roll dice
|
16 |
def roll_dice(num_rolls, dice_type):
|
17 |
rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
|
18 |
-
|
|
|
|
|
|
|
19 |
|
20 |
# Define a function to plot tokens
|
21 |
def plot_tokens(health_tokens, coin_tokens):
|
@@ -35,20 +38,21 @@ num_rolls = st.slider("Choose the number of rolls:", 1, 1000000, DEFAULT_ROLLS)
|
|
35 |
# Roll dice for each type and accumulate high rolls and tokens
|
36 |
history = {"health_tokens": [0], "coin_tokens": [0]}
|
37 |
for dice_type in DICE_TYPES:
|
38 |
-
|
39 |
-
highest_rolls = sum(roll == dice_type for roll in rolls)
|
40 |
st.write(f"Results for {dice_type}-sided dice:")
|
41 |
-
for roll in
|
42 |
-
st.write(f"{EMOJI_LIST[dice_type]} {roll}")
|
43 |
if roll == dice_type:
|
44 |
st.write("Congratulations! You rolled the highest value!")
|
45 |
if dice_type == 100:
|
46 |
st.write("Adding 10 coins for rolling over 90 on 100-sided dice.")
|
47 |
history["coin_tokens"].append(history["coin_tokens"][-1] + 10)
|
48 |
-
history[f"{dice_type}-sided dice high rolls"] =
|
49 |
-
history["roll_history"] = {**history.get("roll_history", {}), dice_type:
|
50 |
-
|
51 |
-
|
|
|
|
|
52 |
|
53 |
# Plot token accumulation
|
54 |
st.write("Token Accumulation:")
|
|
|
15 |
# Define a function to roll dice
|
16 |
def roll_dice(num_rolls, dice_type):
|
17 |
rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
|
18 |
+
variables = np.random.randn(num_rolls)
|
19 |
+
df = pd.DataFrame({"Roll": rolls, "Variable": variables})
|
20 |
+
df.index.name = f"{dice_type}-sided dice"
|
21 |
+
return df
|
22 |
|
23 |
# Define a function to plot tokens
|
24 |
def plot_tokens(health_tokens, coin_tokens):
|
|
|
38 |
# Roll dice for each type and accumulate high rolls and tokens
|
39 |
history = {"health_tokens": [0], "coin_tokens": [0]}
|
40 |
for dice_type in DICE_TYPES:
|
41 |
+
df = roll_dice(num_rolls, dice_type)
|
|
|
42 |
st.write(f"Results for {dice_type}-sided dice:")
|
43 |
+
for roll, var in zip(df["Roll"], df["Variable"]):
|
44 |
+
st.write(f"{EMOJI_LIST[dice_type]} {roll} ({var:.2f})")
|
45 |
if roll == dice_type:
|
46 |
st.write("Congratulations! You rolled the highest value!")
|
47 |
if dice_type == 100:
|
48 |
st.write("Adding 10 coins for rolling over 90 on 100-sided dice.")
|
49 |
history["coin_tokens"].append(history["coin_tokens"][-1] + 10)
|
50 |
+
history[f"{dice_type}-sided dice high rolls"] = sum(df["Roll"] == dice_type)
|
51 |
+
history["roll_history"] = {**history.get("roll_history", {}), f"{dice_type}-sided dice": df}
|
52 |
+
|
53 |
+
# Update token accumulation
|
54 |
+
history["health_tokens"].append(sum(df.loc[20, "Roll"] == 20))
|
55 |
+
history["coin_tokens"].append(sum(df.loc[100, "Roll"] == 100) * 10)
|
56 |
|
57 |
# Plot token accumulation
|
58 |
st.write("Token Accumulation:")
|