4

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?

  • 1
    Basic rules can be found on wikipedia (en.wikipedia.org/wiki/Portable_Game_Notation) - but I don't know if there is a more "official" or more "detailed" answer. I'm also not sure how comprehensive it is on edge conditions. (All of which is why this is a comment, not an answer.) – Ghotir Jul 17 '17 at 13:56
4

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:

  • Event
  • Site
  • Date
  • Round
  • White
  • Black
  • Result

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:

  • "o", '0' in castling (e.g: "o-o", "0-0"). Correct is "O-O", but many people confuse the letters.
  • "{" instead of "["
  • "1-o" or "1-O" instead of "1-0"
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.