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

parsePgn cannot handle moves of type 1.d4 without space between move number and move #76

Open
Mercutio1243 opened this issue Feb 12, 2024 · 0 comments
Assignees

Comments

@Mercutio1243
Copy link

Mercutio1243 commented Feb 12, 2024

In pgn files, the moves might be included in a way, that the move number and the move are not separated by a space:

1.d4 Nf6 2.Nf3 d5 3.e3 Bf5 4.c4 c6 5.Nc3 e6 6.Bd3 Bxd3 7.Qxd3 Nbd7 8.b3 Bd6
9.O-O O-O 10.Bb2 Qe7 11.Rad1 Rad8 12.Rfe1 dxc4 13.bxc4 e5 14.dxe5 Nxe5 15.Nxe5 Bxe5
16.Qe2 Rxd1 17.Rxd1 Rd8 18.Rxd8+ Qxd8 19.Qd1 Qxd1+ 20.Nxd1 Bxb2 21.Nxb2 b5
22.f3 Kf8 23.Kf2 Ke7  1/2-1/2

as seen here: https://www.pgnmentor.com/files.html

In these cases, the parser incorrectly returns "1.d4" as a move instead of "d4". This seems to result from the approach of how move numbers are identified, beginning with final numRegex = RegExp(r'([0-9]+.+ )');

It seems that adding the following check can fix this:

    String move = substr.substring(0, end);
    if (move.contains(".")) {
      move = move.substring(move.indexOf('.') + 1); //Cut off move numbers from move in case move numbers are directly followed by move without space such as "1.d4" (and not "1. d4")
    }
@alexobviously alexobviously self-assigned this Feb 15, 2024
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

No branches or pull requests

2 participants