notnil / chess

chess package for go
MIT License
517 stars 130 forks source link

Create PGN file(s) from The Week in Chess #46

Closed jmellian closed 3 years ago

jmellian commented 4 years ago

On the website The Week in Chess (https://theweekinchess.com/twic) there is an archive of PGN file. I created some functions that would create a large pgn from all or parts of the archive. If you are interested to adding to this project i can make them available to this library

notnil commented 4 years ago

This request has come up a few times so it is definitely something people are interested in. I think a streaming parser makes sense in this case. I also think the API will be more ergonomic than a limited reader. It could look something like:

f, _ := os.Open("many.pgn")
scanner := chess.NewPGNScanner(f)
for scanner.Scan() {
        game := scanner.Next()
    fmt.Println(game)
}
if err := scanner.Err(); err != nil {
    fmt.Fprintln(os.Stderr, "reading standard input:", err)
}
jmellian commented 4 years ago

I agree that this is more ergonomic way reading a large PGN file. My suggestion is however about downloading a pgn file from the The Week in Chess archive. If you download these files and concatenate the weekly pgn files you get a pgn file in size about 1 GB large. I thought something like:

twic_filename := chess.GetTwicArchiveFiles( nr_of_weeks)
//
// gives the latest <nr_of_weeks> Twic archive files concatenated to a large pgn file
// if nr_of_week is 0: take all the available archive files (now: 0920 - 1319) 
// and concatenated them all
// This create a pgn file with name: TWIC_<YYYY-MM-DD>.pgn
//
f, _ := os.Open(twic_filename)
scanner := chess.NewPGNScanner(f)
for scanner.Scan() {
    game := scanner.Next()
    fmt.Println(game)
}
if err := scanner.Err(); err != nil {
    fmt.Fprintln(os.Stderr, "reading standard input:", err)
}

}

notnil commented 4 years ago

Also I would prefer to not have "TWIC" functions in this repo. I have never heard of that and I don't want to embrace specific companies in the chess ecosystem.