-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
executable file
·80 lines (70 loc) · 1.09 KB
/
util.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import numpy as np
import chess
# https://github.com/oripress/DeepChess
pieces = {
'p': 1,
'P': -1,
'n': 2,
'N': -2,
'b': 3,
'B': -3,
'r': 4,
'R': -4,
'q': 5,
'Q': -5,
'k': 6,
'K': -6
}
def shortenString(s):
s = s[:s.rfind(" ")]
return s;
def beautifyFEN(f):
for i in range(4):
f = shortenString(f)
toMove = f[-1]
if toMove == 'w':
toMove = 7
else:
toMove = -7
f = shortenString(f)
newf = []
for char in f:
if char.isdigit():
for i in range(int(char)):
newf.append(0)
elif char != '/':
newf.append(pieces[char])
newf.append(toMove)
return newf
def make_bitboard(f):
arrs = []
result = []
s = {
'1' : 0,
'2' : 1,
'3' : 2,
'4' : 3,
'5' : 4,
'6' : 5,
'-1' : 6,
'-2' : 7,
'-3' : 8,
'-4' : 9,
'-5' : 10,
'-6' : 11,
}
for i in range(12):
arrs.append(np.zeros(64))
for i in range(64):
c = str(int(f[i]))
if c != '0':
c = int(s[c])
arrs[c][i] = 1
for i in range(12):
result.append(arrs[i])
result = list(itertools.chain.from_iterable(result))
if f[64] == -7:
result.append(1)
else:
result.append(0)
return result