I've been playing around with python-chess, I am loading a PGN file (A), reading the game from it. I then make a move, which creates a second updated PGN file (B). I read the last move from B and want to make that same move in A, and make a comment to that move with the date.
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)
The final PGN file shows the game as it was originally, without the move from B. The docs for board()
say that it just produces a copy and doesn't alter the actual game. What's the right way to add a move to a game?