awacke1 commited on
Commit
ff20623
ยท
verified ยท
1 Parent(s): 707d06e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
2
  import pandas as pd
3
  import plotly.express as px
4
  import random
5
- import json
6
  import uuid
7
  from datetime import datetime
8
  from streamlit_flow import streamlit_flow
@@ -60,15 +59,12 @@ ACTIONS = [
60
 
61
  # ๐ŸŽฒ Game Mechanics
62
  def generate_situation():
63
- """๐Ÿ”„ Randomly select a new situation for the player"""
64
  return random.choice(SITUATIONS)
65
 
66
  def generate_actions():
67
- """๐ŸŽญ Generate a set of three random actions for the player to choose from"""
68
  return random.sample(ACTIONS, 3)
69
 
70
  def evaluate_action(action, gear_strength, rider_skill, history):
71
- """โš–๏ธ Determine the outcome of a player's action"""
72
  base_success_chance = (gear_strength + rider_skill) / 2
73
  if action['id'] in history:
74
  success_chance = base_success_chance + (history[action['id']] * 2)
@@ -79,7 +75,6 @@ def evaluate_action(action, gear_strength, rider_skill, history):
79
 
80
  # ๐ŸŒณ Journey Visualization
81
  def create_graph_from_history(history_df):
82
- """๐Ÿ“Š Create a visual representation of the player's journey"""
83
  nodes = []
84
  edges = []
85
  for index, row in history_df.iterrows():
@@ -95,9 +90,18 @@ def create_graph_from_history(history_df):
95
 
96
  return nodes, edges
97
 
 
 
 
 
 
 
 
 
 
 
98
  # ๐Ÿ”„ Game State Management
99
  def update_game_state(game_state, situation, action, outcome, timestamp):
100
- """๐Ÿ”„ Update the game state with the latest action and its outcome"""
101
  new_record = pd.DataFrame({
102
  'user_id': [game_state['user_id']],
103
  'timestamp': [timestamp],
@@ -121,7 +125,6 @@ def update_game_state(game_state, situation, action, outcome, timestamp):
121
 
122
  # ๐ŸŽฎ Main Game Application
123
  def main():
124
- """๐ŸŽฎ Main game loop and Streamlit interface"""
125
  st.title("๐Ÿฑ Cat Rider ๐Ÿ‡")
126
  st.markdown("""
127
  ## Welcome to Cat Rider!
@@ -190,16 +193,24 @@ def main():
190
  timestamp
191
  )
192
 
 
 
 
 
193
  # ๐ŸŒณ Display Journey Graph
194
  if not st.session_state.game_state['history_df'].empty:
195
  st.markdown("## ๐ŸŒณ Your Journey")
196
  nodes, edges = create_graph_from_history(st.session_state.game_state['history_df'])
197
- streamlit_flow('cat_rider_flow',
198
- nodes,
199
- edges,
200
- layout=TreeLayout(direction='down'),
201
- fit_view=True,
202
- height=600)
 
 
 
 
203
 
204
  # ๐Ÿ“Š Character Stats Visualization
205
  data = {"Stat": ["Gear Strength ๐Ÿ›ก๏ธ", "Rider Skill ๐Ÿ‡"],
 
2
  import pandas as pd
3
  import plotly.express as px
4
  import random
 
5
  import uuid
6
  from datetime import datetime
7
  from streamlit_flow import streamlit_flow
 
59
 
60
  # ๐ŸŽฒ Game Mechanics
61
  def generate_situation():
 
62
  return random.choice(SITUATIONS)
63
 
64
  def generate_actions():
 
65
  return random.sample(ACTIONS, 3)
66
 
67
  def evaluate_action(action, gear_strength, rider_skill, history):
 
68
  base_success_chance = (gear_strength + rider_skill) / 2
69
  if action['id'] in history:
70
  success_chance = base_success_chance + (history[action['id']] * 2)
 
75
 
76
  # ๐ŸŒณ Journey Visualization
77
  def create_graph_from_history(history_df):
 
78
  nodes = []
79
  edges = []
80
  for index, row in history_df.iterrows():
 
90
 
91
  return nodes, edges
92
 
93
+ # ๐Ÿ“ Markdown Preview
94
+ def create_markdown_preview(history_df):
95
+ markdown = "## ๐ŸŒณ Journey Preview\n\n"
96
+ for index, row in history_df.iterrows():
97
+ indent = " " * index
98
+ markdown += f"{indent}- {row['situation_emoji']} **{row['situation_name']}**\n"
99
+ markdown += f"{indent} - {row['action_emoji']} {row['action_name']}: "
100
+ markdown += "โœ… Success\n" if row['outcome'] else "โŒ Failure\n"
101
+ return markdown
102
+
103
  # ๐Ÿ”„ Game State Management
104
  def update_game_state(game_state, situation, action, outcome, timestamp):
 
105
  new_record = pd.DataFrame({
106
  'user_id': [game_state['user_id']],
107
  'timestamp': [timestamp],
 
125
 
126
  # ๐ŸŽฎ Main Game Application
127
  def main():
 
128
  st.title("๐Ÿฑ Cat Rider ๐Ÿ‡")
129
  st.markdown("""
130
  ## Welcome to Cat Rider!
 
193
  timestamp
194
  )
195
 
196
+ # ๐Ÿ“ Display Markdown Preview
197
+ if not st.session_state.game_state['history_df'].empty:
198
+ st.markdown(create_markdown_preview(st.session_state.game_state['history_df']))
199
+
200
  # ๐ŸŒณ Display Journey Graph
201
  if not st.session_state.game_state['history_df'].empty:
202
  st.markdown("## ๐ŸŒณ Your Journey")
203
  nodes, edges = create_graph_from_history(st.session_state.game_state['history_df'])
204
+ try:
205
+ streamlit_flow('cat_rider_flow',
206
+ nodes,
207
+ edges,
208
+ layout=TreeLayout(direction='down'),
209
+ fit_view=True,
210
+ height=600)
211
+ except Exception as e:
212
+ st.error(f"An error occurred while rendering the journey graph: {str(e)}")
213
+ st.markdown("Please try refreshing the page if the graph doesn't appear.")
214
 
215
  # ๐Ÿ“Š Character Stats Visualization
216
  data = {"Stat": ["Gear Strength ๐Ÿ›ก๏ธ", "Rider Skill ๐Ÿ‡"],