Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
import plotly.express as px
|
6 |
+
|
7 |
+
st.set_page_config(layout='wide')
|
8 |
+
st.title('๐ฒ Random Dice Game')
|
9 |
+
|
10 |
+
dice_types = [{'name': 'Six-sided Dice', 'sides': 6, 'emoji': '๐ฒ'},
|
11 |
+
{'name': 'Twenty-sided Dice', 'sides': 20, 'emoji': '๐ฏ'},
|
12 |
+
{'name': 'Thirty-sided Dice', 'sides': 30, 'emoji': '๐ฏ'},
|
13 |
+
{'name': 'One Hundred-sided Dice', 'sides': 100, 'emoji': '๐ฏ'}]
|
14 |
+
|
15 |
+
if 'username' not in st.session_state:
|
16 |
+
st.session_state.username = ''
|
17 |
+
if 'dice_roll_history' not in st.session_state:
|
18 |
+
st.session_state.dice_roll_history = pd.DataFrame()
|
19 |
+
|
20 |
+
def username_input():
|
21 |
+
st.text_input('๐ค Username', key='username')
|
22 |
+
|
23 |
+
def display_dice_roll_distribution():
|
24 |
+
dice_type = st.selectbox('๐ฒ Choose a type of dice', dice_types, format_func=lambda d: f"{d['name']} {d['emoji']}")
|
25 |
+
num_rolls = st.slider('๐ How many times do you want to roll the dice?', 1, 1000000, 1000)
|
26 |
+
|
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 |
+
fig.update_layout(title='๐ Dice Roll Distribution', margin=dict(l=20, r=20, t=40, b=20), width=800, height=600)
|
37 |
+
|
38 |
+
show_labels = st.checkbox('๐ท๏ธ Show Labels', value=True)
|
39 |
+
if not show_labels:
|
40 |
+
fig.update_traces(textinfo='none')
|
41 |
+
fig.show()
|
42 |
+
|
43 |
+
return dice_type, rolls
|
44 |
+
|
45 |
+
def display_bonus_match(bonus_match, bonus_dice_type, bonus_dice_emoji):
|
46 |
+
if bonus_match:
|
47 |
+
st.success(f'๐ You rolled a {bonus_dice_type} {bonus_dice_emoji} on the first roll!')
|
48 |
+
|
49 |
+
def update_dice_roll_history(dice_type, rolls):
|
50 |
+
bonus_match = False
|
51 |
+
for dice in dice_types:
|
52 |
+
if rolls[0] == dice['sides']:
|
53 |
+
bonus_match = True
|
54 |
+
bonus_dice_type = dice['name']
|
55 |
+
bonus_dice_emoji = dice['emoji']
|
56 |
+
break
|
57 |
+
|
58 |
+
dice_roll_history = st.session_state.dice_roll_history
|
59 |
+
new_roll_data = pd.DataFrame({'Roll': rolls,
|
60 |
+
'Count': np.ones(len(rolls), dtype=np.uint64),
|
61 |
+
'DiceNumberOfSides': [dice_type['sides']] * len(rolls),
|
62 |
+
'Username': [st.session_state.username] * len(rolls)})
|
63 |
+
if bonus_match:
|
64 |
+
new_roll_data['BonusMatchToDiceName'] = [bonus_dice_type] * len(rolls)
|
65 |
+
new_roll_data['BonusMatchToDiceEmoji'] = [bonus_dice_emoji] * len(rolls)
|
66 |
+
dice_roll_history = dice_roll_history.append(new_roll_data, ignore_index=True)
|
67 |
+
st.session_state.dice_roll_history = dice_roll_history
|
68 |
+
|
69 |
+
return bonus_match
|
70 |
+
|
71 |
+
st.write("""
|
72 |
+
|
73 |
+
๐ Bread, ๐ฅ Croissant, ๐ฅ Baguette Bread, ๐ซ Flatbread, ๐ฅจ Pretzel, ๐ฅฏ Bagel, ๐ฅ Pancakes, ๐ง Waffle, ๐ง Cheese Wedge, ๐ Meat on Bone, ๐ Poultry Leg, ๐ฅฉ Cut of Meat, ๐ฅ Bacon, ๐ Hamburger, ๐ French Fries, ๐ Pizza, ๐ญ Hot Dog, ๐ฅช Sandwich, ๐ฎ Taco, ๐ฏ Burrito, ๐ซ Tamale, ๐ฅ Stuffed Flatbread, ๐ง Falafel, ๐ฅ Egg, ๐ณ Cooking, ๐ฅ Shallow Pan of Food, ๐ฒ Pot of Food, ๐ซ Fondue, ๐ฅฃ Bowl with Spoon, ๐ฅ Green Salad, ๐ฟ Popcorn, ๐ง Butter, ๐ง Salt, ๐ฅซ Canned Food, ๐ฑ Bento Box, ๐ Rice Cracker, ๐ Rice Ball, ๐ Cooked Rice, ๐ Curry Rice, ๐ Steaming Bowl, ๐ Spaghetti, ๐ Roasted Sweet Potato, ๐ข Oden, ๐ฃ Sushi, ๐ค Fried Shrimp, ๐ฅ Fish Cake with Swirl, ๐ฅฎ Moon Cake, ๐ก Dango, ๐ฅ Dumpling, ๐ฅ Fortune Cookie, ๐ฅก Takeout Box, ๐ฆช Oyster, ๐ฆ Soft Ice Cream, ๐ง Shaved Ice, ๐จ Ice Cream, ๐ฉ Doughnut, ๐ช Cookie, ๐ Birthday Cake, ๐ฐ Shortcake, ๐ง Cupcake, ๐ฅง Pie, ๐ซ Chocolate Bar, ๐ฌ Candy, ๐ญ Lollipop, ๐ฎ Custard, ๐ฏ Honey Pot, ๐ผ Baby Bottle, ๐ฅ Glass of Milk, โ Hot Beverage, ๐ซ Teapot, ๐ต Teacup Without Handle, ๐ถ Sake, ๐พ Bottle with Popping Cork, ๐ท Wine Glass, ๐ธ Cocktail Glass, ๐น Tropical Drink, ๐บ Beer Mug, ๐ป Clinking Beer Mugs, ๐ฅ Clinking Glasses, ๐ฅ Tumbler Glass, ๐ซ Pouring Liquid, ๐ฅค Cup with Straw, ๐ง Bubble Tea, ๐ง Beverage Box, ๐ง Mate, ๐ง Ice, ๐ฅข Chopsticks, ๐ฝ๏ธ Fork and Knife with Plate, ๐ด Fork and Knife, ๐ฅ Spoon, ๐ซ Jar")
|
74 |
+
""")
|
75 |
+
|