awacke1 commited on
Commit
be3e5a6
·
verified ·
1 Parent(s): f7b0631

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -8
app.py CHANGED
@@ -51,7 +51,6 @@ ACTIONS = [
51
  {"id": "negotiation", "name": "Negotiate", "description": "Use diplomacy and clever negotiation to get out of a tight spot. Every cat has their price! 💼", "emoji": "💼", "type": "social"}
52
  ]
53
 
54
-
55
  # Expanded conclusions for outcomes - 10 items each for success and failure
56
  SUCCESS_CONCLUSIONS = [
57
  "Your swift paws led you to victory! 🎉",
@@ -106,12 +105,24 @@ def generate_encounter_conclusion(situation, action, outcome):
106
  else:
107
  return random.choice(FAILURE_CONCLUSIONS)
108
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  # 🌳 Journey Visualization
110
  def create_heterogeneous_graph(history_df):
111
  nodes = []
112
  edges = []
113
  for index, row in history_df.iterrows():
114
- scenario_id = f"scenario-{row['situation_id']}"
115
  action_id = f"action-{row['action_id']}-{index}"
116
  conclusion_id = f"conclusion-{index}"
117
 
@@ -123,8 +134,9 @@ def create_heterogeneous_graph(history_df):
123
  action_node = StreamlitFlowNode(action_id, (0, 0), {'content': f"{row['action_emoji']} {row['action_name']}"}, 'output', 'bottom', 'top', shape='ellipse')
124
  nodes.append(action_node)
125
 
126
- # Conclusion node
127
- conclusion_node = StreamlitFlowNode(conclusion_id, (0, 0), {'content': f"{row['conclusion']}\n💪 Gear: {row['gear_strength']:.2f}"}, 'output', 'bottom', 'top', shape='ellipse')
 
128
  nodes.append(conclusion_node)
129
 
130
  # Edges
@@ -146,13 +158,13 @@ def create_markdown_preview(history_df):
146
  for situation_name, group in grouped_scenarios:
147
  markdown += f"🌟 **{situation_name}**\n"
148
  for _, row in group.iterrows():
 
149
  markdown += f" ↪ {row['action_emoji']} {row['action_name']}: "
150
  markdown += "✅ Success\n" if row['outcome'] else "❌ Failure\n"
151
- markdown += f" 📜 {row['conclusion']} 💪 Gear: {row['gear_strength']:.2f} | 🏋️ Skill: {row['rider_skill']:.2f}\n"
152
  markdown += "\n"
153
  return markdown
154
 
155
-
156
  # 🔄 Update game state with the result of the action
157
  def update_game_state(game_state, situation, action, outcome, timestamp):
158
  # Generate the encounter conclusion (success or failure)
@@ -191,7 +203,28 @@ def update_game_state(game_state, situation, action, outcome, timestamp):
191
 
192
  return game_state
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
 
 
 
195
 
196
  # 🎮 Main Game Application
197
  def main():
@@ -284,6 +317,9 @@ def main():
284
  st.markdown(f"💪 Gear Strength: {st.session_state.game_state['gear_strength']:.2f}")
285
  st.markdown(f"🏋️ Rider Skill: {st.session_state.game_state['rider_skill']:.2f}")
286
 
 
 
 
287
  # 📝 Display Markdown Preview
288
  if not st.session_state.game_state['history_df'].empty:
289
  st.markdown(create_markdown_preview(st.session_state.game_state['history_df']))
@@ -311,5 +347,4 @@ def main():
311
  st.plotly_chart(fig)
312
 
313
  if __name__ == "__main__":
314
- main()
315
-
 
51
  {"id": "negotiation", "name": "Negotiate", "description": "Use diplomacy and clever negotiation to get out of a tight spot. Every cat has their price! 💼", "emoji": "💼", "type": "social"}
52
  ]
53
 
 
54
  # Expanded conclusions for outcomes - 10 items each for success and failure
55
  SUCCESS_CONCLUSIONS = [
56
  "Your swift paws led you to victory! 🎉",
 
105
  else:
106
  return random.choice(FAILURE_CONCLUSIONS)
107
 
108
+ # 🔄 Update character stats based on outcome
109
+ def update_character_stats(game_state, outcome):
110
+ if outcome:
111
+ # Increase stats on success
112
+ game_state['rider_skill'] += 0.5
113
+ game_state['gear_strength'] += 0.2
114
+ else:
115
+ # Decrease stats on failure, but not below 1
116
+ game_state['rider_skill'] = max(1, game_state['rider_skill'] - 0.3)
117
+ game_state['gear_strength'] = max(1, game_state['gear_strength'] - 0.1)
118
+ return game_state
119
+
120
  # 🌳 Journey Visualization
121
  def create_heterogeneous_graph(history_df):
122
  nodes = []
123
  edges = []
124
  for index, row in history_df.iterrows():
125
+ scenario_id = f"scenario-{row['situation_id']}-{index}"
126
  action_id = f"action-{row['action_id']}-{index}"
127
  conclusion_id = f"conclusion-{index}"
128
 
 
134
  action_node = StreamlitFlowNode(action_id, (0, 0), {'content': f"{row['action_emoji']} {row['action_name']}"}, 'output', 'bottom', 'top', shape='ellipse')
135
  nodes.append(action_node)
136
 
137
+ # Conclusion node with stars
138
+ stars = '' * int(row['score'])
139
+ conclusion_node = StreamlitFlowNode(conclusion_id, (0, 0), {'content': f"{row['conclusion']}\n{stars}"}, 'output', 'bottom', 'top', shape='ellipse')
140
  nodes.append(conclusion_node)
141
 
142
  # Edges
 
158
  for situation_name, group in grouped_scenarios:
159
  markdown += f"🌟 **{situation_name}**\n"
160
  for _, row in group.iterrows():
161
+ stars = '⭐' * int(row['score'])
162
  markdown += f" ↪ {row['action_emoji']} {row['action_name']}: "
163
  markdown += "✅ Success\n" if row['outcome'] else "❌ Failure\n"
164
+ markdown += f" 📜 {row['conclusion']} {stars} 💪 Gear: {row['gear_strength']:.2f} | 🏋️ Skill: {row['rider_skill']:.2f}\n"
165
  markdown += "\n"
166
  return markdown
167
 
 
168
  # 🔄 Update game state with the result of the action
169
  def update_game_state(game_state, situation, action, outcome, timestamp):
170
  # Generate the encounter conclusion (success or failure)
 
203
 
204
  return game_state
205
 
206
+ # 🏅 Display Scoreboard with Star Emojis and Buckyball Outline
207
+ def display_scoreboard(game_state):
208
+ # Calculate number of star emojis based on score
209
+ score = game_state['score']
210
+ stars = '⭐' * int(score)
211
+
212
+ # Create buckyball style outline (simplified)
213
+ outline = ''
214
+ if score > 0:
215
+ outline = '''
216
+ ⬡ ⬡ ⬡ ⬡ ⬡
217
+ ⬡ ⬡ ⬡ ⬡
218
+ ⬡ ⬡ ⬡ ⬡ ⬡
219
+ ⬡ ⬡ ⬡ ⬡
220
+ ⬡ ⬡ ⬡ ⬡ ⬡
221
+ '''
222
+ else:
223
+ outline = 'No successes yet.'
224
 
225
+ st.markdown("## 🏅 Scoreboard")
226
+ st.markdown(f"**Score:** {stars} ({score})")
227
+ st.markdown(outline)
228
 
229
  # 🎮 Main Game Application
230
  def main():
 
317
  st.markdown(f"💪 Gear Strength: {st.session_state.game_state['gear_strength']:.2f}")
318
  st.markdown(f"🏋️ Rider Skill: {st.session_state.game_state['rider_skill']:.2f}")
319
 
320
+ # 🏅 Display Scoreboard
321
+ display_scoreboard(st.session_state.game_state)
322
+
323
  # 📝 Display Markdown Preview
324
  if not st.session_state.game_state['history_df'].empty:
325
  st.markdown(create_markdown_preview(st.session_state.game_state['history_df']))
 
347
  st.plotly_chart(fig)
348
 
349
  if __name__ == "__main__":
350
+ main()