Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,44 @@
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
-
import
|
5 |
from datetime import datetime
|
6 |
from base64 import b64encode
|
7 |
|
|
|
8 |
FOOD_LIST = {4: "๐", 6: "๐", 8: "๐ฎ", 10: "๐", 12: "๐ฉ", 20: "๐ฅ", 50: "๐ฃ", 100: "๐พ"}
|
9 |
-
DICE_TYPES = [4, 6, 8, 10, 12, 20, 50, 100]
|
10 |
-
DEFAULT_ROLLS = 3
|
11 |
|
12 |
def roll_dice(num_rolls, dice_type):
|
13 |
rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
|
14 |
return rolls
|
15 |
|
16 |
def plot_tokens(health_tokens, coin_tokens):
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
st.graphviz_chart(dot.string())
|
31 |
|
|
|
|
|
32 |
st.title("๐ฒ Slot Machine Game")
|
33 |
-
username = st.text_input("๐ค Enter your username:")
|
34 |
-
num_rolls = st.slider("๐ข Choose the number of rolls:", 1, 100, DEFAULT_ROLLS)
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
history = {"health_tokens": [0], "coin_tokens": [0]}
|
|
|
37 |
for dice_type in DICE_TYPES:
|
38 |
rolls = roll_dice(num_rolls, dice_type)
|
39 |
highest_rolls = sum(roll == dice_type for roll in rolls)
|
@@ -55,10 +60,10 @@ for dice_type in DICE_TYPES:
|
|
55 |
history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
|
56 |
history["coin_tokens"].append(history["coin_tokens"][-1] + coin_tokens_added)
|
57 |
|
58 |
-
st.write("๐ฐ๐ Token Accumulation:")
|
59 |
plot_tokens(history["health_tokens"], history["coin_tokens"])
|
60 |
|
61 |
df = pd.concat([pd.DataFrame(history["roll_history"]), pd.DataFrame(history["health_tokens"], columns=["Health Tokens"]), pd.DataFrame(history["coin_tokens"], columns=["Coin Tokens"])], axis=1)
|
|
|
62 |
timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
|
63 |
filename = f"{username}_{timestamp}.csv"
|
64 |
df.to_csv(filename, index=False)
|
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
+
import plotly.graph_objects as go
|
5 |
from datetime import datetime
|
6 |
from base64 import b64encode
|
7 |
|
8 |
+
# Define general functions
|
9 |
FOOD_LIST = {4: "๐", 6: "๐", 8: "๐ฎ", 10: "๐", 12: "๐ฉ", 20: "๐ฅ", 50: "๐ฃ", 100: "๐พ"}
|
|
|
|
|
10 |
|
11 |
def roll_dice(num_rolls, dice_type):
|
12 |
rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
|
13 |
return rolls
|
14 |
|
15 |
def plot_tokens(health_tokens, coin_tokens):
|
16 |
+
fig = go.Figure()
|
17 |
+
fig.add_trace(go.Sankey(
|
18 |
+
node = {
|
19 |
+
"label": ["Health", "Coins"] + [FOOD_LIST[i] for i in DICE_TYPES],
|
20 |
+
"pad": 15
|
21 |
+
},
|
22 |
+
link = {
|
23 |
+
"source": [0, 1] + list(range(2, len(DICE_TYPES) + 2)),
|
24 |
+
"target": [2] * len(DICE_TYPES) + [3 + i for i in range(len(DICE_TYPES))],
|
25 |
+
"value": health_tokens + coin_tokens
|
26 |
+
},
|
27 |
+
))
|
28 |
+
st.plotly_chart(fig)
|
|
|
29 |
|
30 |
+
# Define Streamlit app
|
31 |
+
st.set_page_config(page_title="Slot Machine Game", page_icon=":game_die:")
|
32 |
st.title("๐ฒ Slot Machine Game")
|
|
|
|
|
33 |
|
34 |
+
# Sidebar
|
35 |
+
username = st.sidebar.text_input("๐ค Enter your username:")
|
36 |
+
num_rolls = st.sidebar.slider("๐ข Choose the number of rolls:", 1, 100, 3)
|
37 |
+
|
38 |
+
# Main content
|
39 |
+
DICE_TYPES = [4, 6, 8, 10, 12, 20, 50, 100]
|
40 |
history = {"health_tokens": [0], "coin_tokens": [0]}
|
41 |
+
|
42 |
for dice_type in DICE_TYPES:
|
43 |
rolls = roll_dice(num_rolls, dice_type)
|
44 |
highest_rolls = sum(roll == dice_type for roll in rolls)
|
|
|
60 |
history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
|
61 |
history["coin_tokens"].append(history["coin_tokens"][-1] + coin_tokens_added)
|
62 |
|
|
|
63 |
plot_tokens(history["health_tokens"], history["coin_tokens"])
|
64 |
|
65 |
df = pd.concat([pd.DataFrame(history["roll_history"]), pd.DataFrame(history["health_tokens"], columns=["Health Tokens"]), pd.DataFrame(history["coin_tokens"], columns=["Coin Tokens"])], axis=1)
|
66 |
+
|
67 |
timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
|
68 |
filename = f"{username}_{timestamp}.csv"
|
69 |
df.to_csv(filename, index=False)
|