dartchess icon indicating copy to clipboard operation
dartchess copied to clipboard

Fix PGN test by differentiating single and multigame PGN parsing

Open KMK-Git opened this issue 5 months ago • 4 comments

This fixes #30 by adding another field to _PgnParser indicating whether it is parsing a single game PGN or multi game PGN. However I am marking this as draft because there is an untested scenario for multi game PGNs which will still fail.

The root cause is the following line which resets the parser and treats any empty/whitespace line as end of the game if the parser is in case _ParserState.moves.

https://github.com/lichess-org/dartchess/blob/65fad86b26618785287152e437a7c80efb94b058/lib/src/pgn.dart#L779-L779

Post the fix:

  • For single game PGNs, empty lines are ignored in case _ParserState.moves (new behaviour).
  • For multi game PGNs, empty lines are treated as end of the game in case _ParserState.moves (current behaviour). This is required for current multi game PGN test scenarios to be parsed correctly.

This will resolve the issue for single game PGNs tested by the test case, but will still continue failing for multigame PGNs. A simple example scenario which will still fail:

[Variant "Standard"] 
  
 1. e4 e5
 2. Nf3 Nc6

 3. Bb5
  
[Variant "Standard"] 1. e4 e5 2. Nf3 Nc6 3. Bb5 { comment }  

This will be parsed as three separate games due to the empty line before 3. Bb5:

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

1. e4 e5 2. Nf3 Nc6 *

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

1. Bb5 *

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

1. e4 e5 2. Nf3 Nc6 3. Bb5 { comment } *

Note that currently there are no test cases for the multigame PGN scenario described here.

@veloce My questions for you:

  1. Do we need to consider the possibility of empty whitespace lines in a multi game PGNs and find a solution to handle it as well?
  2. If we need to ignore whitespace lines, what alternative can be used to separate games in a multigame PGN? Some example test scenarios don't have headers, so the only method I can think of is move numbers (In the above scenario 3. Bb5 is obviously not the start of a new game). However move numbers seem to be completely ignored in the current parsing logic, so this might require significant changes.

KMK-Git avatar Oct 03 '24 04:10 KMK-Git