PGN (.pgn)

As of Version 13.3, "PGN" has been superseded by the Wolfram/Chess paclet in the Wolfram Paclet Repository.
  • Import supports PGN notation.
  • Background & Context

      • MIME Type: application/vnd.chess-pgn
      • Standard text format for storing recorded chess games, supported by every major chess platform.
      • PGN is an acronym for Portable Game Notation.
      • ASCII format.
      • Can store arbitrary game metadata.
      • Can store annotations and suggested variations for any move.
      • Standardized by Steven J. Edwards in 1994.

    Import & Export

    • Import["file.pgn"] imports a PGN file, returning a list of games and their metadata.
    • Import["file.pgn",elements] imports the specified elements.
    • See the following reference pages for full general information:
    • Importimport from a file
      CloudImportimport from a cloud object
      ImportStringimport from a string
      ImportByteArrayimport from a byte array

    Import Elements

    • General Import elements:
    • "Elements" list of elements and options available in this file
      "Rules"full list of rules for each element and option
      "Summary"a summary of the file
    • Game elements:
    • "FENStrings"a list of FEN strings for each game
      "Games"a list of game moves and metadata
      "DynamicGameSummary"an interactive summary of the game
      "PositionRenderingList"a dynamic rendering for each game
      "Metadata"a list of game metadata
      "MoveCount"number of moves per game
      "Moves"a list of moves per game
      "GameResult"final game result per game
    • Each move is a single move of one player, also known as a ply.
    • Import by default uses the "Games" element for the PGN format.
    • Game results could be "1-0", "0-1", "1/2-1/2" (draw) or "*" (unknown).
    • Annotation element:
    • "AnnotatedMoves"move annotations as well as suggested move variations
    • Overall file element:
    • "GameCount"number of games stored in the file

    Options

    • Elements that involve rendering a chessboard take the following options:
    • "BoardOrientation"Automaticon which side of the board to place white pieces
      "Icons"Automatica set of icons to use for chess pieces
      "SquareColors"Automatica list of two colors for light and dark squares
    • Elements that return chess moves take the following options:
    • "IncludeAnnotations"Automaticwhether to include move annotations
      "IncludeVariations"Automaticwhether to include move variations