Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,11 +9,6 @@ wildlife_tokens = ['π»', 'π¦
', 'π', 'π¦', 'πΏοΈ']
|
|
| 9 |
players = ['Player 1', 'Player 2']
|
| 10 |
save_file = 'cascadia_game_state.csv'
|
| 11 |
|
| 12 |
-
# Scoring Function
|
| 13 |
-
def calculate_score(habitat, wildlife):
|
| 14 |
-
# Example scoring logic: 10 points if they match, else 1 point
|
| 15 |
-
return 10 if habitat == wildlife else 1
|
| 16 |
-
|
| 17 |
# Function to load game state from CSV
|
| 18 |
def load_game_state():
|
| 19 |
if os.path.exists(save_file):
|
|
@@ -47,18 +42,16 @@ def save_game_state(game_state):
|
|
| 47 |
df = pd.DataFrame(data)
|
| 48 |
df.to_csv(save_file, index=False)
|
| 49 |
|
| 50 |
-
|
| 51 |
# Initialize or load game state
|
| 52 |
game_state = load_game_state()
|
| 53 |
if game_state is None:
|
| 54 |
game_state = {
|
| 55 |
'habitat_stack': random.sample(habitat_tiles * 10, 50),
|
| 56 |
'wildlife_stack': random.sample(wildlife_tokens * 10, 50),
|
| 57 |
-
'players': {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3
|
| 58 |
}
|
| 59 |
save_game_state(game_state)
|
| 60 |
|
| 61 |
-
|
| 62 |
# Streamlit Interface
|
| 63 |
st.title("π² Cascadia Lite π²")
|
| 64 |
|
|
@@ -68,18 +61,8 @@ def draw_habitat_and_wildlife(player, game_state):
|
|
| 68 |
wildlife = game_state['wildlife_stack'].pop()
|
| 69 |
game_state['players'][player]['habitat'].append(habitat)
|
| 70 |
game_state['players'][player]['wildlife'].append(wildlife)
|
| 71 |
-
# Calculate and update score
|
| 72 |
-
score = calculate_score(habitat, wildlife)
|
| 73 |
-
game_state['players'][player]['score'] += score
|
| 74 |
save_game_state(game_state)
|
| 75 |
|
| 76 |
-
# Function to change wildlife
|
| 77 |
-
def change_wildlife(player, game_state):
|
| 78 |
-
if game_state['players'][player]['wildlife']:
|
| 79 |
-
game_state['players'][player]['wildlife'][-1] = random.choice(wildlife_tokens)
|
| 80 |
-
save_game_state(game_state)
|
| 81 |
-
else:
|
| 82 |
-
st.warning(f"{player}, you have no wildlife to change!")
|
| 83 |
|
| 84 |
# Display players' areas and handle actions
|
| 85 |
col1, col2 = st.columns(2)
|
|
@@ -92,15 +75,11 @@ for index, player in enumerate(players):
|
|
| 92 |
})
|
| 93 |
st.dataframe(player_data)
|
| 94 |
|
| 95 |
-
#
|
| 96 |
-
st.write(f"Current Score: {game_state['players'][player]['score']}")
|
| 97 |
-
|
| 98 |
if st.button(f"{player}: Draw Habitat and Wildlife"):
|
| 99 |
draw_habitat_and_wildlife(player, game_state)
|
| 100 |
game_state = load_game_state()
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
# Tile and Wildlife Placement
|
| 105 |
placement_options = ['Place Habitat', 'Place Wildlife', 'Skip']
|
| 106 |
placement_choice = st.selectbox(f"{player}: Choose an action", placement_options, key=f'placement_{player}')
|
|
|
|
| 9 |
players = ['Player 1', 'Player 2']
|
| 10 |
save_file = 'cascadia_game_state.csv'
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Function to load game state from CSV
|
| 13 |
def load_game_state():
|
| 14 |
if os.path.exists(save_file):
|
|
|
|
| 42 |
df = pd.DataFrame(data)
|
| 43 |
df.to_csv(save_file, index=False)
|
| 44 |
|
|
|
|
| 45 |
# Initialize or load game state
|
| 46 |
game_state = load_game_state()
|
| 47 |
if game_state is None:
|
| 48 |
game_state = {
|
| 49 |
'habitat_stack': random.sample(habitat_tiles * 10, 50),
|
| 50 |
'wildlife_stack': random.sample(wildlife_tokens * 10, 50),
|
| 51 |
+
'players': {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3} for player in players}
|
| 52 |
}
|
| 53 |
save_game_state(game_state)
|
| 54 |
|
|
|
|
| 55 |
# Streamlit Interface
|
| 56 |
st.title("π² Cascadia Lite π²")
|
| 57 |
|
|
|
|
| 61 |
wildlife = game_state['wildlife_stack'].pop()
|
| 62 |
game_state['players'][player]['habitat'].append(habitat)
|
| 63 |
game_state['players'][player]['wildlife'].append(wildlife)
|
|
|
|
|
|
|
|
|
|
| 64 |
save_game_state(game_state)
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Display players' areas and handle actions
|
| 68 |
col1, col2 = st.columns(2)
|
|
|
|
| 75 |
})
|
| 76 |
st.dataframe(player_data)
|
| 77 |
|
| 78 |
+
# Drafting Phase
|
|
|
|
|
|
|
| 79 |
if st.button(f"{player}: Draw Habitat and Wildlife"):
|
| 80 |
draw_habitat_and_wildlife(player, game_state)
|
| 81 |
game_state = load_game_state()
|
| 82 |
|
|
|
|
|
|
|
| 83 |
# Tile and Wildlife Placement
|
| 84 |
placement_options = ['Place Habitat', 'Place Wildlife', 'Skip']
|
| 85 |
placement_choice = st.selectbox(f"{player}: Choose an action", placement_options, key=f'placement_{player}')
|