niklasf / chessops

Chess and chess variant rules and operations in TypeScript
https://niklasf.github.io/chessops/
GNU General Public License v3.0
106 stars 34 forks source link

Support for mate eval notation starting with M #163

Closed franciscoBSalgueiro closed 7 months ago

franciscoBSalgueiro commented 8 months ago

It would be nice if the use of "M" followed by the number of moves to mate, was recognized as an alternative to the currently supported "#" notation. So things as [%eval M1] wouldn't be put into the text field.

niklasf commented 8 months ago

Do you have an example for software creating this notation, and maybe a sample PGN we can add as a test case?

franciscoBSalgueiro commented 8 months ago

The GUI that I'm developing, En Croissant, uses the M notation. Chess.com uses M when displaying engine lines in the analysis board. CuteChess has a different way of annotating evaluations but it also uses M instead of # (example: 7. Bxd1 {+M35/33 4.3s})

Example PGN:

[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "0-1"]

1. f3 e5 2. g4 {[%eval -M1]} Qh4# 0-1
niklasf commented 7 months ago

Cool project!

I am hesistating ... The comments by chess.com and CuteChess are just text, so everything goes, but [%eval ...] is aimed at being unambiguously machine-readable, so introducing another syntax seems like a mistake.

franciscoBSalgueiro commented 7 months ago

The [%eval ...] notation is also just text, it doesn't belong to the PGN standard. Since we're talking about a parser, I think it should be as lenient as possible. The output format wouldn't be changed at all.

It would be nice to eventually add support for the cutechess format too (I'm willing to make a PR for that). However, I understand if you think this is outside of the scope of this library.

niklasf commented 7 months ago

Ultimately yes, but at least [% ...] are somewhat formalized command sequences from https://www.enpassant.dk/chess/palview/enhancedpgn.htm. That document also briefly mentions but does not further specify an eval command. HIARCS, Lichess, python-chess and ChessBase(?) set the precedent for the command itself.

niklasf commented 7 months ago

Sorry, to clarify: I agree that the parser should be lenient, but I wouldn't preemptively add support for syntax variations that do not exist in real-world PGNs.

And that would only happen if programs like En Croissant start using M notation in [%eval ...], which is easily avoidable, even if they use it everywhere else in the user interface.

franciscoBSalgueiro commented 7 months ago

I agree, I didn't give it much thought at the time, and I'm planning to change it to #. The intention was to keep compatibility with older versions.

However, the cutechess format is more commonly found, including in other tools like fast-chess.

niklasf commented 7 months ago

However, the cutechess format is more commonly found, including in other tools like fast-chess.

Mhh ... right. Would accept a patch to add support.

niklasf commented 7 months ago

Via #175.