awacke1 commited on
Commit
d532b2c
ยท
1 Parent(s): aa547cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -1,7 +1,7 @@
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
 
@@ -14,13 +14,20 @@ def roll_dice(num_rolls, dice_type):
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:")
@@ -31,8 +38,10 @@ 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.")
@@ -41,14 +50,17 @@ for dice_type in DICE_TYPES:
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
  timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
52
  filename = f"{username}_{timestamp}.csv"
53
  df.to_csv(filename, index=False)
54
- 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)
 
 
1
  import streamlit as st
2
  import numpy as np
3
  import pandas as pd
4
+ import pygraphviz as pgv
5
  from datetime import datetime
6
  from base64 import b64encode
7
 
 
14
  return rolls
15
 
16
  def plot_tokens(health_tokens, coin_tokens):
17
+ dot = pgv.AGraph(strict=False, directed=True)
18
+ dot.node_attr['shape'] = 'plaintext'
19
+ dot.edge_attr['arrowhead'] = 'none'
20
+
21
  health_foods = [FOOD_LIST[i] for i in health_tokens]
22
  coin_foods = [FOOD_LIST[i] for i in coin_tokens]
23
+
24
+ health_tokens_str = " | ".join(health_foods)
25
+ coin_tokens_str = " | ".join(coin_foods)
26
+
27
+ dot.add_edge('Health', health_tokens_str)
28
+ dot.add_edge('Coins', coin_tokens_str)
29
+
30
+ st.graphviz_chart(dot.string())
31
 
32
  st.title("๐ŸŽฒ Slot Machine Game")
33
  username = st.text_input("๐Ÿ‘ค Enter your username:")
 
38
  rolls = roll_dice(num_rolls, dice_type)
39
  highest_rolls = sum(roll == dice_type for roll in rolls)
40
  coin_tokens_added = 0
41
+
42
  dice_results = [f"{FOOD_LIST[dice_type]} {roll}" for roll in rolls]
43
  st.write(f"๐ŸŽฐ Results for {dice_type}-sided slot machine: {' | '.join(dice_results)}")
44
+
45
  for roll in rolls:
46
  if roll == dice_type:
47
  st.write(f"๐ŸŽ‰ Congratulations! You got the {FOOD_LIST[dice_type]} jackpot! ๐Ÿ’ฐ Adding 3 coins.")
 
50
  st.write(f"๐ŸŽ‰ Congratulations! You got the {FOOD_LIST[dice_type]} maximum value! ๐Ÿ’– Adding 10 health tokens.")
51
  if dice_type == 100:
52
  history["health_tokens"].append(history["health_tokens"][-1] + 10)
53
+
54
  history[f"{dice_type}-sided slot machine jackpots"] = highest_rolls
55
  history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
56
  history["coin_tokens"].append(history["coin_tokens"][-1] + coin_tokens_added)
57
+
58
  st.write("๐Ÿ’ฐ๐Ÿ’– Token Accumulation:")
59
+ plot_tokens(history["health_tokens"], history["coin_tokens"])
60
+
61
  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)
62
  timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
63
  filename = f"{username}_{timestamp}.csv"
64
  df.to_csv(filename, index=False)
65
+ 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)
66
+