Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,167 +1,78 @@
|
|
1 |
-
# Code Destiny and Density is equal to one hundred.
|
2 |
-
|
3 |
-
#st.Markdown("TODO: A code density slider bar shows and adjusts the size of lines. ')
|
4 |
-
#st.Markdown('Any ๐ฒDice๐ฒ way to compress the lines yet make it readable as optimal list of sets will do. Match language from good math books.')
|
5 |
-
|
6 |
-
import os
|
7 |
import streamlit as st
|
8 |
import numpy as np
|
9 |
-
import
|
10 |
-
import plotly.express as px
|
11 |
-
|
12 |
-
st.set_page_config(layout='wide')
|
13 |
-
st.title('Any ๐ฒDice๐ฒ Way - STEM Math and Data Science Numerical Potluck')
|
14 |
-
|
15 |
-
dice_types = [{'name': 'Six-sided Dice', 'sides': 6, 'emoji': '๐ฒ'},
|
16 |
-
{'name': 'Twenty-sided Dice', 'sides': 20, 'emoji': '๐ฟ'},
|
17 |
-
{'name': 'Thirty-sided Dice', 'sides': 30, 'emoji': '๐ฅ'},
|
18 |
-
{'name': 'One Hundred-sided Dice', 'sides': 100, 'emoji': '๐'}]
|
19 |
-
|
20 |
-
if 'username' not in st.session_state:
|
21 |
-
st.session_state.username = ''
|
22 |
-
if 'dice_roll_history' not in st.session_state:
|
23 |
-
st.session_state.dice_roll_history = pd.DataFrame()
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
values=roll_counts.values,
|
33 |
-
color=[f'Roll {i}' for i in roll_counts.index],
|
34 |
-
color_discrete_sequence=px.colors.qualitative.Dark24,
|
35 |
-
maxdepth=2)
|
36 |
|
37 |
-
|
|
|
38 |
|
39 |
-
|
40 |
-
if not
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
bonus_dice_type = dice['name']
|
49 |
-
bonus_dice_emoji = dice['emoji']
|
50 |
-
break
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
new_roll_data['BonusMatchToDiceEmoji'] = [bonus_dice_emoji] * num_rolls
|
60 |
|
61 |
-
|
62 |
-
st.
|
63 |
|
64 |
-
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
else:
|
70 |
-
dice_roll_history = dice_roll_history.drop(columns=['Username'])
|
71 |
-
filename = f'dice_roll_history{dice_type["emoji"]}.csv'
|
72 |
-
st.download_button(label='Download CSV', data=dice_roll_history.to_csv(index=False), file_name=filename, mime
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
๐ฅ Pancakes
|
83 |
-
๐ง Waffle
|
84 |
-
๐ง Cheese Wedge
|
85 |
-
๐ Meat on Bone
|
86 |
-
๐ Poultry Leg
|
87 |
-
๐ฅฉ Cut of Meat
|
88 |
-
๐ฅ Bacon
|
89 |
-
๐ Hamburger
|
90 |
-
๐ French Fries
|
91 |
-
๐ Pizza
|
92 |
-
๐ญ Hot Dog
|
93 |
-
๐ฅช Sandwich
|
94 |
-
๐ฎ Taco
|
95 |
-
๐ฏ Burrito
|
96 |
-
๐ซ Tamale
|
97 |
-
๐ฅ Stuffed Flatbread
|
98 |
-
๐ง Falafel
|
99 |
-
๐ฅ Egg
|
100 |
-
๐ณ Cooking
|
101 |
-
๐ฅ Shallow Pan of Food
|
102 |
-
๐ฒ Pot of Food
|
103 |
-
๐ซ Fondue
|
104 |
-
๐ฅฃ Bowl with Spoon
|
105 |
-
๐ฅ Green Salad
|
106 |
-
๐ฟ Popcorn
|
107 |
-
๐ง Butter
|
108 |
-
๐ง Salt
|
109 |
-
๐ฅซ Canned Food
|
110 |
-
๐ฑ Bento Box
|
111 |
-
๐ Rice Cracker
|
112 |
-
๐ Rice Ball
|
113 |
-
๐ Cooked Rice
|
114 |
-
๐ Curry Rice
|
115 |
-
๐ Steaming Bowl
|
116 |
-
๐ Spaghetti
|
117 |
-
๐ Roasted Sweet Potato
|
118 |
-
๐ข Oden
|
119 |
-
๐ฃ Sushi
|
120 |
-
๐ค Fried Shrimp
|
121 |
-
๐ฅ Fish Cake with Swirl
|
122 |
-
๐ฅฎ Moon Cake
|
123 |
-
๐ก Dango
|
124 |
-
๐ฅ Dumpling
|
125 |
-
๐ฅ Fortune Cookie
|
126 |
-
๐ฅก Takeout Box
|
127 |
-
๐ฆช Oyster
|
128 |
-
๐ฆ Soft Ice Cream
|
129 |
-
๐ง Shaved Ice
|
130 |
-
๐จ Ice Cream
|
131 |
-
๐ฉ Doughnut
|
132 |
-
๐ช Cookie
|
133 |
-
๐ Birthday Cake
|
134 |
-
๐ฐ Shortcake
|
135 |
-
๐ง Cupcake
|
136 |
-
๐ฅง Pie
|
137 |
-
๐ซ Chocolate Bar
|
138 |
-
๐ฌ Candy
|
139 |
-
๐ญ Lollipop
|
140 |
-
๐ฎ Custard
|
141 |
-
๐ฏ Honey Pot
|
142 |
-
๐ผ Baby Bottle
|
143 |
-
๐ฅ Glass of Milk
|
144 |
-
โ Hot Beverage
|
145 |
-
๐ซ Teapot
|
146 |
-
๐ต Teacup Without Handle
|
147 |
-
๐ถ Sake
|
148 |
-
๐พ Bottle with Popping Cork
|
149 |
-
๐ท Wine Glass
|
150 |
-
๐ธ Cocktail Glass
|
151 |
-
๐น Tropical Drink
|
152 |
-
๐บ Beer Mug
|
153 |
-
๐ป Clinking Beer Mugs
|
154 |
-
๐ฅ Clinking Glasses
|
155 |
-
๐ฅ Tumbler Glass
|
156 |
-
๐ซ Pouring Liquid
|
157 |
-
๐ฅค Cup with Straw
|
158 |
-
๐ง Bubble Tea
|
159 |
-
๐ง Beverage Box
|
160 |
-
๐ง Mate
|
161 |
-
๐ง Ice
|
162 |
-
๐ฅข Chopsticks
|
163 |
-
๐ฝ๏ธ Fork and Knife with Plate
|
164 |
-
๐ด Fork and Knife
|
165 |
-
๐ฅ Spoon
|
166 |
-
๐ซ Jar
|
167 |
-
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
+
import plotly.graph_objects as go
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
# Define emoji list
|
6 |
+
EMOJI_LIST = {
|
7 |
+
4: "๐",
|
8 |
+
6: "๐",
|
9 |
+
8: "๐",
|
10 |
+
10: "๐",
|
11 |
+
12: "๐",
|
12 |
+
20: "๐",
|
13 |
+
50: "๐",
|
14 |
+
100: "๐"
|
15 |
+
}
|
16 |
|
17 |
+
# Define the dice types
|
18 |
+
DICE_TYPES = [4, 6, 8, 10, 12, 20, 50, 100]
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
# Define the default number of rolls
|
21 |
+
DEFAULT_ROLLS = 100
|
22 |
|
23 |
+
# Define session state
|
24 |
+
if "username" not in st.session_state:
|
25 |
+
st.session_state.username = ""
|
26 |
+
if "rolls" not in st.session_state:
|
27 |
+
st.session_state.rolls = DEFAULT_ROLLS
|
28 |
+
if "history" not in st.session_state:
|
29 |
+
st.session_state.history = {}
|
30 |
|
31 |
+
# Define a function to roll dice
|
32 |
+
def roll_dice(num_rolls, dice_type):
|
33 |
+
rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
|
34 |
+
return rolls
|
|
|
|
|
|
|
35 |
|
36 |
+
# Define a function to plot tokens
|
37 |
+
def plot_tokens(health_tokens, coin_tokens):
|
38 |
+
fig = go.Figure()
|
39 |
+
fig.add_trace(go.Scatter(x=list(range(1, len(health_tokens) + 1)), y=health_tokens, name="Health"))
|
40 |
+
fig.add_trace(go.Scatter(x=list(range(1, len(coin_tokens) + 1)), y=coin_tokens, name="Coins"))
|
41 |
+
fig.update_layout(title="Token Accumulation", xaxis_title="Rolls", yaxis_title="Tokens")
|
42 |
+
st.plotly_chart(fig)
|
|
|
43 |
|
44 |
+
# Define the app
|
45 |
+
st.title("Dice Rolling Game")
|
46 |
|
47 |
+
# Get username
|
48 |
+
st.write("Enter your username:")
|
49 |
+
st.session_state.username = st.text_input("Username", st.session_state.username)
|
50 |
|
51 |
+
# Get number of rolls
|
52 |
+
st.write("Choose the number of rolls:")
|
53 |
+
st.session_state.rolls = st.slider("Number of Rolls", 1, 1000000, st.session_state.rolls)
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
# Get dice types and roll dice
|
56 |
+
for dice_type in DICE_TYPES:
|
57 |
+
rolls = roll_dice(st.session_state.rolls, dice_type)
|
58 |
+
st.write(f"Results for {dice_type}-sided dice:")
|
59 |
+
for roll in rolls:
|
60 |
+
st.write(f"{EMOJI_LIST[dice_type]} {roll}")
|
61 |
+
if roll == dice_type:
|
62 |
+
st.write("Congratulations! You rolled the highest value!")
|
63 |
+
if dice_type == 100:
|
64 |
+
st.write("Adding 10 coins for rolling over 90 on 100-sided dice.")
|
65 |
+
if "coin_tokens" not in st.session_state.history:
|
66 |
+
st.session_state.history["coin_tokens"] = [0]
|
67 |
+
st.session_state.history["coin_tokens"].append(st.session_state.history["coin_tokens"][-1] + 10)
|
68 |
+
if "roll_history" not in st.session_state.history:
|
69 |
+
st.session_state.history["roll_history"] = {}
|
70 |
+
st.session_state.history["roll_history"][dice_type] = rolls
|
71 |
|
72 |
+
# Plot tokens
|
73 |
+
if "health_tokens" not in st.session_state.history:
|
74 |
+
st.session_state.history["health_tokens"] = [0]
|
75 |
+
if "coin_tokens" not in st.session_state.history:
|
76 |
+
st.session_state.history["coin_tokens"] = [0]
|
77 |
+
st.write("Token Accumulation:")
|
78 |
+
plot_tokens(st.session_state.history["health_tokens"], st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|