Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,105 +1,60 @@
|
|
1 |
import streamlit as st
|
2 |
import random
|
3 |
-
import
|
4 |
-
import os
|
5 |
|
6 |
# Cascadia Game Components
|
7 |
-
habitat_tiles = ['π²', 'ποΈ', 'π', 'π΅', 'π']
|
8 |
-
wildlife_tokens = ['π»', 'π¦
', 'π', 'π¦', 'πΏοΈ']
|
9 |
-
players = ['Player 1', 'Player 2'
|
10 |
save_file = 'cascadia_game_state.txt'
|
11 |
|
12 |
# Initialize or load game state
|
13 |
def initialize_game():
|
14 |
st.session_state['habitat_stack'] = random.sample(habitat_tiles * 10, 50)
|
15 |
st.session_state['wildlife_stack'] = random.sample(wildlife_tokens * 10, 50)
|
16 |
-
st.session_state['players'] = {player: {'habitat': [], 'wildlife': [], 'nature_tokens':
|
17 |
-
st.session_state['current_player'] = 0
|
18 |
-
st.session_state['game_history'] = []
|
19 |
-
|
20 |
-
def load_game_state():
|
21 |
-
if os.path.exists(save_file):
|
22 |
-
with open(save_file, 'r') as file:
|
23 |
-
state = json.load(file)
|
24 |
-
st.session_state.update(state)
|
25 |
-
|
26 |
-
def save_game_state():
|
27 |
-
with open(save_file, 'w') as file:
|
28 |
-
state = {key: value for key, value in st.session_state.items() if key != 'current_player'}
|
29 |
-
json.dump(state, file)
|
30 |
|
31 |
if 'habitat_stack' not in st.session_state:
|
32 |
-
|
33 |
-
if 'habitat_stack' not in st.session_state:
|
34 |
-
initialize_game()
|
35 |
-
|
36 |
-
# AI Player Logic (Placeholder for AI strategy)
|
37 |
-
def ai_player_turn():
|
38 |
-
# AI logic to choose habitat and wildlife
|
39 |
-
return random.choice(habitat_tiles), random.choice(wildlife_tokens)
|
40 |
-
|
41 |
-
# Scoring Function (Placeholder for actual scoring logic)
|
42 |
-
def calculate_score(player):
|
43 |
-
# Implement scoring based on Cascadia rules
|
44 |
-
return random.randint(0, 50) # Placeholder score
|
45 |
-
|
46 |
-
# Gameplay Functions
|
47 |
-
def draw_habitat_and_wildlife(amount=1):
|
48 |
-
habitats, wildlife = [], []
|
49 |
-
for _ in range(amount):
|
50 |
-
if st.session_state.habitat_stack and st.session_state.wildlife_stack:
|
51 |
-
habitats.append(st.session_state.habitat_stack.pop())
|
52 |
-
wildlife.append(st.session_state.wildlife_stack.pop())
|
53 |
-
return habitats, wildlife
|
54 |
|
55 |
# Streamlit Interface
|
56 |
st.title("π² Cascadia Lite π²")
|
57 |
|
58 |
-
#
|
59 |
-
|
60 |
-
st.
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
st.write(' '.join(st.session_state.players[player]['habitat']))
|
65 |
-
with col2:
|
66 |
-
st.write("Wildlife Tokens")
|
67 |
-
st.write(' '.join(st.session_state.players[player]['wildlife']))
|
68 |
-
|
69 |
-
# Drafting phase
|
70 |
-
st.write("## Drafting Phase")
|
71 |
-
current_player = players[st.session_state['current_player']]
|
72 |
-
if current_player != 'AI Player':
|
73 |
-
if st.button(f"{current_player}: Draw Habitat and Wildlife"):
|
74 |
-
habitats, wildlife = draw_habitat_and_wildlife(8) # Draw up to 8 tiles/tokens
|
75 |
-
st.session_state.players[current_player]['habitat'] += habitats
|
76 |
-
st.session_state.players[current_player]['wildlife'] += wildlife
|
77 |
-
st.write(f"{current_player} drew: {habitats}, {wildlife}")
|
78 |
-
st.session_state['current_player'] = (st.session_state['current_player'] + 1) % len(players)
|
79 |
-
else:
|
80 |
-
habitat, wildlife = ai_player_turn()
|
81 |
-
st.session_state.players['AI Player']['habitat'].append(habitat)
|
82 |
-
st.session_state.players['AI Player']['wildlife'].append(wildlife)
|
83 |
-
st.session_state['current_player'] = (st.session_state['current_player'] + 1) % len(players)
|
84 |
-
st.write(f"AI Player drew: {habitat}, {wildlife}")
|
85 |
|
86 |
-
# Display
|
87 |
-
st.write("## Scoring")
|
88 |
for player in players:
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
# Save game state
|
97 |
-
|
98 |
-
|
99 |
-
# Display game history
|
100 |
-
st.write("## Game History")
|
101 |
-
st.write('\n'.join(st.session_state['game_history']))
|
102 |
|
103 |
-
#
|
104 |
st.write("## Game Controls")
|
105 |
-
st.write("Use the buttons and
|
|
|
1 |
import streamlit as st
|
2 |
import random
|
3 |
+
import pandas as pd
|
|
|
4 |
|
5 |
# Cascadia Game Components
|
6 |
+
habitat_tiles = ['π²', 'ποΈ', 'π', 'π΅', 'π']
|
7 |
+
wildlife_tokens = ['π»', 'π¦
', 'π', 'π¦', 'πΏοΈ']
|
8 |
+
players = ['Player 1', 'Player 2']
|
9 |
save_file = 'cascadia_game_state.txt'
|
10 |
|
11 |
# Initialize or load game state
|
12 |
def initialize_game():
|
13 |
st.session_state['habitat_stack'] = random.sample(habitat_tiles * 10, 50)
|
14 |
st.session_state['wildlife_stack'] = random.sample(wildlife_tokens * 10, 50)
|
15 |
+
st.session_state['players'] = {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3} for player in players}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
if 'habitat_stack' not in st.session_state:
|
18 |
+
initialize_game()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Streamlit Interface
|
21 |
st.title("π² Cascadia Lite π²")
|
22 |
|
23 |
+
# Function to draw habitat and wildlife
|
24 |
+
def draw_habitat_and_wildlife(player):
|
25 |
+
habitat = st.session_state['habitat_stack'].pop()
|
26 |
+
wildlife = st.session_state['wildlife_stack'].pop()
|
27 |
+
st.session_state['players'][player]['habitat'].append(habitat)
|
28 |
+
st.session_state['players'][player]['wildlife'].append(wildlife)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
# Display players' areas
|
|
|
31 |
for player in players:
|
32 |
+
st.write(f"## {player}'s Play Area")
|
33 |
+
player_data = pd.DataFrame({'Habitat Tiles': st.session_state['players'][player]['habitat'],
|
34 |
+
'Wildlife Tokens': st.session_state['players'][player]['wildlife']})
|
35 |
+
st.dataframe(player_data)
|
36 |
+
|
37 |
+
# Drafting Phase
|
38 |
+
if st.button(f"{player}: Draw Habitat and Wildlife"):
|
39 |
+
draw_habitat_and_wildlife(player)
|
40 |
+
|
41 |
+
# Tile Placement
|
42 |
+
tile_placement = st.selectbox(f"{player}: Place Habitat Tile", options=['Select Position'] + list(range(1, len(st.session_state['players'][player]['habitat']) + 1)))
|
43 |
+
|
44 |
+
# Wildlife Placement
|
45 |
+
wildlife_placement = st.selectbox(f"{player}: Place Wildlife Token", options=['Select Habitat'] + list(range(1, len(st.session_state['players'][player]['wildlife']) + 1)))
|
46 |
+
|
47 |
+
# Nature Tokens
|
48 |
+
if st.session_state['players'][player]['nature_tokens'] > 0:
|
49 |
+
if st.button(f"{player}: Use a Nature Token"):
|
50 |
+
st.session_state['players'][player]['nature_tokens'] -= 1
|
51 |
+
# Logic for swapping wildlife tokens or other actions
|
52 |
+
st.write(f"{player} used a nature token. Remaining: {st.session_state['players'][player]['nature_tokens']}")
|
53 |
|
54 |
# Save game state
|
55 |
+
with open(save_file, 'w') as file:
|
56 |
+
json.dump(st.session_state, file)
|
|
|
|
|
|
|
57 |
|
58 |
+
# Game Controls and Instructions
|
59 |
st.write("## Game Controls")
|
60 |
+
st.write("Use the buttons and select boxes to play the game!")
|