awacke1 commited on
Commit
f360d45
ยท
1 Parent(s): a4a0c0d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 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
+ fig = go.Figure()
18
+ health_foods = [FOOD_LIST[i] for i in health_tokens]
19
+ coin_foods = [FOOD_LIST[i] for i in coin_tokens]
20
+ fig.add_trace(go.Scatter(x=list(range(1, len(health_foods) + 1)), y=health_foods, name="๐Ÿ’– Health"))
21
+ fig.add_trace(go.Scatter(x=list(range(1, len(coin_foods) + 1)), y=coin_foods, name="๐Ÿ’ฐ Coins"))
22
+ fig.update_layout(title="Token Accumulation", xaxis_title="Rolls", yaxis_title="Tokens")
23
+ st.plotly_chart(fig)
24
+
25
+ st.title("๐ŸŽฒ Slot Machine Game")
26
+ username = st.text_input("๐Ÿ‘ค Enter your username:")
27
+ num_rolls = st.slider("๐Ÿ”ข Choose the number of rolls:", 1, 100, DEFAULT_ROLLS)
28
+
29
+ history = {"health_tokens": [0], "coin_tokens": [0]}
30
+ 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.")
39
+ coin_tokens_added += 3
40
+ if roll == max(rolls):
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
+ plot_tokens(history["health_tokens"], history["coin_tokens"])
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
+
52
+ if username:
53
+ username_str = username
54
+ else:
55
+ username_str = "Anonymous"
56
+ timestamp_str = datetime.now().strftime("%m-%d-%Y-%I-%M-%S-%p")
57
+ filename = f"{username_str}_{timestamp_str}.csv"
58
+
59
+ df.to_csv(filename, index=False)
60
+ 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)
61
+