CascadiaGen1 / backup3.app.py
awacke1's picture
Create backup3.app.py
3b0f24d
import streamlit as st
import random
import pandas as pd
import os
# Cascadia Game Components
habitat_tiles = ['🌲', '🏞️', '🌊', '🌡', 'πŸŒ„']
wildlife_tokens = ['🐻', 'πŸ¦…', '🐟', '🦌', '🐿️']
players = ['Player 1', 'Player 2']
save_file = 'cascadia_game_state.csv'
# Initialize or load game state
def initialize_game():
st.session_state['habitat_stack'] = random.sample(habitat_tiles * 10, 50)
st.session_state['wildlife_stack'] = random.sample(wildlife_tokens * 10, 50)
st.session_state['players'] = {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3} for player in players}
def load_game_state():
if os.path.exists(save_file):
df = pd.read_csv(save_file)
for player in players:
st.session_state['players'][player] = {
'habitat': df[player + '_habitat'].dropna().tolist(),
'wildlife': df[player + '_wildlife'].dropna().tolist(),
'nature_tokens': df[player + '_nature_tokens'][0]
}
st.session_state['habitat_stack'] = df['habitat_stack'].dropna().tolist()
st.session_state['wildlife_stack'] = df['wildlife_stack'].dropna().tolist()
def save_game_state():
data = {
'habitat_stack': pd.Series(st.session_state['habitat_stack']),
'wildlife_stack': pd.Series(st.session_state['wildlife_stack'])
}
for player in players:
player_state = st.session_state['players'][player]
data[player + '_habitat'] = pd.Series(player_state['habitat'])
data[player + '_wildlife'] = pd.Series(player_state['wildlife'])
data[player + '_nature_tokens'] = pd.Series([player_state['nature_tokens']])
df = pd.DataFrame(data)
df.to_csv(save_file, index=False)
if 'players' not in st.session_state:
load_game_state()
if 'players' not in st.session_state:
initialize_game()
# Streamlit Interface
st.title("🌲 Cascadia Lite 🌲")
# Function to draw habitat and wildlife
def draw_habitat_and_wildlife(player):
habitat = st.session_state['habitat_stack'].pop()
wildlife = st.session_state['wildlife_stack'].pop()
st.session_state['players'][player]['habitat'].append(habitat)
st.session_state['players'][player]['wildlife'].append(wildlife)
# Display players' areas
for player in players:
st.write(f"## {player}'s Play Area")
player_data = pd.DataFrame({'Habitat Tiles': st.session_state['players'][player]['habitat'],
'Wildlife Tokens': st.session_state['players'][player]['wildlife']})
st.dataframe(player_data)
# Drafting Phase
if st.button(f"{player}: Draw Habitat and Wildlife"):
draw_habitat_and_wildlife(player)
# Tile Placement
tile_placement = st.selectbox(f"{player}: Place Habitat Tile", options=['Select Position'] + list(range(1, len(st.session_state['players'][player]['habitat']) + 1)))
# Wildlife Placement
wildlife_placement = st.selectbox(f"{player}: Place Wildlife Token", options=['Select Habitat'] + list(range(1, len(st.session_state['players'][player]['wildlife']) + 1)))
# Nature Tokens
if st.session_state['players'][player]['nature_tokens'] > 0:
if st.button(f"{player}: Use a Nature Token"):
st.session_state['players'][player]['nature_tokens'] -= 1
# Logic for swapping wildlife tokens or other actions
st.write(f"{player} used a nature token. Remaining: {st.session_state['players'][player]['nature_tokens']}")
# Save game state
save_game_state()
# Game Controls and Instructions
st.write("## Game Controls")
st.write("Use the buttons and select boxes to play the game!")