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

Scanner: Add option flag to expand variations #127

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mikeb26
Copy link

@mikeb26 mikeb26 commented May 26, 2023

Note this PR depends on prior PR: #125

This series of commits adds an optional ability to expand variations when utilizing Scanner to iterate over a .pgn file. This is done by introducing an optional ScannerOpts where consumers of Scanner can specify different scanning behavior, beginning with an ExpandVariations option. When ExpandVariations==true, rather than create a single Game instance when scanning over a single game in a .pgn file, Scanner will instead create 1 Game instance per variation.

Existing moveListWithComments() contains a parsing bug when the pgn in
question contains a game with nested variations. In this case the
moveListTokenRe regex doesn't work as expected and results in attempts
to parse an illegal game. To demonstrate the problem this commit adds
a TestScannerWithNested() test case along with a 0013.pgn fixture
which is an export of a lichess study. This commit also fixes the
problem by adding a stripVariations() preprocess step in
moveListWithComments(). I have a subsequent commit coming which adds a
Scanner option to include variations in the game list when processing
a pgn.
This commit is part of a series to add an optional ability to expand
variations when utilizing Scanner to iterate over a .pgn file.

This commit specifically introduces ScannerOpts to enable consumers of
Scanner to specify different scanning behavior. The first intended use
is ScannerOpts.ExpandVariations. Currently Scanner will strip out any
variations that are present in a game defined within a .pgn file. This
new option (non-default) when specified will instead allow Scanner
consumers to specify that when iterating over a .pgn it should create
a new instance of a chess game for every variation
encountered. Additionally this commit refactors Scanner internals to
deal with the fact that decoding a single game may return a plural
number of Game instances rather than a singular. Code to actually
actually make this plural will be in a followup commit.
This commit is part of a series to add an optional ability to expand
variations when utilizing Scanner to iterate over a .pgn file.

This commit specifically implements moveListSetWithComments() when
expandVariations==true. Additionally it adds a unit test to verify
Scanner behaves as expected when ExpandVariations==true.
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