Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
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 |
|
@@ -14,13 +14,20 @@ def roll_dice(num_rolls, dice_type):
|
|
14 |
return rolls
|
15 |
|
16 |
def plot_tokens(health_tokens, coin_tokens):
|
17 |
-
|
|
|
|
|
|
|
18 |
health_foods = [FOOD_LIST[i] for i in health_tokens]
|
19 |
coin_foods = [FOOD_LIST[i] for i in coin_tokens]
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
|
25 |
st.title("๐ฒ Slot Machine Game")
|
26 |
username = st.text_input("๐ค Enter your username:")
|
@@ -31,8 +38,10 @@ for dice_type in DICE_TYPES:
|
|
31 |
rolls = roll_dice(num_rolls, dice_type)
|
32 |
highest_rolls = sum(roll == dice_type for roll in rolls)
|
33 |
coin_tokens_added = 0
|
|
|
34 |
dice_results = [f"{FOOD_LIST[dice_type]} {roll}" for roll in rolls]
|
35 |
st.write(f"๐ฐ Results for {dice_type}-sided slot machine: {' | '.join(dice_results)}")
|
|
|
36 |
for roll in rolls:
|
37 |
if roll == dice_type:
|
38 |
st.write(f"๐ Congratulations! You got the {FOOD_LIST[dice_type]} jackpot! ๐ฐ Adding 3 coins.")
|
@@ -41,14 +50,17 @@ for dice_type in DICE_TYPES:
|
|
41 |
st.write(f"๐ Congratulations! You got the {FOOD_LIST[dice_type]} maximum value! ๐ Adding 10 health tokens.")
|
42 |
if dice_type == 100:
|
43 |
history["health_tokens"].append(history["health_tokens"][-1] + 10)
|
|
|
44 |
history[f"{dice_type}-sided slot machine jackpots"] = highest_rolls
|
45 |
history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
|
46 |
history["coin_tokens"].append(history["coin_tokens"][-1] + coin_tokens_added)
|
47 |
-
|
48 |
st.write("๐ฐ๐ Token Accumulation:")
|
49 |
-
|
|
|
50 |
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)
|
51 |
timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
|
52 |
filename = f"{username}_{timestamp}.csv"
|
53 |
df.to_csv(filename, index=False)
|
54 |
-
st.markdown(f'<a href="data:file/csv;base64,{b64encode(open(filename, "rb").read()).decode()}" download="{filename}">Download CSV File</a>', unsafe_allow_html=True)
|
|
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
+
import pygraphviz as pgv
|
5 |
from datetime import datetime
|
6 |
from base64 import b64encode
|
7 |
|
|
|
14 |
return rolls
|
15 |
|
16 |
def plot_tokens(health_tokens, coin_tokens):
|
17 |
+
dot = pgv.AGraph(strict=False, directed=True)
|
18 |
+
dot.node_attr['shape'] = 'plaintext'
|
19 |
+
dot.edge_attr['arrowhead'] = 'none'
|
20 |
+
|
21 |
health_foods = [FOOD_LIST[i] for i in health_tokens]
|
22 |
coin_foods = [FOOD_LIST[i] for i in coin_tokens]
|
23 |
+
|
24 |
+
health_tokens_str = " | ".join(health_foods)
|
25 |
+
coin_tokens_str = " | ".join(coin_foods)
|
26 |
+
|
27 |
+
dot.add_edge('Health', health_tokens_str)
|
28 |
+
dot.add_edge('Coins', coin_tokens_str)
|
29 |
+
|
30 |
+
st.graphviz_chart(dot.string())
|
31 |
|
32 |
st.title("๐ฒ Slot Machine Game")
|
33 |
username = st.text_input("๐ค Enter your username:")
|
|
|
38 |
rolls = roll_dice(num_rolls, dice_type)
|
39 |
highest_rolls = sum(roll == dice_type for roll in rolls)
|
40 |
coin_tokens_added = 0
|
41 |
+
|
42 |
dice_results = [f"{FOOD_LIST[dice_type]} {roll}" for roll in rolls]
|
43 |
st.write(f"๐ฐ Results for {dice_type}-sided slot machine: {' | '.join(dice_results)}")
|
44 |
+
|
45 |
for roll in rolls:
|
46 |
if roll == dice_type:
|
47 |
st.write(f"๐ Congratulations! You got the {FOOD_LIST[dice_type]} jackpot! ๐ฐ Adding 3 coins.")
|
|
|
50 |
st.write(f"๐ Congratulations! You got the {FOOD_LIST[dice_type]} maximum value! ๐ Adding 10 health tokens.")
|
51 |
if dice_type == 100:
|
52 |
history["health_tokens"].append(history["health_tokens"][-1] + 10)
|
53 |
+
|
54 |
history[f"{dice_type}-sided slot machine jackpots"] = highest_rolls
|
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)
|
65 |
+
st.markdown(f'<a href="data:file/csv;base64,{b64encode(open(filename, "rb").read()).decode()}" download="{filename}">Download CSV File</a>', unsafe_allow_html=True)
|
66 |
+
|