js library to convert engine output to readable format

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

ccherng
Posts: 11
Joined: Thu Sep 13, 2012 3:18 am

js library to convert engine output to readable format

Post by ccherng »

Is there a javascript library that converts engine output to the typical human readable format? For example, engines might output something like

info depth 16 seldepth 25 multipv 1 score cp 21 nodes 1175401 nps 1416145 tbhits 0 time 830 pv e2e4 e7e5 g1f3 g8f6 d2d4 f6e4 d1e2 d7d5 f3e5 f8d6 b1d2 d6e5 d4e5 e4d2 c1d2 b8c6 e1c1 e8g8
info depth 17 seldepth 26 multipv 1 score cp 32 nodes 1313645 nps 1418623 tbhits 0 time 926 pv e2e4 e7e5 g1f3 b8c6 f1b5 a7a6 b5c6 d7c6 e1g1 g8f6 d2d3 f8d6 c1e3 h7h6 b1d2 e8g8 d2c4 f6g4 h2h3

And chess user interfaces might show it as something looking like

31 +0.23 17...Qh5 18.a4 Re6 19.Bxd5 Qxd5
31 +0.25 17...Re6 18.Qf1 Qh5 19.f3 Nxe3

If such a library does not exist is there any code out there that does this and how is this done?
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: js library to convert engine output to readable format

Post by hgm »

The script for the Interactive Diagram does generate SAN for the moves the user enters (e.g. http://hgm.nubati.net/variants/chess/ ) It doesn't produce fully compliant SAN, because it does not keep track of check. So occasionally it will put a disambiguator in a move that was not strictly needed, because the alternative move was illegal. And it never prints a '+' on checking moves. But if the purpose is human readability, that is not much of a problem.

To make the conversion, you need a pseudo-legal move generator, which checks how many other pieces of the same type as the moved one can move to the same square, and whether any of these have the same rank (requiring a file disambiguator), the same file (requiring a rank disambiguator), or could be resolved by either of those. If at the end everything can be solved by either of those, you use a file disambiguator. Because the Interactive Diagram can hadle arbitrary variants, the move generator might be more complex than what you are looking for.

For converting an entire PV you will also have to keep track of the position alog it, as it is not possible to generate SAN without having the position from which the move is made. The JavaScript powering the page I mentioned is at http://hgm.nubati.net/variants/betza.js .