我正在使用模块python-chess ( 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))
将所有游戏动作打印为字符串就好了。
任何帮助是极大的赞赏。