Update backup.app.py
Browse files- backup.app.py +50 -83
backup.app.py
CHANGED
@@ -1,97 +1,64 @@
|
|
1 |
import streamlit as st
|
2 |
-
import random
|
3 |
import numpy as np
|
4 |
|
5 |
-
#
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
'initialized': True
|
14 |
-
})
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
"Wizard": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Wise and powerful, connected to magical forces."},
|
22 |
-
"Witch": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Cunning, skilled in potions and spells."}
|
23 |
-
}
|
24 |
|
25 |
-
# Locations and emoji grid maps
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
#
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
#
|
33 |
directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}
|
34 |
|
35 |
-
#
|
36 |
-
def
|
37 |
-
|
38 |
-
if st.session_state.character is None:
|
39 |
-
choose_character()
|
40 |
-
else:
|
41 |
-
display_character_info()
|
42 |
-
navigate_world()
|
43 |
-
|
44 |
-
def choose_character():
|
45 |
-
st.header("Choose your character π§ββοΈπ§ββοΈ")
|
46 |
-
character = st.selectbox("Select your character", options=list(characters.keys()), format_func=lambda x: f"{x} {characters[x]['emoji']}")
|
47 |
-
if st.button("Choose"):
|
48 |
-
st.session_state.character = characters[character]
|
49 |
-
st.experimental_rerun()
|
50 |
-
|
51 |
-
def display_character_info():
|
52 |
-
char = st.session_state.character
|
53 |
-
st.subheader(f"Character: {char['description']}")
|
54 |
-
st.write(f"Knowledge: {char['knowledge']}")
|
55 |
-
if st.session_state.inventory:
|
56 |
-
st.write(f"Inventory: {', '.join(st.session_state.inventory)}")
|
57 |
-
else:
|
58 |
-
st.write("Inventory: Empty")
|
59 |
-
|
60 |
-
def navigate_world():
|
61 |
-
st.header("Explore the World")
|
62 |
-
location = st.session_state.current_location
|
63 |
-
st.write(f"You are in the {location}.")
|
64 |
-
display_map(location)
|
65 |
-
move_direction = st.selectbox("Which direction would you like to go?", options=list(directions.keys()))
|
66 |
-
if st.button("Move"):
|
67 |
-
move_player(move_direction)
|
68 |
-
handle_location_change()
|
69 |
-
|
70 |
-
def display_map(location):
|
71 |
-
map_with_player = locations[location]
|
72 |
-
map_display = "\n".join(["".join(row) for row in map_with_player])
|
73 |
-
st.text(map_display)
|
74 |
-
|
75 |
-
def move_player(direction):
|
76 |
dx, dy = directions[direction]
|
77 |
-
|
78 |
-
|
79 |
-
if 0 <= nx < 5 and 0 <= ny < 5: # Ensure new position is within bounds
|
80 |
-
# Update map position
|
81 |
-
st.session_state.map_position = (nx, ny)
|
82 |
-
# Update the character's position on the map
|
83 |
-
update_map_position(st.session_state.current_location, st.session_state.map_position)
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
# Set new position
|
89 |
-
st.session_state.map_position = new_position
|
90 |
-
locations[location][new_position] = "πΆ"
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
if __name__ == "__main__":
|
97 |
-
main()
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import numpy as np
|
3 |
|
4 |
+
# Helper functions for number theory-based emoji placement
|
5 |
+
def is_prime(n):
|
6 |
+
if n <= 1:
|
7 |
+
return False
|
8 |
+
for i in range(2, int(n**0.5) + 1):
|
9 |
+
if n % i == 0:
|
10 |
+
return False
|
11 |
+
return True
|
|
|
|
|
12 |
|
13 |
+
def fib_sequence(n):
|
14 |
+
fib_seq = [0, 1]
|
15 |
+
while fib_seq[-1] + fib_seq[-2] <= n:
|
16 |
+
fib_seq.append(fib_seq[-1] + fib_seq[-2])
|
17 |
+
return fib_seq[2:] # Exclude first two numbers for this use case
|
18 |
|
19 |
+
# Expanded set of emojis for landscape elements
|
20 |
+
emoji_set = ["π²", "π³", "π", "π²", "πΏ", "π", "π ", "π°", "πΌ", "π€οΈ", "π", "ποΈ", "π", "πΎ", "ποΈ", "ποΈ", "π", "π€οΈ", "π£οΈ", "ποΈ", "π", "β°οΈ", "π§±", "π΅", "π", "πΌ", "π»", "πΊ", "π‘", "πΊοΈ"]
|
|
|
|
|
|
|
21 |
|
22 |
+
# Locations and emoji grid maps initialization
|
23 |
+
def initialize_locations(size):
|
24 |
+
"""Initialize different locations with unique emoji grids."""
|
25 |
+
# Placeholder for location initialization logic
|
26 |
+
# Randomly fill grids with emojis from emoji_set for each location
|
27 |
+
np.random.seed(42) # Optional: for reproducible emoji distributions
|
28 |
+
locations = {
|
29 |
+
'forest edge': np.random.choice(emoji_set, (size, size)),
|
30 |
+
'deep forest': np.random.choice(emoji_set, (size, size)),
|
31 |
+
# Additional locations can be added here
|
32 |
+
}
|
33 |
+
return locations
|
34 |
|
35 |
+
# Directions for movement
|
36 |
directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}
|
37 |
|
38 |
+
# Movement and emoji map update functions
|
39 |
+
def move_emojis(locations, current_location, direction):
|
40 |
+
"""Shift emojis in the specified direction with wrap-around for the current location."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
dx, dy = directions[direction]
|
42 |
+
locations[current_location] = np.roll(locations[current_location], shift=(dx, dy), axis=(0, 1))
|
43 |
+
return locations
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
# Streamlit application setup
|
46 |
+
def main():
|
47 |
+
st.title("Explore the Emoji World")
|
|
|
|
|
|
|
48 |
|
49 |
+
size = st.sidebar.slider("Grid Size", 5, 40, 10)
|
50 |
+
if 'locations' not in st.session_state:
|
51 |
+
st.session_state.locations = initialize_locations(size)
|
52 |
+
|
53 |
+
current_location = st.sidebar.selectbox("Select location", options=list(st.session_state.locations.keys()))
|
54 |
+
emoji_map = st.session_state.locations[current_location]
|
55 |
+
map_str = "\n".join(["".join(row) for row in emoji_map])
|
56 |
+
st.text(map_str)
|
57 |
+
|
58 |
+
direction = st.sidebar.selectbox("Move direction", ["None", "North", "South", "East", "West"])
|
59 |
+
if direction != "None":
|
60 |
+
st.session_state.locations = move_emojis(st.session_state.locations, current_location, direction)
|
61 |
+
st.experimental_rerun()
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
+
main()
|