PGN

From Just Solve the File Format Problem
Revision as of 15:34, 30 July 2024 by Sembiance (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
File Format
Name PGN
Ontology
Extension(s) .pgn
MIME Type(s) application/vnd.chess-pgn, application/x-chess-pgn

Portable Game Notation (PGN) is a text format that stores the moves of a game of chess, along with annotations and other metadata.

Contents

PGN Formats

There are two PGN formats, the PGN Import format, and PGN Export format. The PGN import format allows for manually prepared data, and asks the reader to be flexible in how it interprets potentially inconsistent data a la Postel's law. The PGN Export Format is more concisely described, and we can see more about the export format below.

Identification

PGN Export Format

Characters are stored in the PGN export format as bytes using the ISO 8859/1 Latin-1 (ECMA-94) code set.

The PGN export format uses a specific order of tags called the Seven Tag Roster. These tags are described as "a set of tags defined for mandatory use for archival storage of PGN data." "The interpretation of these tags is fixed as is the order in which they appear". The tags are as follows:

  • Event (the name of the tournament or match event)
  • Site (the location of the event)
  • Date (the starting date of the game)
  • Round (the playing round ordinal of the game)
  • White (the player of the white pieces)
  • Black (the player of the black pieces)
  • Result (the result of the game)

A commonly cited example of the PGN format using the seven tag rotation is the 1992 match played in Yugoslavia between Bobby Fischer and Boris Spassky. This example is also described in the PGN standard.

[Event "F/S Return Match"] 
[Site "Belgrade, Serbia JUG"] 
[Date "1992.11.04"] 
[Round "29"] 
[White "Fischer, Robert J."]
[Black "Spassky, Boris V."] 
[Result "1/2-1/2"] 

1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 8. c3
O-O 9. h3 Nb8 10. d4 Nbd7 11. c4 c6 12. cxb5 axb5 13. Nc3 Bb7 14. Bg5 b4 15.
Nb1 h6 16. Bh4 c5 17. dxe5 Nxe4 18. Bxe7 Qxe7 19. exd6 Qf6 20. Nbd2 Nxd6 21.
Nc4 Nxc4 22. Bxc4 Nb6 23. Ne5 Rae8 24. Bxf7+ Rxf7 25. Nxf7 Rxe1+ 26. Qxe1 Kxf7
27. Qe3 Qg5 28. Qxg5 hxg5 29. b3 Ke6 30. a3 Kd6 31. axb4 cxb4 32. Ra5 Nd5 33.
f3 Bc8 34. Kf2 Bf5 35. Ra7 g6 36. Ra6+ Kc5 37. Ke1 Nf4 38. g3 Nxh3 39. Kd2 Kb5
40. Rd6 Kc5 41. Ra6 Nf2 42. g4 Bd3 43. Re6 1/2-1/2

Example PRONOM signature

An example PRONOM signature may be:

5B4576656E742022{0-*}225D{0-1}(0D0A|0A)5B536974652022{0-*}225D{0-1}(0D0A|0A)5B446174652022{0-*}225D{0-1}(0D0A|0A)5B526F756E642022{0-*}225D{0-1}(0D0A|0A)5B57686974652022{0-*}225D{0-1}(0D0A|0A)5B426C61636B2022{0-*}225D{0-1}(0D0A|0A)5B526573756C742022{0-*}225D{0-1}(0D0A|0A)

However, there are weaknesses with this approach described here: https://groups.google.com/g/pronom/c/OIWiXqhZqNU/m/57eP8o1aAAAJ

PGNPack

PGNPack can be used to compress PGN files and apparently have their own file format.

Software

Sample files

Other sample files

Various other samples are dotted around, e.g. on GitHub you can find sample PGN files developers have used to create PGN parsers.

Links to the PGN specification

See also

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox