Skip to content

Chess: load a PGN to review a game - #153

Open
mvanhorn wants to merge 1 commit into
HeyPuter:mainfrom
mvanhorn:feat/chess-pgn-import
Open

mvanhorn wants to merge 1 commit into
HeyPuter:mainfrom
mvanhorn:feat/chess-pgn-import

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Oct 30, 2026 •

Copy link
Copy Markdown

Chess: load a PGN to review a game

The move list already copies and downloads a game as PGN. This adds the other direction: paste a PGN, or open a .pgn file, and step through it on the board.

What changes

  • Load a PGN sits next to copy and download on the move list. It opens a dialog: paste the game, or choose a file, then Load.
  • The first game in the dump is replayed as Pass & Play, with no clock. Player names from the PGN show on the cards. Comments, ; line comments, $1-style glyphs, and parenthetical variations are ignored. A [FEN] tag is honoured, so a game that did not start from the initial array still plays.
  • The existing review controls and arrow keys step through the loaded moves. If the PGN records a result the engine cannot see (a resignation, a draw by agreement), that result is shown on the banner without opening the game-over dialog.
  • A game in progress asks before it is replaced. An online match in progress asks before leaving.

Tests

  • The engine now accepts a SAN string (Nf3, O-O, e8Q, e2e4) as well as {from, to}.
  • parsePgn / replayPgn cover tags, glued move numbers, comments, variations, a FEN start, an illegal move, a FEN the engine will not load, and a round-trip of Scholar's mate through export then import.
  • npm test: 150 passed. npm run build succeeds.

Test plan

  • cd src/chess && npm ci && npm test && npm run build
  • New game, play a few moves, copy PGN, New game, Load that paste, step back to the start with the arrows
  • Load a .pgn file that includes {comments}, a (variation), and a result; confirm the variation is not played
  • Load a PGN with a [FEN] tag that is not the starting position
  • Load garbage text and confirm the dialog says why it failed, without touching the board

Not included

  • Only the first game in a multi-game file is loaded.
  • Variations are skipped rather than offered as a side line.
  • Descriptive notation (P-K4) is not read.

Demo

demo

Paste or open a PGN on the move list to replay it as Pass & Play, including
games that start from a FEN, then step through the moves with the existing
review controls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant