File size: 12,974 Bytes
3e43c6c
be66a8a
af72d67
 
 
 
 
 
 
 
 
be66a8a
af72d67
0f4bb5a
e59ea3f
be66a8a
 
 
 
0f4bb5a
be66a8a
0f4bb5a
4c1130f
 
 
 
 
 
 
 
 
 
 
0f4bb5a
dc60f58
3e43c6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc60f58
 
 
 
 
 
 
 
 
 
3e43c6c
 
 
 
dc60f58
 
 
 
 
 
 
 
 
 
3e43c6c
 
 
be66a8a
 
3e43c6c
 
 
 
 
dc60f58
3e43c6c
 
 
 
dc60f58
 
 
 
3e43c6c
be66a8a
3e43c6c
 
 
be66a8a
3e43c6c
 
 
be66a8a
3e43c6c
 
be66a8a
3e43c6c
 
 
 
 
 
 
be66a8a
3e43c6c
 
 
 
 
 
 
 
 
be66a8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc60f58
3e43c6c
 
 
dc60f58
 
 
7bfbbae
be66a8a
3e43c6c
 
be66a8a
3e43c6c
be66a8a
3e43c6c
be66a8a
 
3e43c6c
 
 
 
be66a8a
 
dc60f58
be66a8a
 
 
 
 
 
 
 
 
dc60f58
be66a8a
dc60f58
be66a8a
dc60f58
be66a8a
 
dc60f58
 
 
 
 
 
 
 
 
 
 
 
 
be66a8a
3e43c6c
 
 
be66a8a
3e43c6c
 
dc60f58
3e43c6c
 
 
 
 
 
 
 
 
 
 
 
 
be66a8a
 
dc60f58
 
be66a8a
 
 
 
 
 
 
 
 
 
3e43c6c
 
 
dc60f58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239


import streamlit as st
import pandas as pd
import plotly.express as px
import random
import uuid
import os
from datetime import datetime
from streamlit_flow import streamlit_flow
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
from streamlit_flow.layouts import TreeLayout, RadialLayout

# Set page configuration to wide mode
Site_Name = '๐ŸฆCatRider๐Ÿˆ'
title = "๐ŸฆCatRider๐Ÿˆby๐Ÿ‘คAaron Wacker"
helpURL = 'https://huggingface.co/awacke1'
bugURL = 'https://huggingface.co/spaces/awacke1'
icons = '๐Ÿฆ'

useConfig = True
if useConfig:
    st.set_page_config(
        page_title=title,
        page_icon=icons,
        layout="wide",
        initial_sidebar_state="auto",
        menu_items={
            'Get Help': helpURL,
            'Report a bug': bugURL,
            'About': title
        }
    )


# ๐Ÿฑ Cat Rider and Gear Data
CAT_RIDERS = [
    {"name": "Whiskers", "type": "Speed", "emoji": "๐Ÿพ", "strength": 3, "skill": 7},
    {"name": "Fluffy", "type": "Bravery", "emoji": "๐Ÿฆ", "strength": 5, "skill": 5},
    {"name": "Midnight", "type": "Stealth", "emoji": "๐ŸŒ‘", "strength": 4, "skill": 6},
    {"name": "Bella", "type": "Charm", "emoji": "๐Ÿ˜บ", "strength": 2, "skill": 8},
    {"name": "Shadow", "type": "Mystery", "emoji": "๐Ÿ‘ค", "strength": 4, "skill": 6},
    {"name": "Simba", "type": "Royalty", "emoji": "๐Ÿฆ", "strength": 5, "skill": 7},
    {"name": "Luna", "type": "Magic", "emoji": "๐ŸŒ™", "strength": 3, "skill": 8},
    {"name": "Leo", "type": "Courage", "emoji": "๐Ÿฏ", "strength": 6, "skill": 5},
    {"name": "Milo", "type": "Playful", "emoji": "๐Ÿ˜ผ", "strength": 4, "skill": 7},
    {"name": "Nala", "type": "Grace", "emoji": "๐Ÿˆ", "strength": 5, "skill": 6}
]

RIDING_GEAR = [
    {"name": "Feathered Boots", "type": "Agility", "strength": 2},
    {"name": "Golden Armor", "type": "Defense", "strength": 4},
    {"name": "Magic Whisker Wand", "type": "Magic", "strength": 3},
    {"name": "Sleek Shadow Cape", "type": "Stealth", "strength": 1}
]

# ๐ŸŒ Game World Data (Expanded to 10 Situations)
SITUATIONS = [
    {"id": "feline_escape", "name": "The Great Feline Escape", "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! ๐Ÿš๏ธ", "emoji": "๐Ÿšช", "type": "escape", "preferred_action": "agility"},
    {"id": "lost_temple", "name": "The Treasure of the Lost Temple", "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! ๐Ÿ‘ป", "emoji": "๐Ÿ›๏ธ", "type": "exploration", "preferred_action": "resourcefulness"},
    {"id": "royal_tournament", "name": "The Royal Tournament", "description": "Compete in a grand tournament where the finest cat riders showcase their skills and bravery to earn the title of the Royal Rider. Prepare for a showdown with noble feline adversaries! ๐Ÿฑ", "emoji": "๐Ÿ‘‘", "type": "competition", "preferred_action": "bravery"},
    {"id": "sky_race", "name": "The Sky Race", "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! ๐ŸŒฉ๏ธ", "emoji": "โ˜๏ธ", "type": "competition", "preferred_action": "agility"},
    {"id": "cheese_heist", "name": "The Great Cheese Heist", "description": "Your cat rider must sneak into the royal pantry to steal the legendary Cheese of Destiny. Beware โ€“ the palace mice are guarding it! ๐Ÿง€", "emoji": "๐Ÿง€", "type": "heist", "preferred_action": "stealth"},
    {"id": "pirate_cove", "name": "The Pirate Cove", "description": "Sail the high seas with your trusty crew of cats and uncover the secrets of Pirate Cove. Beware of the treacherous Sea Dogs! ๐Ÿดโ€โ˜ ๏ธ", "emoji": "๐Ÿดโ€โ˜ ๏ธ", "type": "exploration", "preferred_action": "bravery"},
    {"id": "feline_moon_mission", "name": "The Feline Moon Mission", "description": "Blast off into space! Your mission is to plant the flag of Catopia on the moon. Pilot your rocket through an asteroid field! ๐Ÿš€", "emoji": "๐ŸŒ•", "type": "exploration", "preferred_action": "resourcefulness"},
    {"id": "purr_summit", "name": "The Purr Summit", "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! ๐Ÿง ", "emoji": "๐Ÿ“œ", "type": "debate", "preferred_action": "insight"},
    {"id": "feline_invasion", "name": "The Feline Invasion", "description": "Aliens have invaded Earth and only your cat rider can save the planet! Use cunning strategies to repel the invaders! ๐Ÿ‘ฝ", "emoji": "๐Ÿ‘ฝ", "type": "battle", "preferred_action": "strategy"},
    {"id": "eternal_catnap", "name": "The Eternal Catnap", "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? ๐Ÿ›๏ธ", "emoji": "๐Ÿ’ค", "type": "exploration", "preferred_action": "stealth"}
]

# ๐Ÿง  Expanded Actions (10 Actions)
ACTIONS = [
    {"id": "stealth", "name": "Use Stealth", "description": "Sneak past obstacles or enemies without being detected. You're like a ninja in the shadows! ๐Ÿพ", "emoji": "๐Ÿคซ", "type": "skill"},
    {"id": "agility", "name": "Showcase Agility", "description": "Perform impressive acrobatic maneuvers to overcome challenges. Cats always land on their feet, right? ๐Ÿƒ", "emoji": "๐Ÿƒ", "type": "physical"},
    {"id": "charm", "name": "Charm Others", "description": "Use your cat's natural charisma to win over allies or distract foes. Who could resist those cute eyes? ๐Ÿ˜ป", "emoji": "๐Ÿ˜ป", "type": "social"},
    {"id": "resourcefulness", "name": "Be Resourceful", "description": "Utilize the environment or items in creative ways to solve problems. Think on your paws! ๐Ÿง ", "emoji": "๐Ÿง ", "type": "mental"},
    {"id": "bravery", "name": "Show Bravery", "description": "Face dangers head-on with your feline courage. Not all heroes wear capes โ€“ some wear fur! ๐Ÿฆ", "emoji": "๐Ÿฆ", "type": "physical"},
    {"id": "strategy", "name": "Develop a Strategy", "description": "Use tactical thinking to outsmart opponents and gain the upper hand in battle. Brains over brawn! ๐Ÿง ", "emoji": "๐Ÿง ", "type": "mental"},
    {"id": "speed", "name": "Sprint Away", "description": "Run faster than you've ever run before to escape danger. Like a cat fleeing a vacuum cleaner! ๐Ÿƒโ€โ™€๏ธ", "emoji": "๐Ÿƒโ€โ™€๏ธ", "type": "physical"},
    {"id": "insight", "name": "Use Insight", "description": "Tap into ancient feline wisdom to solve puzzles and mysteries. A cat always knows! ๐Ÿ”ฎ", "emoji": "๐Ÿ”ฎ", "type": "mental"},
    {"id": "distraction", "name": "Create a Distraction", "description": "Use cunning tricks and diversions to draw attention away from your real goal. Look over there! ๐Ÿช„", "emoji": "๐Ÿช„", "type": "mental"},
    {"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"}
]


SUCCESS_CONCLUSIONS = ["Your swift paws led you to victory! ๐ŸŽ‰"]
FAILURE_CONCLUSIONS = ["You tried your best, but it just wasnโ€™t enough. ๐Ÿ˜ฟ"]

# Function to save history to a markdown file
def save_history_to_file(history_df, user_id):
    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    filename = f"history_{user_id}_{timestamp}.md"
    markdown = create_markdown_preview(history_df)
    with open(filename, 'w', encoding='utf-8') as f:
        f.write(markdown)
    return filename

# Function to load saved histories
def load_saved_histories():
    history_files = [f for f in os.listdir('.') if f.startswith('history_') and f.endswith('.md')]
    return history_files

# Generate a random situation
def generate_situation():
    return random.choice(SITUATIONS)

# Generate random actions
def generate_actions():
    return random.sample(ACTIONS, min(3, len(ACTIONS)))

# Evaluate the chosen action
def evaluate_action(situation, action, gear_strength, rider_skill, history):
    base_success_chance = 50
    stat_modifier = (gear_strength + rider_skill - 10) * 2
    success_chance = base_success_chance + stat_modifier
    if action['id'] == situation['preferred_action']:
        success_chance += 10
    success_chance = max(5, min(95, success_chance))
    outcome = random.randint(1, 100) <= success_chance
    return outcome, success_chance

# Update character stats based on outcome
def update_character_stats(game_state, outcome):
    if outcome:
        game_state['rider_skill'] += 0.5
        game_state['gear_strength'] += 0.2
    else:
        game_state['rider_skill'] = max(1, game_state['rider_skill'] - 0.3)
        game_state['gear_strength'] = max(1, game_state['gear_strength'] - 0.1)
    return game_state

# Create markdown preview of history
def create_markdown_preview(history_df):
    markdown = "## ๐ŸŒณ Journey Preview\n\n"
    grouped = history_df.groupby(['situation_name'], sort=False)
    for situation_name, group in grouped:
        markdown += f"### {group.iloc[0]['situation_emoji']} **{situation_name}**\n"
        for _, row in group.iterrows():
            outcome_str = 'โœ… Success' if row['outcome'] else 'โŒ Failure'
            stars = 'โญ' * int(row['score'])
            markdown += f"- Attempt {row['attempt']}: {row['action_emoji']} **{row['action_name']}**: {outcome_str} {stars}\n"
            markdown += f"  - {row['conclusion']}\n"
        markdown += "\n"
    return markdown

# Create knowledge graph with markdown support in nodes
def create_knowledge_graph(history_df):
    nodes = []
    edges = []
    node_ids = {}
    for index, row in history_df.iterrows():
        situation_node_id = f"situation_{row['situation_id']}"
        action_node_id = f"action_{index}"

        # Situation node with markdown content
        if situation_node_id not in node_ids:
            situation_node = StreamlitFlowNode(
                id=situation_node_id,
                pos=(0, 0),
                data={'content': f"### {row['situation_emoji']} {row['situation_name']}\n\n{row['description']}"},
                type='default',
                shape='ellipse',
                width=300
            )
            nodes.append(situation_node)
            node_ids[situation_node_id] = situation_node_id

        # Attempt node (action and outcome) with markdown content
        outcome_content = 'โœ… **Success**' if row['outcome'] else 'โŒ **Failure**'
        stars = 'โญ' * int(row['score'])
        attempt_node_content = f"""
#### {row['action_emoji']} {row['action_name']} ({outcome_content})

**Conclusion:** {row['conclusion']}

**Score:** {stars}

**Gear Strength:** {row['gear_strength']:.2f} | **Rider Skill:** {row['rider_skill']:.2f}
"""
        attempt_node = StreamlitFlowNode(
            id=action_node_id,
            pos=(0, 0),
            data={'content': attempt_node_content},
            type='default',
            shape='rectangle',
            width=300
        )
        nodes.append(attempt_node)

        # Edge from situation to attempt
        edges.append(StreamlitFlowEdge(
            id=f"edge_{situation_node_id}_{action_node_id}",
            source=situation_node_id,
            target=action_node_id,
            animated=True
        ))

    return nodes, edges

# Main game application
def main():
    st.title("๐Ÿฑ Cat Rider ๐Ÿ‡")

    # Initialize game state
    if 'game_state' not in st.session_state:
        st.session_state.game_state = {
            'user_id': str(uuid.uuid4()),
            'score': 0,
            'history': {},
            'gear_strength': 0,
            'rider_skill': 0,
            'cat_rider': None,
            'riding_gear': None,
            'history_df': pd.DataFrame(columns=['user_id', 'timestamp', 'situation_id', 'situation_name', 'situation_emoji', 'situation_type', 'attempt', 'action_id', 'action_name', 'action_emoji', 'action_type', 'outcome', 'conclusion', 'gear_strength', 'rider_skill', 'score']),
            'current_situation': None,
            'current_attempt': 1,
            'actions': [],
            'succeeded': False
        }

    # Game logic...

    game_state = st.session_state.game_state

    # ๐ŸŒณ Display Knowledge Journey Graph
    if not game_state['history_df'].empty:
        nodes, edges = create_knowledge_graph(game_state['history_df'])
        try:
            streamlit_flow('cat_rider_flow', nodes, edges, layout=TreeLayout(direction='down'), fit_view=True, height=600)
        except Exception as e:
            st.error(f"An error occurred while rendering the journey graph: {str(e)}")
            st.markdown("Please try refreshing the page if the graph doesn't appear.")

    # Rest of the game logic...

if __name__ == "__main__":
    main()