Skip to content

parse pgn to list #1029

Answered by MarkZH
sugizo asked this question in Q&A
Discussion options

You must be logged in to vote

The simplest thing to do is to change the for move in game.mainline_moves(): loop from

            for move in game.mainline_moves():
                board.push(move)
                move_stack = board.move_stack
                variation_san = board.root().variation_san(move_stack)

to this

            for move in game.mainline_moves():
                board.push(move)
            move_stack = board.move_stack
            variation_san = board.root().variation_san(move_stack)

In my quick tests (with relatively simple PGN files), this made reading a PGN file about 8 times faster: 128 seconds to read 1000 games before the change, 17 seconds after the change. You don't need the move_stack and

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sugizo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants