Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -133,31 +133,31 @@ def game_ui():
|
|
133 |
headers = [header.strip() for header in lines[0].strip().split(',')]
|
134 |
data = [[cell.strip() for cell in line.strip().split(',')] for line in lines[1:]]
|
135 |
st.write(st.dataframe(data, columns=headers))
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
133 |
headers = [header.strip() for header in lines[0].strip().split(',')]
|
134 |
data = [[cell.strip() for cell in line.strip().split(',')] for line in lines[1:]]
|
135 |
st.write(st.dataframe(data, columns=headers))
|
136 |
+
|
137 |
+
# Load game state from file
|
138 |
+
with open('game_state.txt', 'r') as f:
|
139 |
+
game_state = eval(f.read())
|
140 |
+
|
141 |
+
# Play the game
|
142 |
+
while game_state['rounds_played'] < NUM_ROUNDS and len(game_state['player_cards']) + len(game_state['ai_cards']) == 52:
|
143 |
+
game_ui()
|
144 |
+
|
145 |
+
player_card = draw_card(game_state['player_cards'])
|
146 |
+
ai_card = draw_card(game_state['ai_cards'])
|
147 |
+
winner = determine_winner(player_card, ai_card)
|
148 |
+
|
149 |
+
if winner == 'player':
|
150 |
+
game_state['player_cards'].extend([player_card, ai_card])
|
151 |
+
game_state['player_score'] += 2
|
152 |
+
elif winner == 'ai':
|
153 |
+
game_state['ai_cards'].extend([player_card, ai_card])
|
154 |
+
game_state['ai_score'] += 2
|
155 |
+
else:
|
156 |
+
game_state['player_cards'].append(player_card)
|
157 |
+
game_state['ai_cards'].append(ai_card)
|
158 |
+
|
159 |
+
game_state['rounds_played'] += 1
|
160 |
+
|
161 |
+
# Save game state to file
|
162 |
+
with open('game_state.txt', 'w') as f:
|
163 |
+
f.write(str(game_state))
|