我一直在玩python-国际象棋,我正在加载一个PGN文件(A),从中读取游戏。然后,我进行了一次移动,这将创建第二个更新的PGN文件(B)。我读到了B的最后一步,并想在A中进行同样的移动,并使用日期对该移动进行注释。
last_move = new_game.end()
last_move_san = last_move.san()
old_last = game.end()
old_last_san = old_last.san()
if last_move_san != old_last_san:
game.end().board().push_san(last_move_san)
game.end().comment = datetime.strftime(tdate, "%m/%d")
f_exporter = chess.pgn.FileExporter(temp_pgn)
game.accept(f_exporter)最终的PGN文件显示了游戏的原始状态,没有来自B的移动。board()的docs说它只生成一个副本,不会改变实际的游戏。在游戏中添加一步棋的正确方法是什么?
发布于 2017-02-23 02:26:43
我终于想通了:
last_move = new_game.end()
last_move_san = last_move.san()
old_last = game.end()
old_last_san = old_last.san()
if last_move_san != old_last_san:
new_move = game.end().board().push_san(last_move_san)
game.end().add_main_variation(new_move, comment = datetime.strftime(tdate, "%m/%d"))GameNode.add_main_variation()按照我需要的方式改变了游戏。
https://stackoverflow.com/questions/42306337
复制相似问题