Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
|
|
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 ๐"],
|