Explanation
PGN, short for Portable Game Notation, is a text format for storing and exchanging chess games. A person can open it as ordinary text, while chess programs, websites, and databases can use its structure to reconstruct the game.
The two sections of a PGN game
- The tag-pair section stores bracketed information such as Event, Site, Date, Round, White, Black, and Result. Those seven tags form the basic archival roster.
- The movetext section contains move numbers, moves in , optional comments, variations, and one final result marker.
Comments normally appear inside braces. Alternative lines appear in parentheses and can contain nested variations. Compact assessments can be stored as NAGs, codes made from $ and a number. A single .pgn file may hold one game or many separated games.
PGN records a game or variation tree, not merely a snapshot of the board. If the game begins from a nonstandard position, the SetUp and headers can supply that starting position. FEN by itself describes a position, not the move history that produced it.
What PGN is not
PGN is not a protocol for an engine to think or communicate with a graphical interface. Protocols such as exchange commands between programs; PGN exchanges game records. Programs also differ in the extensions they accept, so the most portable files follow the standard structure and contain legal moves.
The final marker must be 1-0, 0-1, 1/2-1/2, or *. It must also match the Result header. The asterisk is used when the game is in progress or has no available final result.
Common confusions
PGN versus FEN
PGN stores a game and its metadata; FEN describes one starting or intermediate position.
PGN versus UCI
PGN is a game-record format; UCI is an engine communication protocol.
Sources
- 1.Portable Game Notation Specification and Implementation Guide, Steven J. Edwards
- 2.PGN parsing and writing, python-chess
