Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,10 +18,11 @@ X_LABELS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] # Labels for x-axis (a to h
|
|
18 |
Y_LABELS = [8, 7, 6, 5, 4, 3, 2, 1] # Reversed labels for y-axis (8 to 1)
|
19 |
|
20 |
# Functions
|
21 |
-
def get_grid_coordinate(pixel_x, pixel_y):
|
22 |
"""
|
23 |
Function to determine the grid coordinate of a pixel, considering a 10px border and
|
24 |
the grid where bottom-left is (a, 1) and top-left is (h, 8).
|
|
|
25 |
"""
|
26 |
# Grid settings
|
27 |
border = 10 # 10px border
|
@@ -46,17 +47,17 @@ def get_grid_coordinate(pixel_x, pixel_y):
|
|
46 |
if x_index < 0 or x_index >= len(x_labels) or y_index < 0 or y_index >= len(y_labels):
|
47 |
return "Pixel outside grid bounds"
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
-
|
|
|
52 |
|
53 |
-
# Convert row index to the correct label, with '8' at the bottom
|
54 |
-
y_labeld = y_labels[y_index] # Correct index directly maps to '8' to '1'
|
55 |
x_label = x_labels[x_index]
|
56 |
-
y_label =
|
57 |
|
58 |
return f"{x_label}{y_label}"
|
59 |
|
|
|
60 |
def predict_next_move(fen, stockfish):
|
61 |
"""
|
62 |
Predict the next move using Stockfish.
|
|
|
18 |
Y_LABELS = [8, 7, 6, 5, 4, 3, 2, 1] # Reversed labels for y-axis (8 to 1)
|
19 |
|
20 |
# Functions
|
21 |
+
def get_grid_coordinate(pixel_x, pixel_y, perspective):
|
22 |
"""
|
23 |
Function to determine the grid coordinate of a pixel, considering a 10px border and
|
24 |
the grid where bottom-left is (a, 1) and top-left is (h, 8).
|
25 |
+
The perspective argument can adjust for white ('w') or black ('b') viewpoint.
|
26 |
"""
|
27 |
# Grid settings
|
28 |
border = 10 # 10px border
|
|
|
47 |
if x_index < 0 or x_index >= len(x_labels) or y_index < 0 or y_index >= len(y_labels):
|
48 |
return "Pixel outside grid bounds"
|
49 |
|
50 |
+
# Adjust labels based on perspective
|
51 |
+
if perspective == "b":
|
52 |
+
x_labels = x_labels[::-1] # Flip x-axis for black's perspective
|
53 |
+
y_labels = y_labels[::-1] # Flip y-axis for black's perspective
|
54 |
|
|
|
|
|
55 |
x_label = x_labels[x_index]
|
56 |
+
y_label = y_labels[y_index]
|
57 |
|
58 |
return f"{x_label}{y_label}"
|
59 |
|
60 |
+
|
61 |
def predict_next_move(fen, stockfish):
|
62 |
"""
|
63 |
Predict the next move using Stockfish.
|