awacke1 commited on
Commit
bd783b5
·
1 Parent(s): 2c6b833

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -28
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
- # 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))
 
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))