Lyte commited on
Commit
f1f3822
·
verified ·
1 Parent(s): 92541e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -22
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(board_moves: List[str]) -> str:
106
- """Returns the next available position (lowest empty spot) for each column."""
107
- # Initialize empty grid (. means empty)
108
- grid = [['.' for _ in range(7)] for _ in range(6)]
109
-
110
- # Fill in taken positions from the moves
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 grid[row][col] == '.': # Found empty spot
126
- next_pos = f"{col_letter}{row + 1}" # +1 because grid is 0-based
127
  break
128
- if next_pos: # Only add if column isn't full
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):