-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
32 lines (22 loc) · 774 Bytes
/
utils.py
File metadata and controls
32 lines (22 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import chess
import numpy as np
def board_to_array(board):
d = {}
index = 0
a = np.array([None, None, None, None, None, None, None, None])
myboard = np.vstack((a, a, a, a, a, a, a, a))
for i, v in enumerate(chess.SQUARE_NAMES):
d[i] = v
for r in range(8):
for c in range(8):
myboard[r][c] = (
board.piece_at(chess.parse_square(d[index])).symbol()
if board.piece_at(chess.parse_square(d[index]))
else None
)
index += 1
return np.flip(myboard, axis=0)
def get_squares():
return np.flip(np.array(chess.SQUARE_NAMES).reshape((8, 8)), axis=0)
def get_square_indexes():
return np.flip(np.array(chess.SQUARES).reshape((8, 8)), axis=0)