Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,99 +8,189 @@ from streamlit_flow import streamlit_flow
|
|
8 |
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
|
9 |
from streamlit_flow.layouts import TreeLayout
|
10 |
|
11 |
-
# ๐ Game World Data
|
12 |
-
SITUATIONS = [
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
|
|
|
31 |
def generate_encounter_conclusion(situation, action, outcome):
|
32 |
-
# Scenario-based conclusions
|
33 |
if outcome:
|
34 |
-
|
35 |
-
f"Your {action['name']} was successful! You've overcome the challenges of {situation['name']}. ๐",
|
36 |
-
f"Through clever use of {action['name']}, you've triumphed in the {situation['name']}! ๐",
|
37 |
-
f"Your mastery of {action['name']} led to victory in the {situation['name']}! ๐ช"
|
38 |
-
]
|
39 |
else:
|
40 |
-
|
41 |
-
f"Despite your efforts with {action['name']}, you couldn't overcome the {situation['name']}. ๐",
|
42 |
-
f"Your attempt at {action['name']} wasn't enough in the {situation['name']}. ๐ข",
|
43 |
-
f"The challenges of {situation['name']} proved too great this time. ๐"
|
44 |
-
]
|
45 |
-
return random.choice(conclusions)
|
46 |
-
|
47 |
-
def update_character_stats(game_state, outcome):
|
48 |
-
# Improve stats only on success
|
49 |
-
if outcome:
|
50 |
-
game_state['gear_strength'] = min(10, game_state['gear_strength'] + random.uniform(0.1, 0.5))
|
51 |
-
game_state['rider_skill'] = min(10, game_state['rider_skill'] + random.uniform(0.1, 0.5))
|
52 |
-
return game_state
|
53 |
-
|
54 |
-
# ๐ณ Journey Visualization with Heterogeneous Graph Structure (unchanged)
|
55 |
-
def create_heterogeneous_graph(history_df):
|
56 |
-
# Your existing node and edge creation logic
|
57 |
-
...
|
58 |
|
59 |
-
#
|
60 |
-
|
61 |
-
markdown = "## ๐ณ Journey Preview\n\n"
|
62 |
-
for index, row in history_df.iterrows():
|
63 |
-
indent = " " * (index * 3)
|
64 |
-
markdown += f"{indent}๐ **{row['situation_name']}** ({row['situation_type']})\n"
|
65 |
-
markdown += f"{indent} โช {row['action_emoji']} {row['action_name']} ({row['action_type']}): "
|
66 |
-
markdown += "โ
Success\n" if row['outcome'] else "โ Failure\n"
|
67 |
-
markdown += f"{indent} ๐ {row['conclusion']}\n"
|
68 |
-
markdown += f"{indent} ๐ช Gear: {row['gear_strength']:.2f} | ๐๏ธ Skill: {row['rider_skill']:.2f}\n\n"
|
69 |
-
return markdown
|
70 |
-
|
71 |
-
# ๐ Game State Management (unchanged)
|
72 |
-
def update_game_state(game_state, situation, action, outcome, timestamp):
|
73 |
-
# Update based on encounter outcome
|
74 |
-
conclusion = generate_encounter_conclusion(situation, action, outcome)
|
75 |
-
game_state = update_character_stats(game_state, outcome)
|
76 |
-
|
77 |
-
new_record = pd.DataFrame({
|
78 |
-
'user_id': [game_state['user_id']],
|
79 |
-
'timestamp': [timestamp],
|
80 |
-
'situation_id': [situation['id']],
|
81 |
-
'situation_name': [situation['name']],
|
82 |
-
'situation_emoji': [situation['emoji']],
|
83 |
-
'situation_type': [situation['type']],
|
84 |
-
'action_id': [action['id']],
|
85 |
-
'action_name': [action['name']],
|
86 |
-
'action_emoji': [action['emoji']],
|
87 |
-
'action_type': [action['type']],
|
88 |
-
'outcome': [outcome],
|
89 |
-
'conclusion': [conclusion],
|
90 |
-
'gear_strength': [game_state['gear_strength']],
|
91 |
-
'rider_skill': [game_state['rider_skill']],
|
92 |
-
'score': [game_state['score']]
|
93 |
-
})
|
94 |
-
game_state['history_df'] = pd.concat([game_state['history_df'], new_record], ignore_index=True)
|
95 |
-
|
96 |
-
if action['id'] in game_state['history']:
|
97 |
-
game_state['history'][action['id']] += 1 if outcome else -1
|
98 |
-
else:
|
99 |
-
game_state['history'][action['id']] = 1 if outcome else -1
|
100 |
-
|
101 |
-
return game_state
|
102 |
-
|
103 |
-
# ๐ฎ Main Game Application (main logic with improvements)
|
104 |
def main():
|
105 |
st.title("๐ฑ Cat Rider ๐")
|
106 |
st.markdown("""
|
@@ -120,7 +210,7 @@ def main():
|
|
120 |
| 5๏ธโฃ | Complete the Quest and Grow Stronger |
|
121 |
""")
|
122 |
|
123 |
-
# ๐ Initialize game state
|
124 |
if 'game_state' not in st.session_state:
|
125 |
st.session_state.game_state = {
|
126 |
'user_id': str(uuid.uuid4()),
|
@@ -130,17 +220,12 @@ def main():
|
|
130 |
'rider_skill': 5,
|
131 |
'history_df': pd.DataFrame(columns=['user_id', 'timestamp', 'situation_id', 'situation_name', 'situation_emoji', 'situation_type', 'action_id', 'action_name', 'action_emoji', 'action_type', 'outcome', 'conclusion', 'gear_strength', 'rider_skill', 'score'])
|
132 |
}
|
133 |
-
|
134 |
-
#
|
135 |
-
st.sidebar.markdown("## ๐ Game Stats")
|
136 |
-
st.sidebar.markdown(f"**Score:** {st.session_state.game_state['score']}")
|
137 |
-
st.sidebar.markdown(f"**Gear Strength:** {st.session_state.game_state['gear_strength']:.2f}")
|
138 |
-
st.sidebar.markdown(f"**Rider Skill:** {st.session_state.game_state['rider_skill']:.2f}")
|
139 |
-
|
140 |
-
# ๐ญ Game Loop
|
141 |
situation = generate_situation()
|
142 |
actions = generate_actions()
|
143 |
|
|
|
144 |
st.markdown(f"## {situation['emoji']} Current Situation: {situation['name']} ({situation['type']})")
|
145 |
st.markdown(situation['description'])
|
146 |
st.markdown("### ๐ญ Choose your action:")
|
@@ -176,7 +261,7 @@ def main():
|
|
176 |
st.markdown(f"**Updated Stats:**")
|
177 |
st.markdown(f"๐ช Gear Strength: {st.session_state.game_state['gear_strength']:.2f}")
|
178 |
st.markdown(f"๐๏ธ Rider Skill: {st.session_state.game_state['rider_skill']:.2f}")
|
179 |
-
|
180 |
# ๐ Display Markdown Preview (unchanged)
|
181 |
if not st.session_state.game_state['history_df'].empty:
|
182 |
st.markdown(create_markdown_preview(st.session_state.game_state['history_df']))
|
@@ -196,7 +281,7 @@ def main():
|
|
196 |
st.error(f"An error occurred while rendering the journey graph: {str(e)}")
|
197 |
st.markdown("Please try refreshing the page if the graph doesn't appear.")
|
198 |
|
199 |
-
# ๐ Character Stats Visualization
|
200 |
data = {"Stat": ["Gear Strength ๐ก๏ธ", "Rider Skill ๐"],
|
201 |
"Value": [st.session_state.game_state['gear_strength'], st.session_state.game_state['rider_skill']]}
|
202 |
df = pd.DataFrame(data)
|
|
|
8 |
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
|
9 |
from streamlit_flow.layouts import TreeLayout
|
10 |
|
11 |
+
# ๐ Game World Data - SITUATIONS and ACTIONS expanded with humorous elements
|
12 |
+
SITUATIONS = [
|
13 |
+
{
|
14 |
+
"id": "feline_escape",
|
15 |
+
"name": "The Great Feline Escape",
|
16 |
+
"description": "Your cat rider is trapped in an old mansion, which is about to be demolished. Using agility, wit, and bravery, orchestrate the perfect escape before the walls crumble! ๐๏ธ",
|
17 |
+
"emoji": "๐ช",
|
18 |
+
"type": "escape"
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"id": "lost_temple",
|
22 |
+
"name": "The Treasure of the Lost Temple",
|
23 |
+
"description": "On a quest to retrieve an ancient artifact, your cat rider must navigate through a labyrinth filled with traps and guardian spirits. Don't let the spooky ghosts get you! ๐ป",
|
24 |
+
"emoji": "๐๏ธ",
|
25 |
+
"type": "exploration"
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"id": "royal_tournament",
|
29 |
+
"name": "The Royal Tournament",
|
30 |
+
"description": "Compete in a grand tournament where the finest cat riders showcase their skills and bravery to earn the title of the Royal Rider. Be prepared to face noble feline adversaries! ๐ฑ",
|
31 |
+
"emoji": "๐",
|
32 |
+
"type": "competition"
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"id": "cheese_heist",
|
36 |
+
"name": "The Great Cheese Heist",
|
37 |
+
"description": "Your cat rider must sneak into the royal pantry to steal the legendary Cheese of Destiny. But beware โ the palace mice are guarding it! ๐ง",
|
38 |
+
"emoji": "๐ง",
|
39 |
+
"type": "heist"
|
40 |
+
},
|
41 |
+
{
|
42 |
+
"id": "sky_race",
|
43 |
+
"name": "The Sky Race",
|
44 |
+
"description": "Compete in the annual Sky Race where your cat rider flies across the skies on a magical broomstick! Watch out for lightning storms and mischievous crows! ๐ฉ๏ธ",
|
45 |
+
"emoji": "โ๏ธ",
|
46 |
+
"type": "competition"
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"id": "purr_summit",
|
50 |
+
"name": "The Purr Summit",
|
51 |
+
"description": "Join a secret gathering of the most intellectual cats in the world. Engage in a battle of wits and wisdom to become the Grand Purr! ๐ง ",
|
52 |
+
"emoji": "๐",
|
53 |
+
"type": "debate"
|
54 |
+
},
|
55 |
+
{
|
56 |
+
"id": "cat_nap",
|
57 |
+
"name": "The Eternal Catnap",
|
58 |
+
"description": "You've entered a sacred temple where cats nap for centuries. Can you navigate the dream world and escape before you too are lulled into eternal slumber? ๐๏ธ",
|
59 |
+
"emoji": "๐ค",
|
60 |
+
"type": "exploration"
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"id": "feline_moon_mission",
|
64 |
+
"name": "The Feline Moon Mission",
|
65 |
+
"description": "Blast off into space! Your mission is to plant the flag of Catopia on the moon. But first, you must pilot your rocket through an asteroid field. ๐",
|
66 |
+
"emoji": "๐",
|
67 |
+
"type": "exploration"
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"id": "pirate_cove",
|
71 |
+
"name": "The Pirate Cove",
|
72 |
+
"description": "Sail the high seas with your trusty crew of cats and uncover the secrets of the Pirate Cove. But beware of the treacherous Sea Dogs! ๐ดโโ ๏ธ",
|
73 |
+
"emoji": "๐ดโโ ๏ธ",
|
74 |
+
"type": "exploration"
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"id": "cat_casino",
|
78 |
+
"name": "The Cat Casino",
|
79 |
+
"description": "Test your luck in the glamorous Cat Casino! Bet your whiskers on the tables and try not to lose it all. Meow is the time! ๐ฒ",
|
80 |
+
"emoji": "๐ฐ",
|
81 |
+
"type": "competition"
|
82 |
+
}
|
83 |
+
]
|
84 |
|
85 |
+
ACTIONS = [
|
86 |
+
{
|
87 |
+
"id": "stealth",
|
88 |
+
"name": "Use Stealth",
|
89 |
+
"description": "Sneak past obstacles or enemies without being detected. You're like a ninja in the shadows! ๐พ",
|
90 |
+
"emoji": "๐คซ",
|
91 |
+
"type": "skill"
|
92 |
+
},
|
93 |
+
{
|
94 |
+
"id": "agility",
|
95 |
+
"name": "Showcase Agility",
|
96 |
+
"description": "Perform impressive acrobatic maneuvers to overcome challenges. Cats always land on their feet, right? ๐",
|
97 |
+
"emoji": "๐",
|
98 |
+
"type": "physical"
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"id": "charm",
|
102 |
+
"name": "Charm Others",
|
103 |
+
"description": "Use your cat's natural charisma to win over allies or distract foes. Who could resist those cute eyes? ๐ป",
|
104 |
+
"emoji": "๐ป",
|
105 |
+
"type": "social"
|
106 |
+
},
|
107 |
+
{
|
108 |
+
"id": "resourcefulness",
|
109 |
+
"name": "Be Resourceful",
|
110 |
+
"description": "Utilize the environment or items in creative ways to solve problems. Think on your paws! ๐ง ",
|
111 |
+
"emoji": "๐ง ",
|
112 |
+
"type": "mental"
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"id": "bravery",
|
116 |
+
"name": "Show Bravery",
|
117 |
+
"description": "Face dangers head-on with your feline courage. Not all heroes wear capes โ some wear fur! ๐ฆธโโ๏ธ",
|
118 |
+
"emoji": "๐ฆธโโ๏ธ",
|
119 |
+
"type": "physical"
|
120 |
+
},
|
121 |
+
{
|
122 |
+
"id": "negotiation",
|
123 |
+
"name": "Negotiate",
|
124 |
+
"description": "Use diplomacy and clever negotiation to get out of a tight spot. Every cat has their price! ๐ผ",
|
125 |
+
"emoji": "๐ผ",
|
126 |
+
"type": "social"
|
127 |
+
},
|
128 |
+
{
|
129 |
+
"id": "precision",
|
130 |
+
"name": "Precision Attack",
|
131 |
+
"description": "Execute a perfectly timed attack to disable traps or defeat enemies. Purrfection in motion! ๐ฏ",
|
132 |
+
"emoji": "๐ฏ",
|
133 |
+
"type": "skill"
|
134 |
+
},
|
135 |
+
{
|
136 |
+
"id": "distraction",
|
137 |
+
"name": "Create a Distraction",
|
138 |
+
"description": "Use cunning tricks and diversions to draw attention away from your real goal. Look over there! ๐ช",
|
139 |
+
"emoji": "๐ช",
|
140 |
+
"type": "mental"
|
141 |
+
},
|
142 |
+
{
|
143 |
+
"id": "speed",
|
144 |
+
"name": "Sprint Away",
|
145 |
+
"description": "Run faster than you've ever run before to escape danger. Just like a cat fleeing a vacuum cleaner! ๐โโ๏ธ",
|
146 |
+
"emoji": "๐โโ๏ธ",
|
147 |
+
"type": "physical"
|
148 |
+
},
|
149 |
+
{
|
150 |
+
"id": "insight",
|
151 |
+
"name": "Use Insight",
|
152 |
+
"description": "Tap into ancient feline wisdom to solve puzzles and mysteries. A cat always knows! ๐ฎ",
|
153 |
+
"emoji": "๐ฎ",
|
154 |
+
"type": "mental"
|
155 |
+
}
|
156 |
+
]
|
157 |
|
158 |
+
# Expanded conclusions for outcomes - 10 items each for success and failure
|
159 |
+
SUCCESS_CONCLUSIONS = [
|
160 |
+
"Your swift paws led you to victory! ๐",
|
161 |
+
"You pounced at the perfect moment! ๐",
|
162 |
+
"The stars aligned for your cat rider! ๐",
|
163 |
+
"You navigated the challenge like a true feline champion! ๐ฑ",
|
164 |
+
"Victory is sweet, just like a bowl of fresh milk! ๐ฅ",
|
165 |
+
"Your opponents are left in awe of your skills! ๐บ",
|
166 |
+
"Youโve earned the title of Cat Commander! ๐
",
|
167 |
+
"All the other cats are jealous of your agility! ๐โโ๏ธ",
|
168 |
+
"Your strategy was flawless, and the victory is yours! ๐๏ธ",
|
169 |
+
"Your cat rider is now a legend in the feline world! ๐"
|
170 |
+
]
|
171 |
|
172 |
+
FAILURE_CONCLUSIONS = [
|
173 |
+
"You tried your best, but it just wasnโt enough. ๐ฟ",
|
174 |
+
"Maybe next time, kitty. Keep your tail up! ๐พ",
|
175 |
+
"That didnโt go as planned. Time for a catnap to recover! ๐ค",
|
176 |
+
"Even the best cats have their off days. ๐",
|
177 |
+
"The challenge was too great this time. Better luck next time! ๐",
|
178 |
+
"You might need more than nine lives to get through this. ๐",
|
179 |
+
"The enemy was too clever for your plan. ๐ง ",
|
180 |
+
"You tripped over your own paws! ๐พ",
|
181 |
+
"The cat gods were not in your favor today. ๐",
|
182 |
+
"Itโs okay, every cat has a learning curve. ๐"
|
183 |
+
]
|
184 |
|
185 |
+
# Function to generate encounter conclusions
|
186 |
def generate_encounter_conclusion(situation, action, outcome):
|
|
|
187 |
if outcome:
|
188 |
+
return random.choice(SUCCESS_CONCLUSIONS)
|
|
|
|
|
|
|
|
|
189 |
else:
|
190 |
+
return random.choice(FAILURE_CONCLUSIONS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
+
# The rest of the code remains mostly the same
|
193 |
+
# ๐ฎ Main Game Application
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
def main():
|
195 |
st.title("๐ฑ Cat Rider ๐")
|
196 |
st.markdown("""
|
|
|
210 |
| 5๏ธโฃ | Complete the Quest and Grow Stronger |
|
211 |
""")
|
212 |
|
213 |
+
# ๐ Initialize game state
|
214 |
if 'game_state' not in st.session_state:
|
215 |
st.session_state.game_state = {
|
216 |
'user_id': str(uuid.uuid4()),
|
|
|
220 |
'rider_skill': 5,
|
221 |
'history_df': pd.DataFrame(columns=['user_id', 'timestamp', 'situation_id', 'situation_name', 'situation_emoji', 'situation_type', 'action_id', 'action_name', 'action_emoji', 'action_type', 'outcome', 'conclusion', 'gear_strength', 'rider_skill', 'score'])
|
222 |
}
|
223 |
+
|
224 |
+
# Main gameplay loop and event handling (same as before)
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
situation = generate_situation()
|
226 |
actions = generate_actions()
|
227 |
|
228 |
+
# Display current situation and available actions
|
229 |
st.markdown(f"## {situation['emoji']} Current Situation: {situation['name']} ({situation['type']})")
|
230 |
st.markdown(situation['description'])
|
231 |
st.markdown("### ๐ญ Choose your action:")
|
|
|
261 |
st.markdown(f"**Updated Stats:**")
|
262 |
st.markdown(f"๐ช Gear Strength: {st.session_state.game_state['gear_strength']:.2f}")
|
263 |
st.markdown(f"๐๏ธ Rider Skill: {st.session_state.game_state['rider_skill']:.2f}")
|
264 |
+
|
265 |
# ๐ Display Markdown Preview (unchanged)
|
266 |
if not st.session_state.game_state['history_df'].empty:
|
267 |
st.markdown(create_markdown_preview(st.session_state.game_state['history_df']))
|
|
|
281 |
st.error(f"An error occurred while rendering the journey graph: {str(e)}")
|
282 |
st.markdown("Please try refreshing the page if the graph doesn't appear.")
|
283 |
|
284 |
+
# ๐ Character Stats Visualization
|
285 |
data = {"Stat": ["Gear Strength ๐ก๏ธ", "Rider Skill ๐"],
|
286 |
"Value": [st.session_state.game_state['gear_strength'], st.session_state.game_state['rider_skill']]}
|
287 |
df = pd.DataFrame(data)
|