awacke1 commited on
Commit
cc2268c
ยท
1 Parent(s): 1f9a1e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -154
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 pandas as pd
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
- dice_type = st.selectbox('Choose a type of dice', dice_types, format_func=lambda d: f"{d['name']} {d['emoji']}")
26
- num_rolls = st.slider('How many times do you want to roll the dice?', 1, 1000000, 1000)
27
- rolls = np.random.randint(1, dice_type['sides'] + 1, num_rolls, dtype=np.uint64)
28
- roll_counts = pd.Series(rolls).value_counts().sort_index()
 
 
 
 
 
 
 
29
 
30
- fig = px.sunburst(names=[f'Roll {i}' for i in roll_counts.index],
31
- parents=['Dice Rolls'] * dice_type['sides'],
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
- fig.update_layout(title='Dice Roll Distribution', margin=dict(l=20, r=20, t=40, b=20), width=800, height=600)
 
38
 
39
- show_labels = st.checkbox('Show Labels', value=True)
40
- if not show_labels:
41
- fig.update_traces(textinfo='none')
42
- fig.show()
 
 
 
43
 
44
- bonus_match = False
45
- for dice in dice_types:
46
- if rolls[0] == dice['sides']:
47
- bonus_match = True
48
- bonus_dice_type = dice['name']
49
- bonus_dice_emoji = dice['emoji']
50
- break
51
 
52
- dice_roll_history = st.session_state.dice_roll_history
53
- new_roll_data = pd.DataFrame({'Roll': rolls,
54
- 'Count': np.ones(num_rolls, dtype=np.uint64),
55
- 'DiceNumberOfSides': [dice_type['sides']] * num_rolls,
56
- 'Username': [st.session_state.username] * num_rolls})
57
- if bonus_match:
58
- new_roll_data['BonusMatchToDiceName'] = [bonus_dice_type] * num_rolls
59
- new_roll_data['BonusMatchToDiceEmoji'] = [bonus_dice_emoji] * num_rolls
60
 
61
- dice_roll_history = dice_roll_history.append(new_roll_data, ignore_index=True)
62
- st.session_state.dice_roll_history = dice_roll_history
63
 
64
- include_name_column = st.checkbox('Include Username Column in Downloaded CSV', value=True)
 
 
65
 
66
- if st.button('Download Results'):
67
- if include_name_column:
68
- filename = f'dice_roll_history_{st.session_state.username}{dice_type["emoji"]}.csv'
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
- st.write("""
76
- ๐Ÿž Bread
77
- ๐Ÿฅ Croissant
78
- ๐Ÿฅ– Baguette Bread
79
- ๐Ÿซ“ Flatbread
80
- ๐Ÿฅจ Pretzel
81
- ๐Ÿฅฏ Bagel
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