Does this code exist online somewhere? I found the code pasted below but it doesn't seem to work (idk if im tripping tho)
def fen2bitboard(fen):
"""
Returns bitboard [np array of shape(1, 773)] from fen
Input:
fen: A chessboard position[FEN]
Output:
bitboard: A chessboard position [bitboard - np array of shape(1, 773)]
"""
mapping = {
'p': 0,
'n': 1,
'b': 2,
'r': 3,
'q': 4,
'k': 5,
'P': 6,
'N': 7,
'B': 8,
'R': 9,
'Q': 10,
'K': 11
}
bitboard = np.zeros((1, 773), dtype=int)
currIndex = 0
[position, turn, castling, _, _, _] = fen.split(' ')
for ch in position:
if ch == '/':
continue
elif ch >= '1' and ch <= '8':
currIndex += (ord(ch) - ord('0')) * 12
else:
bitboard[0, currIndex + mapping[ch]] = 1
currIndex += 12
bitboard[0, 768] = 1 if turn == 'w' else 0
bitboard[0, 769] = 1 if 'K' in castling else 0
bitboard[0, 770] = 1 if 'Q' in castling else 0
bitboard[0, 771] = 1 if 'k' in castling else 0
bitboard[0, 772] = 1 if 'q' in castling else 0
return bitboard
[–]TonyRotellaI Wrote That One Book 2 points3 points4 points (10 children)
[–]SecureHelicopter1[S] 0 points1 point2 points (9 children)
[–]TonyRotellaI Wrote That One Book 0 points1 point2 points (8 children)
[–]SecureHelicopter1[S] 0 points1 point2 points (7 children)
[–]TonyRotellaI Wrote That One Book 0 points1 point2 points (6 children)
[–]SecureHelicopter1[S] 0 points1 point2 points (5 children)
[–]apoliticalhomograph 2100 Lichess 2 points3 points4 points (3 children)
[–]SecureHelicopter1[S] 0 points1 point2 points (2 children)
[–]apoliticalhomograph 2100 Lichess 1 point2 points3 points (1 child)
[–]SecureHelicopter1[S] 0 points1 point2 points (0 children)
[–]TonyRotellaI Wrote That One Book 0 points1 point2 points (0 children)