Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,121 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import random
|
| 3 |
-
import pandas as pd
|
| 4 |
-
import os
|
| 5 |
-
|
| 6 |
-
# Game Components
|
| 7 |
-
habitat_tiles = ['π²', 'ποΈ', 'π', 'π΅', 'π', 'π', 'π
', 'ποΈ']
|
| 8 |
-
wildlife_tokens = [
|
| 9 |
-
('π»', 'Mammal'), ('π¦
', 'Bird'), ('π', 'Fish'),
|
| 10 |
-
('π¦', 'Mammal'), ('πΏοΈ', 'Mammal'), ('π¦', 'Bird'),
|
| 11 |
-
('π¦', 'Insect'), ('π’', 'Reptile')
|
| 12 |
-
]
|
| 13 |
-
players = ['Player 1', 'Player 2']
|
| 14 |
-
save_file = 'cascadia_game_state.csv'
|
| 15 |
-
|
| 16 |
-
# Function to load game state from CSV
|
| 17 |
-
def load_game_state():
|
| 18 |
-
if os.path.exists(save_file):
|
| 19 |
-
df = pd.read_csv(save_file)
|
| 20 |
-
game_state = {
|
| 21 |
-
'habitat_stack': df['habitat_stack'].dropna().tolist(),
|
| 22 |
-
'wildlife_stack': df['wildlife_stack'].dropna().tolist(),
|
| 23 |
-
'players': {}
|
| 24 |
-
}
|
| 25 |
-
for player in players:
|
| 26 |
-
game_state['players'][player] = {
|
| 27 |
-
'habitat': df[player + '_habitat'].dropna().tolist(),
|
| 28 |
-
'wildlife': df[player + '_wildlife'].dropna().tolist(),
|
| 29 |
-
'nature_tokens': int(df[player + '_nature_tokens'][0])
|
| 30 |
-
}
|
| 31 |
-
return game_state
|
| 32 |
-
else:
|
| 33 |
-
return None
|
| 34 |
-
|
| 35 |
-
# Function to save game state to CSV
|
| 36 |
-
def save_game_state(game_state):
|
| 37 |
-
data = {
|
| 38 |
-
'habitat_stack': pd.Series(game_state['habitat_stack']),
|
| 39 |
-
'wildlife_stack': pd.Series(game_state['wildlife_stack'])
|
| 40 |
-
}
|
| 41 |
-
for player in players:
|
| 42 |
-
player_state = game_state['players'][player]
|
| 43 |
-
data[player + '_habitat'] = pd.Series(player_state['habitat'])
|
| 44 |
-
data[player + '_wildlife'] = pd.Series(player_state['wildlife'])
|
| 45 |
-
data[player + '_nature_tokens'] = pd.Series([player_state['nature_tokens']])
|
| 46 |
-
df = pd.DataFrame(data)
|
| 47 |
-
df.to_csv(save_file, index=False)
|
| 48 |
-
|
| 49 |
-
# Initialize or load game state
|
| 50 |
-
game_state = load_game_state()
|
| 51 |
-
if game_state is None:
|
| 52 |
-
game_state = {
|
| 53 |
-
'habitat_stack': random.sample(habitat_tiles * 10, 50),
|
| 54 |
-
'wildlife_stack': random.sample(wildlife_tokens * 10, 50),
|
| 55 |
-
'players': {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3} for player in players}
|
| 56 |
-
}
|
| 57 |
-
save_game_state(game_state)
|
| 58 |
-
|
| 59 |
-
# Streamlit Interface
|
| 60 |
-
st.title("π² Cascadia Lite π²")
|
| 61 |
-
|
| 62 |
-
# Function to draw habitat and wildlife
|
| 63 |
-
def draw_habitat_and_wildlife(player, game_state):
|
| 64 |
-
habitat = game_state['habitat_stack'].pop()
|
| 65 |
-
wildlife = game_state['wildlife_stack'].pop()
|
| 66 |
-
game_state['players'][player]['habitat'].append(habitat)
|
| 67 |
-
game_state['players'][player]['wildlife'].append(wildlife)
|
| 68 |
-
save_game_state(game_state)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
col1, col2 = st.columns(2)
|
| 72 |
-
|
| 73 |
-
# Display players' areas and handle actions
|
| 74 |
-
for index, player in enumerate(players):
|
| 75 |
-
with (col1 if index == 0 else col2):
|
| 76 |
-
st.write(f"## {player}'s Play Area")
|
| 77 |
-
player_data = pd.DataFrame({
|
| 78 |
-
'Habitat Tiles': game_state['players'][player]['habitat'],
|
| 79 |
-
'Wildlife Tokens': [
|
| 80 |
-
f"{emoji} ({category})" for emoji, category in
|
| 81 |
-
game_state['players'][player]['wildlife']
|
| 82 |
-
]
|
| 83 |
-
})
|
| 84 |
-
st.dataframe(player_data)
|
| 85 |
-
|
| 86 |
-
# Drafting Phase
|
| 87 |
-
if st.button(f"{player}: Draw Habitat and Wildlife"):
|
| 88 |
-
draw_habitat_and_wildlife(player, game_state)
|
| 89 |
-
game_state = load_game_state()
|
| 90 |
-
|
| 91 |
-
# Tile and Wildlife Placement
|
| 92 |
-
placement_options = ['Place Habitat', 'Place Wildlife', 'Skip']
|
| 93 |
-
placement_choice = st.selectbox(f"{player}: Choose an action", placement_options, key=f'placement_{player}')
|
| 94 |
-
if placement_choice != 'Skip':
|
| 95 |
-
st.write(f"{player} chose to {placement_choice}")
|
| 96 |
-
|
| 97 |
-
# Nature Tokens
|
| 98 |
-
nature_tokens = game_state['players'][player]['nature_tokens']
|
| 99 |
-
if st.button(f"{player}: Use a Nature Token ({nature_tokens} left)"):
|
| 100 |
-
if nature_tokens > 0:
|
| 101 |
-
# Logic to use a nature token
|
| 102 |
-
st.write(f"{player} used a Nature Token!")
|
| 103 |
-
game_state['players'][player]['nature_tokens'] -= 1
|
| 104 |
-
save_game_state(game_state)
|
| 105 |
-
else:
|
| 106 |
-
st.warning("No Nature Tokens left!")
|
| 107 |
-
|
| 108 |
-
# Reset Button
|
| 109 |
-
if st.button("Reset Game"):
|
| 110 |
-
os.remove(save_file) # Delete the save file
|
| 111 |
-
game_state = {
|
| 112 |
-
'habitat_stack': random.sample(habitat_tiles * 10, 50),
|
| 113 |
-
'wildlife_stack': random.sample(wildlife_tokens * 10, 50),
|
| 114 |
-
'players': {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3} for player in players}
|
| 115 |
-
}
|
| 116 |
-
save_game_state(game_state)
|
| 117 |
-
st.experimental_rerun()
|
| 118 |
-
|
| 119 |
-
# Game Controls and Instructions
|
| 120 |
-
st.write("## Game Controls")
|
| 121 |
-
st.write("Use the buttons and select boxes to play the game!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|