Spaces:
Runtime error
Runtime error
Rename Backup-app-pyBeforeDownload.py to app_backup.py
Browse files
Backup-app-pyBeforeDownload.py β app_backup.py
RENAMED
@@ -5,61 +5,48 @@ import plotly.graph_objects as go
|
|
5 |
from datetime import datetime
|
6 |
from base64 import b64encode
|
7 |
|
8 |
-
# Define emoji list
|
9 |
EMOJI_LIST = {4: "π", 6: "π", 8: "π", 10: "π", 12: "π", 20: "π", 50: "π", 100: "π"}
|
10 |
-
|
11 |
-
# Define the dice types and default number of rolls
|
12 |
DICE_TYPES = [4, 6, 8, 10, 12, 20, 50, 100]
|
13 |
DEFAULT_ROLLS = 3
|
14 |
|
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 |
return rolls
|
19 |
|
20 |
-
# Define a function to plot tokens
|
21 |
def plot_tokens(health_tokens, coin_tokens):
|
22 |
fig = go.Figure()
|
23 |
-
fig.add_trace(go.Scatter(x=list(range(1, len(health_tokens) + 1)), y=health_tokens, name="Health"))
|
24 |
-
fig.add_trace(go.Scatter(x=list(range(1, len(coin_tokens) + 1)), y=coin_tokens, name="Coins"))
|
25 |
fig.update_layout(title="Token Accumulation", xaxis_title="Rolls", yaxis_title="Tokens")
|
26 |
st.plotly_chart(fig)
|
27 |
|
28 |
-
|
29 |
-
st.
|
30 |
-
|
31 |
-
# Get username and number of rolls
|
32 |
-
username = st.text_input("Enter your username:")
|
33 |
-
num_rolls = st.slider("Choose the number of rolls:", 1, 100, DEFAULT_ROLLS)
|
34 |
|
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 |
rolls = roll_dice(num_rolls, dice_type)
|
39 |
highest_rolls = sum(roll == dice_type for roll in rolls)
|
40 |
-
|
|
|
|
|
41 |
for roll in rolls:
|
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 |
-
|
47 |
-
history["coin_tokens"].append(history["coin_tokens"][-1] + 10)
|
48 |
history[f"{dice_type}-sided dice high rolls"] = highest_rolls
|
49 |
history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
|
50 |
-
history["
|
51 |
-
|
52 |
-
|
53 |
-
# Plot token accumulation
|
54 |
-
st.write("Token Accumulation:")
|
55 |
plot_tokens(history["health_tokens"], history["coin_tokens"])
|
56 |
-
|
57 |
-
# Create DataFrame and save to CSV file
|
58 |
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)
|
59 |
timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
|
60 |
filename = f"{username}_{timestamp}.csv"
|
61 |
df.to_csv(filename, index=False)
|
62 |
-
|
63 |
-
# Show download link for CSV file
|
64 |
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)
|
65 |
-
|
|
|
5 |
from datetime import datetime
|
6 |
from base64 import b64encode
|
7 |
|
|
|
8 |
EMOJI_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 |
fig = go.Figure()
|
18 |
+
fig.add_trace(go.Scatter(x=list(range(1, len(health_tokens) + 1)), y=health_tokens, name="π Health"))
|
19 |
+
fig.add_trace(go.Scatter(x=list(range(1, len(coin_tokens) + 1)), y=coin_tokens, name="π° Coins"))
|
20 |
fig.update_layout(title="Token Accumulation", xaxis_title="Rolls", yaxis_title="Tokens")
|
21 |
st.plotly_chart(fig)
|
22 |
|
23 |
+
st.title("π² Dice Rolling Game")
|
24 |
+
username = st.text_input("π€ Enter your username:")
|
25 |
+
num_rolls = st.slider("π’ Choose the number of rolls:", 1, 100, DEFAULT_ROLLS)
|
|
|
|
|
|
|
26 |
|
|
|
27 |
history = {"health_tokens": [0], "coin_tokens": [0]}
|
28 |
for dice_type in DICE_TYPES:
|
29 |
rolls = roll_dice(num_rolls, dice_type)
|
30 |
highest_rolls = sum(roll == dice_type for roll in rolls)
|
31 |
+
coin_tokens_added = 0
|
32 |
+
dice_results = [f"{EMOJI_LIST[dice_type]} {roll}" for roll in rolls]
|
33 |
+
st.write(f"π² Results for {dice_type}-sided dice: {' | '.join(dice_results)}")
|
34 |
for roll in rolls:
|
|
|
35 |
if roll == dice_type:
|
36 |
+
st.write(f"π Congratulations! You rolled the {EMOJI_LIST[dice_type]} highest value! π° Adding 3 coins.")
|
37 |
+
coin_tokens_added += 3
|
38 |
+
if roll == max(rolls):
|
39 |
+
st.write(f"π Congratulations! You rolled the {EMOJI_LIST[dice_type]} maximum value! π Adding 10 health tokens.")
|
40 |
if dice_type == 100:
|
41 |
+
history["health_tokens"].append(history["health_tokens"][-1] + 10)
|
|
|
42 |
history[f"{dice_type}-sided dice high rolls"] = highest_rolls
|
43 |
history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
|
44 |
+
history["coin_tokens"].append(history["coin_tokens"][-1] + coin_tokens_added)
|
45 |
+
|
46 |
+
st.write("π°π Token Accumulation:")
|
|
|
|
|
47 |
plot_tokens(history["health_tokens"], history["coin_tokens"])
|
|
|
|
|
48 |
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)
|
49 |
timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
|
50 |
filename = f"{username}_{timestamp}.csv"
|
51 |
df.to_csv(filename, index=False)
|
|
|
|
|
52 |
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)
|
|