File size: 3,958 Bytes
e155c22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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!")