#Does Lichess have an API where you can pass a game in uci notation and have it returned in PGN?

8 messages · Page 1 of 1 (latest)

prime trench
#

You are right, there is no such API - typically one adds a chess library to the application to do things like that.
Here's an example in Java, with an HTTP API, https://gist.github.com/tors42/cf4def84a0b4cb6f3410fce3b6e4ff94

$ curl --get --data-urlencode 'uci=e2e4 e7e5 b1c3' 'http://127.0.0.1:1234/san'
e4 e5 Nc3

$ curl --get --data-urlencode 'uci=e2e4 e7e5 b1c3' 'http://127.0.0.1:1234/fen'
rnbqkbnr/pppp1ppp/8/4p3/4P3/2N5/PPPP1PPP/R1BQKBNR b KQkq - 1 2

$ curl --get --data-urlencode 'uci=e2e4 e7e5 b1c3 g8f6 f1c4' 'http://127.0.0.1:1234/pgn'
1. e4 e5 2. Nc3 Nf6 3. Bc4 *

$ curl --get --data-urlencode 'uci=g8f6' --data-urlencode 'fen=rnbqkbnr/pppp1ppp/8/4p3/4P3/2N5/PPPP1PPP/R1BQKBNR b KQkq - 1 2' 'http://127.0.0.1:1234/pgn'
2... Nf6 *
Gist

Example HTTP Server for converting UCI to SAN, FEN and PGN - uci2pgn.jsh

spare jasper
#

Another question: Do you know of any method for compressing FEN? I created my own, which in the worst case (the longest possible FEN) weighs 12.2 bytes (rounded up to 13 bytes).

#

In case there is one that compresses it to fewer bytes, use that one.

velvet quarry
#

You might look at how endgame tablebases compress positions.

I think you could compress a standard game position to around ~160 bits? Method: each piece has 65 possible states(64 squares, or captured), and for each piece you have, you don't need to store additional positions, so something like log2(65! / (65-32)!). You would need to add bit for turn, move counts, enPassant, and such.

#

Though, 13 bytes beats this too.

prime trench
spare jasper
# velvet quarry You might look at how endgame tablebases compress positions. I think you could ...

What I would look for would be to compress this:
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", but without the last two numbers (because they are too irrelevant to see a FEN), I already made a compression method for that and I got confused, it does not weigh 12.2 bytes, it weighs 8,625 bytes (rounded to 9 bytes), the truth is I do not see a possible way to compress even more without losing important information such as who's turn it is to play, if they can castle, and if there is en passant.