我正在使用模块python (https://python-chess.readthedocs.io/en/latest/index.html)来提取分析400万国际象棋游戏(http://caissabase.co.uk/)。
如何将游戏的所有移动加载为字符串到列表中?我的想法是能够提取有关移动的信息。例如,女王抓取对手的棋子多少次?因此,我将在每个移动字符串中搜索"Qx“。我试过这样做:
test = [] # list I wish to append moves to (as strings)
game = chess.pgn.read_game(pgn)
board = game.board()
for move in game.mainline_moves():
board.push(move)
test.append(board.san(move)) # this does not work and seems to cause the below error上面的代码会产生以下错误:
AssertionError: san() and lan() expect move to be legal or null, but got g1f3 in rnbqkbnr/pppppppp/8/8/8/5N2/PPPPPPPP/RNBQKB1R b KQkq - 1 1但是,没有test.append(board.san(move))的其余代码会将所有游戏动作打印为字符串,非常好。
任何帮助都是非常感谢的。
发布于 2021-02-04 00:50:19
board.san(move)根据当前位置给出移动的表示法(参见文档)。然而,你已经改变了立场,通过在董事会上采取行动。因此,它不承认第一个骑士移动g1f3是合法的:骑士已经在f3上了!
我怀疑如果您交换了循环中的两行,那么它应该可以工作。也就是说,你首先需要写下移动,然后使它(有点不同,你会做什么实际下棋;)
https://stackoverflow.com/questions/66037243
复制相似问题