Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse minimal pgns #376

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

theborakompanioni
Copy link

@theborakompanioni theborakompanioni commented Feb 3, 2023

This is currently WIP.

Goal of this PR is being able to parse minimal PGNs, e.g. starting positions (without any moves made yet).
Any feedback is highly appreciated.
Q: What is the most minimal valid PGN?
From what it seems, an empty string '' is a valid PGN, as mentioned in Section 8 of the spec, hence it should be supported.

"An empty file is a valid, although somewhat uninformative, PGN database"

The second minimum input would be just a Termination Marker, e.g. simply *.

This is for example how chess.com exports the starting position:

[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]

*

In all the cases described above, the loadPgn method throws an error:

Invalid move:

      1220 |     if (!moveObj) {
      1221 |       if (typeof move === 'string') {
    > 1222 |         throw new Error(`Invalid move: ${move}`)
           |               ^
      1223 |       } else {
      1224 |         throw new Error(`Invalid move: ${JSON.stringify(move)}`)
      1225 |       }

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