awacke1 commited on
Commit
6f86ef3
ยท
verified ยท
1 Parent(s): 60b006e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +181 -96
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 (unchanged)
12
- SITUATIONS = [ ... ] # Your existing SITUATIONS data
13
- ACTIONS = [ ... ] # Your existing ACTIONS data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- # ๐ŸŽฒ Game Mechanics (unchanged)
16
- def generate_situation():
17
- return random.choice(SITUATIONS)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- def generate_actions():
20
- return random.sample(ACTIONS, 3)
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- def evaluate_action(action, gear_strength, rider_skill, history):
23
- base_success_chance = (gear_strength + rider_skill) / 2
24
- if action['id'] in history:
25
- success_chance = base_success_chance + (history[action['id']] * 2)
26
- else:
27
- success_chance = base_success_chance
28
- outcome = random.randint(1, 100) <= success_chance
29
- return outcome, success_chance
 
 
 
 
30
 
 
31
  def generate_encounter_conclusion(situation, action, outcome):
32
- # Scenario-based conclusions
33
  if outcome:
34
- conclusions = [
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
- conclusions = [
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
- # ๐Ÿ“ Markdown Preview (unchanged)
60
- def create_markdown_preview(history_df):
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 (unchanged)
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
- # ๐Ÿ“Š Game Stats (unchanged)
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 (unchanged)
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)