Lyte commited on
Commit
a1a0788
·
verified ·
1 Parent(s): 0b1bf5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -7,7 +7,7 @@ from typing import List
7
 
8
  model = Llama(
9
  model_path=hf_hub_download(
10
- repo_id=os.environ.get("REPO_ID", "Lyte/QuadConnect2.5-0.5B-v0.0.8b"), #"Lyte/QuadConnect2.5-0.5B-v0.0.6b"), #"Lyte/QuadConnect-Llama-1B-v0.0.7b"),#"
11
  filename=os.environ.get("MODEL_FILE", "unsloth.Q8_0.gguf"), #"quadconnect.Q8_0.gguf"),
12
  ),
13
  n_ctx=16384
@@ -102,20 +102,34 @@ 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: 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:
 
7
 
8
  model = Llama(
9
  model_path=hf_hub_download(
10
+ repo_id=os.environ.get("REPO_ID", "Lyte/QuadConnect2.5-0.5B-v0.0.9b"),#"Lyte/QuadConnect2.5-0.5B-v0.0.8b"), #"Lyte/QuadConnect2.5-0.5B-v0.0.6b"), #"Lyte/QuadConnect-Llama-1B-v0.0.7b"),#"
11
  filename=os.environ.get("MODEL_FILE", "unsloth.Q8_0.gguf"), #"quadconnect.Q8_0.gguf"),
12
  ),
13
  n_ctx=16384
 
102
  grid[row][col] = piece
103
  return grid
104
 
105
+ def get_available_positions(board_moves: List[str]) -> str:
106
+ """Returns all available positions per column after simulating gravity."""
107
+ # Initialize empty grid ('.' means empty)
108
+ grid = [['.' for _ in range(7)] for _ in range(6)]
109
+
110
+ # Place each move into the lowest available slot in its column
111
+ for i, move in enumerate(board_moves):
112
+ if not move:
113
+ continue
114
+ col = ord(move[0]) - ord('a')
115
+ for row in range(6):
116
+ if grid[row][col] == '.':
117
+ grid[row][col] = 'X' if i % 2 == 0 else 'O'
118
+ break
119
+
120
+ # For each column, list all empty positions (which will be above the placed pieces)
121
  available = []
122
  for col in range(7):
123
  col_letter = chr(ord('a') + col)
124
+ positions = []
125
  for row in range(6):
126
+ if grid[row][col] == '.':
127
+ positions.append(f"{col_letter}{row + 1}")
128
+ if positions:
129
+ available.append(f"Column {col_letter}: {', '.join(positions)}")
130
+ else:
131
+ available.append(f"Column {col_letter}: Full")
132
+
133
  return "\n ".join(available)
134
 
135
  class ConnectFour: