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

Create backup2.app.py

Browse files
Files changed (1) hide show
  1. backup2.app.py +105 -0
backup2.app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")
105
+ st.write("Use the buttons and controls to play the game!")