mliebelt / pgn-viewer

Simple PGN viewer with the necessary features to display chess games
GNU General Public License v3.0
155 stars 44 forks source link

Add Universal Chess Interface (UCI) protocol specifications #397

Open mnm-sys opened 1 year ago

mnm-sys commented 1 year ago

It would be nice to have all the chess related specifications in one place. Apart from SAN most chess engines commonly use UCI protocol interface to communicate to Internet Chess servers or to other chess engines.

http://wbec-ridderkerk.nl/html/UCIProtocol.html

mliebelt commented 1 year ago

What is your expectation here? Like the name of the repository denotes, this is a tool to parse PGN strings. I see some relation to UCI protocol, but how could the pgn-parser be helpful in the context of UCI? Could you describe a scenario/use case/... that explains how the pgn-parser helps in implementing the UCI protocol interface?

Or is the expectation to translate the (somehow) difficult to read and understand "specification" to something more readable? It would of course be possible to create a grammar that parses the input, and translates that to something more readable, but the value of that would be minimal (in my opinion).

mnm-sys commented 1 year ago

Generally, the chess engines communicate with each other using UCI format. Now, if I want to input a game (file.gpn) into the chess engine, the UCI engines expect the moves of a game to be formatted in long-algebraic UCI notation. You can modify your tool pgn-parser to convert a game into this UCI format. For instance, you can add a -uci flag to the command line that will output the moves of a game in a format suitable for the analyser to pass on to a UCI engine. For instance:

pgn-parser -uci -o out.pgn -i games.pgn outputs the PGN games from games.pgn to the file out.pgn, which would then be passed to the analyser.

https://www.cs.kent.ac.uk/people/staff/djb/uci-analyser/

mliebelt commented 1 year ago

Wow, that is a great specification, thank you a lot. Based on this description, it should be easy to find a way to do something like that.

Thinking more on it, I have to find the right setup. The pgn-parser knows everything about parsing games, but needs some additional knowledge how to interpret that game. For example, the following example leads to

echo "e4 e5 Nf3 Nc6" | pgn-parser -p -

[
  {
    "tags": {},
    "gameComment": null,
    "moves": [
      {
        "moveNumber": null,
        "notation": {
          "fig": null,
          "strike": null,
          "col": "e",
          "row": "4",
          "check": null,
          "promotion": null,
          "notation": "e4"
        },
        "variations": [],
        "nag": null,
        "commentDiag": null,
        "turn": "w"
      },
...

As you may notice, the start square is not contained in the notation. Only the pgn-reader then is able to interpret it the right way, and knows then what has to be spit out at the end. I will think of how to move that issue to the right place, to find then an implementation for it.

mliebelt commented 1 year ago

Sorry for moving the thing over, but the pgn-reader is more appropriate to do the job. The tasks here are: