Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -82,7 +82,7 @@ def parse_coordinate_list(board_str: str) -> List[List[str]]:
|
|
82 |
into a 6x7 grid (list of lists) with row index 0 as the bottom.
|
83 |
"""
|
84 |
grid = [['.' for _ in range(7)] for _ in range(6)]
|
85 |
-
if not board_str.strip():
|
86 |
return grid
|
87 |
coords = board_str.split(",")
|
88 |
for coord in coords:
|
@@ -102,33 +102,21 @@ def parse_coordinate_list(board_str: str) -> List[List[str]]:
|
|
102 |
grid[row][col] = piece
|
103 |
return grid
|
104 |
|
105 |
-
def get_available_positions(
|
106 |
-
"""
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
for move in board_moves:
|
112 |
-
if len(move) >= 2:
|
113 |
-
col = ord(move[0]) - ord('a')
|
114 |
-
row = int(move[1]) - 1
|
115 |
-
if 0 <= row < 6 and 0 <= col < 7:
|
116 |
-
grid[row][col] = 'X' if len(board_moves) % 2 == 1 else 'O'
|
117 |
-
|
118 |
-
# Find next available position in each column
|
119 |
available = []
|
120 |
for col in range(7):
|
121 |
col_letter = chr(ord('a') + col)
|
122 |
# Search from bottom (row 0) to top (row 5)
|
123 |
-
next_pos = None
|
124 |
for row in range(6):
|
125 |
-
if
|
126 |
-
|
127 |
break
|
128 |
-
|
129 |
-
available.append(f"{col_letter}: {next_pos}")
|
130 |
-
|
131 |
-
return "\n ".join(available) # Format with newlines and indentation
|
132 |
|
133 |
class ConnectFour:
|
134 |
def __init__(self):
|
|
|
82 |
into a 6x7 grid (list of lists) with row index 0 as the bottom.
|
83 |
"""
|
84 |
grid = [['.' for _ in range(7)] for _ in range(6)]
|
85 |
+
if not board_str.strip() or board_str == "Empty Board":
|
86 |
return grid
|
87 |
coords = board_str.split(",")
|
88 |
for coord in coords:
|
|
|
102 |
grid[row][col] = piece
|
103 |
return grid
|
104 |
|
105 |
+
def get_available_positions(board: np.ndarray) -> str:
|
106 |
+
"""
|
107 |
+
Returns the next available position (the lowest empty spot) for each column
|
108 |
+
directly from the board (a NumPy array). If a piece has been played at a1,
|
109 |
+
then the available spot in column a will be a2.
|
110 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
available = []
|
112 |
for col in range(7):
|
113 |
col_letter = chr(ord('a') + col)
|
114 |
# Search from bottom (row 0) to top (row 5)
|
|
|
115 |
for row in range(6):
|
116 |
+
if board[row][col] == 0: # Found empty spot
|
117 |
+
available.append(f"{col_letter}: {col_letter}{row + 1}")
|
118 |
break
|
119 |
+
return "\n ".join(available)
|
|
|
|
|
|
|
120 |
|
121 |
class ConnectFour:
|
122 |
def __init__(self):
|