【发布时间】:2022-06-28 06:18:34
【问题描述】:
我有以下 fen RNBK1B1R/PPPPQPPP/5N2/3pP3/4p1p1/2n2n2/ppp2p1p/r1bkqb1r b,它是由图像识别技术生成的。此分基于翻转的棋盘,黑色棋子位于底部。当我查看legal_moves 时,似乎我的棋子轨迹是向后的。有什么方法可以控制我的棋子的方向吗?
这是棋盘的图像以及合法的动作 -
快速 sn-p 打印所有合法移动 -
import chess
def legalMoves(board):
legMovesDict = {}
for lm in board.legal_moves:
src, des = lm.from_square, lm.to_square
src, des = chess.square_name(src).upper(), chess.square_name(des).upper()
if src not in legMovesDict.keys():
legMovesDict[src] = [des]
else:
if des not in legMovesDict[src]:
legMovesDict[src].append(des)
# print(src, des)
return legMovesDict
board = chess.Board('RNBK1B1R/PPPPQPPP/5N2/3pP3/4p1p1/2n2n2/ppp2p1p/r1bkqb1r b')
print(legalMoves(board))
【问题讨论】:
标签: python python-chess