Skip to content

How to implement all commentary

Markus Liebelt edited this page Aug 17, 2019 · 5 revisions

See the ticket #97 for the original request.

Context

  • PGN spec says: Commentary can be everywhere outside of one token. That is a bold statement.
  • There is also the line end comment, which is not done here.

Examples for regular comments

`

  • {c1} 1. {c2} e4 {c3} + {c4} ! {c5} $47 {c6}
  • 1 {c1}.{c2} e4# {c3}
  • 1. {c1} d4! {c2}
  • 1. d4 {c1} ! {c2} $17: This is unclear, if it is allowed to have a comment in between.

I found that from the 6 symbols !,!!,?,??,?!,!? only one is allowed per move. See spec chapter 8 for details.

Current implementation

The current implementation allows exactly 3 comment sections, which is not sufficient according to the spec. Those are:

  • moveComment: Starts before the move number.
  • commentBefore: Starts before the move, but after the move number.
  • commentAfter: Starts after the move.

There is the special comment for comment annotations, which are arrows and circles (in the used Chessground named board from lichess). This has to be one comment, and is normally not written by humans, but by machines.

Future implementation

The future implementation should allow comments anywhere. This will lead to the following change:

  • Parse all things, and collect them in one order.
  • Some of them are necessary like SAN for the move, and some are optional, like comments and NAGs.

So the representation should include:

  • Necessary: fig, col, row, notation (== san), variations (an array of moves)
  • Optional: disc, strike, check, moveNumber, promotion
  • In any order: NAGs, comments

To represent the exactly same, every part of the notation has to be typed, so that every instance is then able to represent itself in the output.

So the following type system would help here:

  • MoveNumber: int, may depend on the color
  • SAN: Fig Col Row (like Nf3)
  • Nag: for every nag, includes the number, with some mapping.
  • Comment: Any comment
  • CommentAnnotation: with the special role to create symbols (arrows, circles, ...) on the board.