Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Portable Game Notation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Usage== PGN is structured "for easy reading and writing by human users and for easy [[parsing]] and generation by [[computer program]]s." The chess moves themselves are given in [[Algebraic notation (chess)|algebraic chess notation]] using English initials for the pieces. The [[filename extension]] is <code>.pgn</code>. There are two formats in the PGN specification, the "import" format and the "export" format. The import format describes data that may have been prepared by hand, and is intentionally lax; a program that can read PGN data should be able to handle the somewhat lax import format. The export format is rather strict and describes data prepared under program control, similar to a [[prettyprint|pretty printed]] source program reformatted by a [[compiler]]. The export format representations generated by different programs on the same computer should be exactly equivalent, byte for byte. PGN text begins with a set of "tag pairs" (a tag name and its value), followed by the "movetext" (chess moves with optional commentary). === Tag pairs === Tag pairs begin with an initial left bracket {{code|[}}, followed by the name of the tag in plain [[ASCII]] text. The tag value is enclosed in double-quotes, and the tag is then terminated with a closing right bracket {{code|]}}. A quote inside a tag value is represented by the backslash immediately followed by a quote. A backslash inside a tag value is represented by two adjacent backslashes. There are no special control codes involving escape characters, or carriage returns, and linefeeds to separate the fields, and superfluous embedded spaces are usually skipped when parsing. ==== Seven Tag Roster ==== PGN data for archival storage is required to provide seven tag pairs – together known as the "''Seven Tag Roster''". In export format, these tag pairs must appear before any other tag pairs and in this order: {{aligned table|class=wikitable |cols=2 |col1header=on |col1style=text-align:left; | Event|Name of the tournament or match event. | Site|Location of the event. This is in {{code|City, Region COUNTRY}} format, where COUNTRY is the three-letter [[List of IOC country codes|International Olympic Committee code]] for the country. An example is {{code|New York City, NY USA}}.{{pb}}Although not part of the specification, some [[online chess|online chess platforms]] will include a URL or website as the site value.<ref>For example, the PGN generated by [[lichess]] for the online match between grandmasters [https://lichess.org/GmglqIQz Pavel Smirnov and Andrew Tang (2020)] lists a URL in the site field.</ref> | Date|Starting date of the game, in {{code|YYYY.MM.DD}} form. {{code|??}} is used for unknown values. | Round|Playing round ordinal of the game within the event. | White|Player of the white pieces, in {{code|Lastname, Firstname}} format. | Black|Player of the black pieces, same format as White. | Result|Result of the game. It is recorded as White score, dash, then Black score, or {{code|*}} (other, e.g., the game is ongoing). }} ==== Optional tag pairs ==== The standard allows for other optional tag pairs. The more common ones include: {{aligned table|class=wikitable |cols=2 |col1header=on |col1style=text-align:left; | Annotator| The person providing notes to the game. | PlyCount| String value denoting the total number of half-moves played. | TimeControl| e.g. {{code|40/7200:3600}} (moves per seconds: sudden death seconds) | Time| Time the game started, in {{code|HH:MM:SS}} format, in local clock time. | Termination| Gives more details about the termination of the game. It may be {{code|abandoned}}, {{code|adjudication}} (result determined by third-party adjudication), {{code|death}}, {{code|emergency}}, {{code|normal}}, {{code|rules infraction}}, {{code|time forfeit}}, or {{code|unterminated}}. | Mode| {{code|OTB}} ([[over-the-board]]) {{code|ICS}} (Internet Chess Server) | FEN| The initial position of the [[chessboard]], in [[Forsyth–Edwards Notation]]. This is used to record partial games (starting at some initial position). It is also necessary for chess variants such as [[Chess960]], where the initial position is not always the same as traditional chess. :If a FEN tag is used, a separate tag pair {{code|SetUp}} must also appear and have its value set to {{code|1}}. }} === Movetext === [[image:SCD algebraic notation.svg|right|Chessboard notation|frame]] The movetext describes the actual moves of the game. This includes move number indicators (numbers followed by either one or three periods; one if the next move is White's move, three if the next move is Black's move) and movetext in [[Algebraic notation (chess)|Standard Algebraic Notation]] (SAN). For most moves the SAN consists of the letter abbreviation for the piece, an <code>x</code> if there is a capture, and the two-character algebraic name of the final square the piece moved to. The letter abbreviations are <code>K</code> ([[King (chess)|king]]), <code>Q</code> ([[Queen (chess)|queen]]), <code>R</code> ([[Rook (chess)|rook]]), <code>B</code> ([[Bishop (chess)|bishop]]), and <code>N</code> ([[Knight (chess)|knight]]). The [[pawn (chess)|pawn]] is given an empty abbreviation in SAN movetext, but in other contexts the abbreviation <code>P</code> is used. The algebraic name of any square is as per usual algebraic chess notation; from white's perspective, the leftmost square closest to white is <code>a1</code>, the rightmost square closest to the white is <code>h1</code>, and the rightmost (from white's perspective) square closest to black side is <code>h8</code>. In a few cases, a more detailed representation is needed to resolve ambiguity; if so, the piece's [[file (chess)|file]] letter, numerical [[rank (chess)|rank]], or the exact square is inserted after the moving piece's name (in that order of preference). Thus, <code>Nge2</code> specifies that the knight originally on the g-file moves to e2. SAN [[kingside]] [[castling]] is indicated by the sequence <code>O-O</code>; [[queenside]] castling is indicated by the sequence <code>O-O-O</code> (note that these are capital Os, not zeroes, contrary to the [[FIDE]] standard for notation).<ref>{{citation|last=Burgess|first=Graham|author-link=Graham Burgess|title=The Mammoth Book of Chess|date=2000|orig-year=1997|publisher=Carroll & Graph|isbn=0-7867-0725-9|page=517|quote=The main differences from standard Algebraic are that there is both a dot and a space after each move number, and an upper case "O" is used instead of a zero in the notation for castling.}}</ref> Pawn promotions are notated by [[append]]ing <code>=</code> to the destination square, followed by the piece the pawn is promoted to. For example: <code>e8=Q</code>. If the move is a checking move, <code>+</code> is also appended; if the move is a checkmating move, <code>#</code> is appended instead. For example: <code>e8=Q#</code>. An [[Glossary of chess#Annotation|annotator]] who wishes to suggest alternative moves to those actually played in the game may insert variations enclosed in parentheses. They may also comment on the game by inserting [[Numeric Annotation Glyphs]] (NAGs) into the movetext. Each NAG reflects a subjective impression of the move preceding the NAG or of the resultant position. If the game result is anything other than <code>*</code>, the result is repeated at the end of the movetext. === Comments === Comments are inserted by either a <code>;</code> (a comment that continues to the end of the line) or a <code>{</code> (which continues until a <code>}</code>). Comments do not nest. === Example === Here is the PGN format of the 29th game of the [[Fischer–Spassky (1992 match)|1992 match]] played in [[Federal Republic of Yugoslavia|Yugoslavia]] between [[Bobby Fischer]] and [[Boris Spassky]]: {{sxhl|2=moin| [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 {This opening is called the Ruy Lopez.} 3...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 }} === Handling chess variants === Many [[chess variant]]s can be recorded using PGN, provided the names of the pieces can be limited to one character, usually a letter and not a number. They are typically noted with a tag named "Variant" giving the name of the rules. The term "Variation" must be avoided, as that refers to the name of an opening variation. Note that traditional chess programs can only handle, at most, a few variants. [[Forsyth-Edwards Notation]] is used to record the starting position for variants (such as [[Chess960]]) which have initial positions other than the orthodox chess initial position.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)