bhlangonijr / chesslib

chess library for legal move generation, FEN/PGN parsing and more
Apache License 2.0
223 stars 78 forks source link

Feature - Count the number of games in a PGN file before loading it #63

Closed liebig closed 3 years ago

liebig commented 3 years ago

A function to count the number of games in a PGN file before loading would be interesting, as this would also allow a PgnLoadListener to calculate the exact percentage of games currently processed. I will create a pull request for this implementation.

liebig commented 3 years ago

For the implementation I count all lines which start with the string "[Event " because the Event field is mandatory by PGN definition. This implementation is fast. Counting 121332 games took my PC 707ms while loading the PGN file took 18597ms.

bhlangonijr commented 3 years ago

Fixed here: https://github.com/bhlangonijr/chesslib/commit/8b167cf3749d681b459592a210016d5b3cc4011d. Should be available on version 1.3.1