bhlangonijr / chesslib

chess library for legal move generation, FEN/PGN parsing and more
Apache License 2.0
229 stars 80 forks source link

Comment e Nag #73

Open marciusbrandao opened 3 years ago

marciusbrandao commented 3 years ago

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

dcolazin commented 1 year ago

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 commented 1 year ago

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:

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

bhlangonijr commented 1 year ago

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?