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

Comment e Nag #73

Open
marciusbrandao opened this issue Sep 7, 2021 · 3 comments
Open

Comment e Nag #73

marciusbrandao opened this issue Sep 7, 2021 · 3 comments

Comments

@marciusbrandao
Copy link

How do I get the comment (and Nag) of a move?

@dcolazin
Copy link
Contributor

dcolazin commented Feb 1, 2023

Comments and nags are fields of the Game class, not of the Move. The generation is not perfect (for example see the first game in cct131.pgn: the comment of white 26th move has the index 99...); working on it!

@dcolazin
Copy link
Contributor

dcolazin commented Feb 7, 2023

Hello @bhlangonijr, I studied the code in Game.loadMoveText() and I think the issue is the following: the variantIndex (and not the halfMove) is used to store comments. Given a Game object, if no variation was modified it should be possible (but messy) to retrieve the comment given the halfMove. I propose to:

  • introduce a Variation object, which is composed by:
  1. a MoveList
  2. a Map<variantIndex, comment> to store the nested comments in the variation
  3. a Map<variantIndex, variant> to store the recursive variations, as specified in the PGN standard
  4. a Map<variantIndex, nag> to store the nags of the variation
  • use a Map<halfMove, Variation> instead of the current Map<halfMove, MoveList> for variations in the Game object or have a Variation object called "mainVariation" to store the current movelist/maps that are on the Game top level

I can work on this, but as it is quite a change I want to be sure that it is desired.

@bhlangonijr
Copy link
Owner

Hello @dcolazin ,
I like your idea and it seems to me as a natural approach to it (just like navigating in a DOM object).
However, I'd like to keep half moves as a simple MoveList object as I understand that nag, commentaries and variations are in fact part of the Game data - as well as for keeping backward compatibility. Bear in mind that MoveLists can also be used while traversing a game tree in a chess engine and it'd be advisable keep it as simple and lightweight as possible. Remember as well that PGN files are sometimes huge and having a lot of nested Maps may overwhelm the memory. That being said I am good with the idea that the Variation object will be loaded on demand (loadMoveText()) and detached from the existent main line half moves object in Game.

Also note that MoveList has a parentId member that can be used though accessor methods. When loading the PGN parentId is populated with variantIndex of previous MoveList from which it branched out. This way you can navigate thorough all the variations in a recursive way. This is pretty much HACKY, but got the job done in an UI that used this library.
This is also more resource friendly.

What do you think?

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

3 participants