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

Is there any way to write multiple comments on a move? #946

Open
olleeriksson opened this issue Dec 28, 2022 · 2 comments · May be fixed by #1068
Open

Is there any way to write multiple comments on a move? #946

olleeriksson opened this issue Dec 28, 2022 · 2 comments · May be fixed by #1068

Comments

@olleeriksson
Copy link

I'm trying to use python-chess to merge two pgn games, which is working fine. But it appears some PGN viewers really want the normal text comments and the %cal and %csl annotations separated into their own comment, like so:

  1. e4 { Here is a text comment } { [%cal Ge2e4] }

I seem to have no way to create this type of comment since the "comment" field in the GameNode class in pgn.py is a string, when I think I want it to be a list of strings. So I end up with this:

  1. e4 { Here is a text comment [%cal Ge2e4] } <--- without a closing and opening bracket between the text and annotation

I have also tried setting node.comment = f"{text} }} {{ {annotations}" , ie injecting a } and a { inside the comment but it doesn't work, and is hacky anyway. It appears to insert the { but the } never appears.

What's your take on this? Just something the library doesn't support?

@niklasf
Copy link
Owner

niklasf commented Dec 30, 2022

Hi. It's currently not really possible (except by subclassing chess.pgn.StringExporter), but I think it makes sense to add.

By the way, which PGN viewer has this requirement?

@olleeriksson
Copy link
Author

This is how Lichess.org outputs comments + annotations:

2... Nf6 { Queen's Gambit Declined - Marshall defense } { [%csl Gc4][%cal Gc4d5] }

And Chesstempo.org:
(though it's not obvious how to create these so not a lot of people are probably creating annotations here, but maybe some people import into Chesstempo and then export, in which case you also get this)

1.e4 e5 { This is a comment } {[%cal Gf2f5,Gg2g3][%csl Gb3,Yc4]}

And this NodeJS library for parsing PGN files seem to want it formatted this way too.

https://www.npmjs.com/package/pgn-parser

Check out test/test_grammer.js around line 170 for a test that tells alot.

I have sort of gotten around this by now by creating python script using your parser and a hack that inserts } { between the text part and the [% part after it is printed, but at least based on these three frameworks/sites I would guess this would be something good to support.

@MarkZH MarkZH linked a pull request Feb 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants