I want to build a program that makes and reads PGNs. What is valid PGN? What arguments are valid in the header? What values are mandatory, what can be omitted?
Can I find somewhere rules for composing PGNs?
I want to build a program that makes and reads PGNs. What is valid PGN? What arguments are valid in the header? What values are mandatory, what can be omitted?
Can I find somewhere rules for composing PGNs?
PGN is not a rigorous file format. Everything in the wikipedia link (posted by @Ghotir) applies, but nothing is "mandatory".
The most common headers are:
But they are not mandatory. For example, you can get away by not specifying the player names.
Most chess programs only require you to define a header, but it can be anything. You have to define something because that's how chess programs parse the file - it expects the [
character.
Your PGN parser must be robust and handle invalid PGN scenarios. I personally deliver PGN softwares, and I know what I'm talking about. Common PGN errors:
The PGN (Portable Game Notation) format has its origins in a text document from 1994. It contains a specification and copious examples.
The best location to read the original text transformed into a web-optimized format is at this link. The Colophon near the beginning discusses the different iterations the original text went through before finding its way to that website.
Different PGN readers have implemented various aspects of this format and taken liberties of their own. Still, this is the closest you'll find to an official standard.