I'm trying to build a chess engine by using the "python-chess"-package
My problem is that I want to add variations to games, so I used the method:
add_variation(move: chess.Move, *, comment: str = '', starting_comment: str = '', nags: Iterable[int] = []) → chess.pgn.ChildNode
If I have a game that has the moves.
1. e4 e5 2. Nf3 Nf6
Then I can do it for the first move:
pgn = io.StringIO("1. e4 e5 2. Nf3 Nf6 *")
game = chess.pgn.read_game(pgn)
board = game.board()
for move in game.mainline_moves():
board.push(move)
node0 = game.add_variation(chess.Move.from_uci("d2d4"))
node = node0.add_variation(chess.Move.from_uci("d7d5"))
node = node.add_variation(chess.Move.from_uci("g1f3"))
node2 = game.add_variation(chess.Move.from_uci("a2a4"))
print(game)
And it will show
1. e4 ( 1. d4 d5 2. Nf3 ) ( 1. a4 ) 1... e5 2. Nf3 Nf6 *
Then I have two nodes for the first move. (one that starts with the move "d4" and one that starts with the move "a4")
My problem is that I can't find a way to do it for any other moves. So e.g. what's the way to do it, if I want to add nodes to the move 2. Nf3
?