Skip to contents

Parse Portable Game Notation into a game object: header tags plus the sequence of moves and resulting positions.

Usage

gm_read_pgn(file, text = FALSE, call = rlang::caller_env())

Arguments

file

A path to a .pgn file, or a single character string of 'PGN' text when text = TRUE.

text

If TRUE, treat file as literal 'PGN' text rather than a path.

call

The execution environment, for error reporting. Experts only.

Value

A gm_game object.

Details

Comments ({...} and ; to end of line), numeric annotation glyphs ($1), move numbers and recursive variations ((...)) are stripped, and the remaining mainline tokens are replayed through gm_move(), so an illegal or ambiguous move is reported where it occurs. A FEN tag is honoured as the starting position.

Examples

pgn <- "1. e4 e5 2. Nf3 Nc6 *"
gm_read_pgn(pgn, text = TRUE)
#> <gm_game> — 4 half-moves, result "*"
#> 1. e4 e5 2. Nf3 Nc6 *