Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ Board:
|
|
24 |
Strategy:
|
25 |
1. Identify taken positions, and empty positions.
|
26 |
2. Find and execute winning moves.
|
27 |
-
3. If There isn't a winning move, then block your opponent
|
28 |
4. Control the center and set up future moves.
|
29 |
|
30 |
Respond in XML:
|
@@ -207,9 +207,24 @@ class ConnectFour:
|
|
207 |
moves.append(f"{col_letter}{row_num}({piece})")
|
208 |
return ", ".join(moves) if moves else "Empty Board"
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
def format_game_state(self):
|
211 |
board_str = self.board_to_string()
|
212 |
-
|
|
|
213 |
|
214 |
# Format player and AI moves
|
215 |
player_moves_str = ", ".join(self.player_moves) if self.player_moves else ""
|
|
|
24 |
Strategy:
|
25 |
1. Identify taken positions, and empty positions.
|
26 |
2. Find and execute winning moves.
|
27 |
+
3. If There isn't a winning move, then block your opponent's potential wins.
|
28 |
4. Control the center and set up future moves.
|
29 |
|
30 |
Respond in XML:
|
|
|
207 |
moves.append(f"{col_letter}{row_num}({piece})")
|
208 |
return ", ".join(moves) if moves else "Empty Board"
|
209 |
|
210 |
+
def get_board_moves(self):
|
211 |
+
"""
|
212 |
+
Returns a list of all moves made in the game in the format 'a1', 'b2', etc.
|
213 |
+
This is used for the get_available_positions function.
|
214 |
+
"""
|
215 |
+
moves = []
|
216 |
+
for row in range(6):
|
217 |
+
for col in range(7):
|
218 |
+
if self.board[row][col] != 0:
|
219 |
+
col_letter = chr(ord('a') + col)
|
220 |
+
row_num = str(row + 1)
|
221 |
+
moves.append(f"{col_letter}{row_num}")
|
222 |
+
return moves
|
223 |
+
|
224 |
def format_game_state(self):
|
225 |
board_str = self.board_to_string()
|
226 |
+
board_moves = self.get_board_moves()
|
227 |
+
available_positions = get_available_positions(board_moves)
|
228 |
|
229 |
# Format player and AI moves
|
230 |
player_moves_str = ", ".join(self.player_moves) if self.player_moves else ""
|