awacke1 commited on
Commit
81ae0d1
Β·
1 Parent(s): dfffb7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -40
app.py CHANGED
@@ -1,60 +1,104 @@
1
  import streamlit as st
2
  import random
3
- import pandas as pd
 
4
 
5
  # Cascadia Game Components
6
  habitat_tiles = ['🌲', '🏞️', '🌊', '🌡', 'πŸŒ„'] # Representing different habitats
7
  wildlife_tokens = ['🐻', 'πŸ¦…', '🐟', '🦌', '🐿️'] # Different wildlife
8
- nature_tokens = 'πŸƒ' # Nature tokens
 
9
 
10
- # Initialize game state
11
- if 'habitat_stack' not in st.session_state:
12
  st.session_state['habitat_stack'] = random.sample(habitat_tiles * 10, 50)
13
- if 'wildlife_stack' not in st.session_state:
14
  st.session_state['wildlife_stack'] = random.sample(wildlife_tokens * 10, 50)
15
- if 'player_area' not in st.session_state:
16
- st.session_state['player_area'] = {'habitat': [], 'wildlife': []}
17
- if 'nature_tokens' not in st.session_state:
18
- st.session_state['nature_tokens'] = 0
19
-
20
- # Function to draw habitat and wildlife
21
- def draw_habitat_and_wildlife():
22
- if st.session_state.habitat_stack and st.session_state.wildlife_stack:
23
- habitat = st.session_state.habitat_stack.pop()
24
- wildlife = st.session_state.wildlife_stack.pop()
25
- return habitat, wildlife
26
- else:
27
- return None, None
28
-
29
- # Display game board
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  st.title("🌲 Cascadia Lite 🌲")
31
- st.write("## Your Play Area")
32
- col1, col2 = st.columns(2)
33
- with col1:
34
- st.write("Habitat Tiles")
35
- st.write(' '.join(st.session_state.player_area['habitat']))
36
- with col2:
37
- st.write("Wildlife Tokens")
38
- st.write(' '.join(st.session_state.player_area['wildlife']))
 
 
 
39
 
40
  # Drafting phase
41
  st.write("## Drafting Phase")
42
- if st.button("Draw Habitat and Wildlife"):
43
- habitat, wildlife = draw_habitat_and_wildlife()
44
- if habitat and wildlife:
45
- st.session_state.player_area['habitat'].append(habitat)
46
- st.session_state.player_area['wildlife'].append(wildlife)
47
- st.write(f"Drawn Habitat: {habitat}, Wildlife: {wildlife}")
48
- else:
49
- st.write("No more tiles or tokens to draw!")
50
-
51
- # Scoring (Placeholder for actual scoring logic)
 
 
 
 
 
 
52
  st.write("## Scoring")
53
- st.write("Your score will be calculated here.")
 
 
54
 
55
  # End of Game (Placeholder)
56
  st.write("## End of Game")
57
- st.write("Final score and winner announcement will be displayed here.")
 
 
 
 
 
 
 
58
 
59
  # Run the Streamlit app
60
  st.write("## Game Controls")
 
1
  import streamlit as st
2
  import random
3
+ import json
4
+ import os
5
 
6
  # Cascadia Game Components
7
  habitat_tiles = ['🌲', '🏞️', '🌊', '🌡', 'πŸŒ„'] # Representing different habitats
8
  wildlife_tokens = ['🐻', 'πŸ¦…', '🐟', '🦌', '🐿️'] # Different wildlife
9
+ players = ['Player 1', 'Player 2', 'AI Player']
10
+ save_file = 'cascadia_game_state.txt'
11
 
12
+ # Initialize or load game state
13
+ def initialize_game():
14
  st.session_state['habitat_stack'] = random.sample(habitat_tiles * 10, 50)
 
15
  st.session_state['wildlife_stack'] = random.sample(wildlife_tokens * 10, 50)
16
+ st.session_state['players'] = {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 0} for player in players}
17
+ st.session_state['current_player'] = 0
18
+ st.session_state['game_history'] = []
19
+
20
+ def load_game_state():
21
+ if os.path.exists(save_file):
22
+ with open(save_file, 'r') as file:
23
+ state = json.load(file)
24
+ st.session_state.update(state)
25
+
26
+ def save_game_state():
27
+ with open(save_file, 'w') as file:
28
+ state = {key: value for key, value in st.session_state.items() if key != 'current_player'}
29
+ json.dump(state, file)
30
+
31
+ if 'habitat_stack' not in st.session_state:
32
+ load_game_state()
33
+ if 'habitat_stack' not in st.session_state:
34
+ initialize_game()
35
+
36
+ # AI Player Logic (Placeholder for AI strategy)
37
+ def ai_player_turn():
38
+ # AI logic to choose habitat and wildlife
39
+ return random.choice(habitat_tiles), random.choice(wildlife_tokens)
40
+
41
+ # Scoring Function (Placeholder for actual scoring logic)
42
+ def calculate_score(player):
43
+ # Implement scoring based on Cascadia rules
44
+ return random.randint(0, 50) # Placeholder score
45
+
46
+ # Gameplay Functions
47
+ def draw_habitat_and_wildlife(amount=1):
48
+ habitats, wildlife = [], []
49
+ for _ in range(amount):
50
+ if st.session_state.habitat_stack and st.session_state.wildlife_stack:
51
+ habitats.append(st.session_state.habitat_stack.pop())
52
+ wildlife.append(st.session_state.wildlife_stack.pop())
53
+ return habitats, wildlife
54
+
55
+ # Streamlit Interface
56
  st.title("🌲 Cascadia Lite 🌲")
57
+
58
+ # Display game board for each player
59
+ for player in players:
60
+ st.write(f"## {player}'s Play Area")
61
+ col1, col2 = st.columns(2)
62
+ with col1:
63
+ st.write("Habitat Tiles")
64
+ st.write(' '.join(st.session_state.players[player]['habitat']))
65
+ with col2:
66
+ st.write("Wildlife Tokens")
67
+ st.write(' '.join(st.session_state.players[player]['wildlife']))
68
 
69
  # Drafting phase
70
  st.write("## Drafting Phase")
71
+ current_player = players[st.session_state['current_player']]
72
+ if current_player != 'AI Player':
73
+ if st.button(f"{current_player}: Draw Habitat and Wildlife"):
74
+ habitats, wildlife = draw_habitat_and_wildlife(8) # Draw up to 8 tiles/tokens
75
+ st.session_state.players[current_player]['habitat'] += habitats
76
+ st.session_state.players[current_player]['wildlife'] += wildlife
77
+ st.write(f"{current_player} drew: {habitats}, {wildlife}")
78
+ st.session_state['current_player'] = (st.session_state['current_player'] + 1) % len(players)
79
+ else:
80
+ habitat, wildlife = ai_player_turn()
81
+ st.session_state.players['AI Player']['habitat'].append(habitat)
82
+ st.session_state.players['AI Player']['wildlife'].append(wildlife)
83
+ st.session_state['current_player'] = (st.session_state['current_player'] + 1) % len(players)
84
+ st.write(f"AI Player drew: {habitat}, {wildlife}")
85
+
86
+ # Display scoring for each player
87
  st.write("## Scoring")
88
+ for player in players:
89
+ score = calculate_score(player)
90
+ st.write(f"{player}'s score: {score}")
91
 
92
  # End of Game (Placeholder)
93
  st.write("## End of Game")
94
+ st.write("Final scores and winner announcement will be displayed here.")
95
+
96
+ # Save game state
97
+ save_game_state()
98
+
99
+ # Display game history
100
+ st.write("## Game History")
101
+ st.write('\n'.join(st.session_state['game_history']))
102
 
103
  # Run the Streamlit app
104
  st.write("## Game Controls")