CascadiaGen1 / backup2.app.py
awacke1's picture
Create backup2.app.py
e155c22
import streamlit as st
import random
import json
import os
# Cascadia Game Components
habitat_tiles = ['🌲', '🏞️', '🌊', '🌡', 'πŸŒ„'] # Representing different habitats
wildlife_tokens = ['🐻', 'πŸ¦…', '🐟', '🦌', '🐿️'] # Different wildlife
players = ['Player 1', 'Player 2', 'AI Player']
save_file = 'cascadia_game_state.txt'
# 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': 0} for player in players}
st.session_state['current_player'] = 0
st.session_state['game_history'] = []
def load_game_state():
if os.path.exists(save_file):
with open(save_file, 'r') as file:
state = json.load(file)
st.session_state.update(state)
def save_game_state():
with open(save_file, 'w') as file:
state = {key: value for key, value in st.session_state.items() if key != 'current_player'}
json.dump(state, file)
if 'habitat_stack' not in st.session_state:
load_game_state()
if 'habitat_stack' not in st.session_state:
initialize_game()
# AI Player Logic (Placeholder for AI strategy)
def ai_player_turn():
# AI logic to choose habitat and wildlife
return random.choice(habitat_tiles), random.choice(wildlife_tokens)
# Scoring Function (Placeholder for actual scoring logic)
def calculate_score(player):
# Implement scoring based on Cascadia rules
return random.randint(0, 50) # Placeholder score
# Gameplay Functions
def draw_habitat_and_wildlife(amount=1):
habitats, wildlife = [], []
for _ in range(amount):
if st.session_state.habitat_stack and st.session_state.wildlife_stack:
habitats.append(st.session_state.habitat_stack.pop())
wildlife.append(st.session_state.wildlife_stack.pop())
return habitats, wildlife
# Streamlit Interface
st.title("🌲 Cascadia Lite 🌲")
# Display game board for each player
for player in players:
st.write(f"## {player}'s Play Area")
col1, col2 = st.columns(2)
with col1:
st.write("Habitat Tiles")
st.write(' '.join(st.session_state.players[player]['habitat']))
with col2:
st.write("Wildlife Tokens")
st.write(' '.join(st.session_state.players[player]['wildlife']))
# Drafting phase
st.write("## Drafting Phase")
current_player = players[st.session_state['current_player']]
if current_player != 'AI Player':
if st.button(f"{current_player}: Draw Habitat and Wildlife"):
habitats, wildlife = draw_habitat_and_wildlife(8) # Draw up to 8 tiles/tokens
st.session_state.players[current_player]['habitat'] += habitats
st.session_state.players[current_player]['wildlife'] += wildlife
st.write(f"{current_player} drew: {habitats}, {wildlife}")
st.session_state['current_player'] = (st.session_state['current_player'] + 1) % len(players)
else:
habitat, wildlife = ai_player_turn()
st.session_state.players['AI Player']['habitat'].append(habitat)
st.session_state.players['AI Player']['wildlife'].append(wildlife)
st.session_state['current_player'] = (st.session_state['current_player'] + 1) % len(players)
st.write(f"AI Player drew: {habitat}, {wildlife}")
# Display scoring for each player
st.write("## Scoring")
for player in players:
score = calculate_score(player)
st.write(f"{player}'s score: {score}")
# End of Game (Placeholder)
st.write("## End of Game")
st.write("Final scores and winner announcement will be displayed here.")
# Save game state
save_game_state()
# Display game history
st.write("## Game History")
st.write('\n'.join(st.session_state['game_history']))
# Run the Streamlit app
st.write("## Game Controls")
st.write("Use the buttons and controls to play the game!")