I'm playing around with some python chess code, its for fun.
However i have difficulty in using the board.attackers function.
I'm not sure what it accepts
This code below makes use of the chess lib described here:
http://python-chess.readthedocs.io/en/latest/core.html
in the docs example code exists where they put in chess.F3 though i need some conversion from move to chess.xx i guess ?.
def staticAnalysis(board, move, my_color):
score = random.random()
board.push(move)
for (piece, value) in [(chess.PAWN, 1),
(chess.BISHOP, 4),
(chess.KING, 0),
(chess.QUEEN, 10),
(chess.KNIGHT, 5),
(chess.ROOK, 3)]:
score += len(board.pieces(piece, my_color)) * value
score -= len(board.pieces(piece, not my_color)) * value
score += 100 if board.is_checkmate() else 0
score += 10 if board.is_capture(move) else 0
# to get proposed destination of the move, removes piece, thus Ph1 becomes h1
square = str(move)[-2:]
# but its not accepted ?.. what can be used to do achieve this ?.
myAttackers = board.attackers(not my_color, square)
score +=len(attackers)*-2
return score