PGN

From Just Solve the File Format Problem
(Difference between revisions)
Jump to: navigation, search
(Sample files)
(Sample files)
 
(6 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
|subcat=Saved Games
 
|subcat=Saved Games
 
|extensions={{ext|pgn}}
 
|extensions={{ext|pgn}}
|mimetypes={{mimetype|application/x-chess-pgn}}
+
|mimetypes={{mimetype|application/vnd.chess-pgn}}, {{mimetype|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.
 
'''Portable Game Notation''' ('''PGN''') is a text format that stores the moves of a game of chess, along with annotations and other metadata.
 +
 +
== 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 <i>"a set of tags defined for mandatory use for archival storage of PGN data."</i> <i>"The interpretation of these tags is fixed as is the order in which they appear"</i>. 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.
 +
 +
<pre>
 +
[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
 +
</pre>
 +
 +
==== Example PRONOM signature ====
 +
 +
An example PRONOM signature may be:
 +
 +
<pre>
 +
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)
 +
</pre>
 +
 +
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.
 +
 +
* [[PGNPack]]
  
 
== Software ==
 
== Software ==
Line 11: Line 67:
  
 
== Sample files ==
 
== Sample files ==
* The games at [http://www.chessgames.com/ chessgames.com] have links to view or download PGN files
+
* The games at [http://www.chessgames.com/ chessgames.com] have links to view or download PGN files.
 +
* Games are archived and can be downloaded as PGN files at [https://chess.com chess.com].
 +
* Various tournaments can be downloaded in PGN format at the Dutch Computer Chess Network [https://www.csvn.nl/index.php/download/partijen Computerschaak - Computer Chess Network].
 +
* {{DexvertSamples|text/portableGamingNotation}}
 +
 
 +
=== 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.
 +
 
 +
* https://github.com/niklasf/python-chess/tree/master/data/pgn
 +
* https://github.com/fsmosca/chess-artist/tree/master/PGN
 +
* https://github.com/ValdemarOrn/Chess/tree/master
 +
 
 +
== Links to the PGN specification ==
 +
 
 +
* [http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm HTML rendering of the PGN spec]
 +
* [https://web.archive.org/web/20230205122425/http://www6.chessclub.com/help/PGN-spec PGN spec]
 +
* [https://opensource.apple.com/source/Chess/Chess-109.0.3/Documentation/PGN-Standard.txt.auto.html apple.com backup of the PGN spec]
 +
 
 +
== See also ==
  
== Links ==
 
 
* [[Wikipedia:Portable Game Notation|Wikipedia article]]
 
* [[Wikipedia:Portable Game Notation|Wikipedia article]]
* [http://www6.chessclub.com/help/PGN-spec PGN spec]
+
* [https://www.chessprogramming.org/Portable_Game_Notation PGN links on ChessProgramming.org]
 +
* [https://www.chess.com/terms/chess-pgn introducing to PGN at chess.com]

Latest revision as of 15:34, 30 July 2024

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

[edit] 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.

[edit] Identification

[edit] 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

[edit] 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

[edit] PGNPack

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

[edit] Software

[edit] Sample files

[edit] 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.

[edit] Links to the PGN specification

[edit] See also

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox