Official chess.com moveList > PGN (Help)

Sort:
paradox109

Need help converting "MoveList' notation to FEN/PGN format. 

Game: Hikaru vs Polish_fighter300

Game API: Hikaru vs Polish_fighter300

  • from API encoded moves: 
    "moveList": "lB!TkA0SgvZJowJAfo5ZegYQiyWGbs9zdk8!siXPvlzlclTJmCJ0fd6OlM3VMDZTis0UDu7Ypx47nD98knTZCKU0wE1Ldl89gp91ag!3ov2UnF7?loZ9FnOXnmY7mALEoE0LunPHAtQIvX1XyHIBsC75CRX2nB?!RC9ZBn!9tA5XAQ95QX5XCsZPgdPAd72Z76ZlsClkpgkcgpckjrAu6kukCT32HPkuEgXPT823gcUMcY3UnuLuY2UL21LC8RCJpwPr1ZMDwDuoDEJKRAKTAGrPZlPzEwoulnuLwpzyGryCrICuniLBinT0ni0RIXRJpoSKiGJCXRCDR1VNGOuwonwvnoKCOyvwofBL17DvfewgelCultgdtkd7",


    The result should look:
  • 1. d4 Nf6 2. c4 e6 3. Nf3 d5 4. g3 dxc4 5. Bg2 Nbd7 6. O-O c6 7. a4 a5 8. Nc3
    Bb4 9. Qc2 O-O 10. Na2 b6 11. Nd2 Bxd2 12. Bxd2 Nd5 13. e4 Ne7 14. Rfd1 Ba6 15.
    Bg5 h6 16. Bf4 Nf6 17. Nc3 Ng6 18. Be3 Qc7 19. h3 Rad8 20. f4 Rfe8 21. Qf2 Nd7
    22. e5 Ne7 23. g4 f5 24. Rd2 Rf8 25. Kh2 Rf7 26. Rg1 Kh7 27. Bf3 g6 28. Qh4 Rh8
    29. Rdg2 Nf8 30. Qf2 Bb7 31. Qe2 Qd8 32. Qxc4 fxg4 33. Rxg4 Nf5 34. Bf2 b5 35.
    Qd3 c5 36. Bxb7 Rxb7 37. axb5 cxd4 38. Ne4 Qb8 39. Nd6 Rg7 40. Bxd4 Rhg8 41. Ne4
    Nd7 42. Bf2 Rf8 43. Qc4 Qb7 44. Qc6 Rb8 45. Qxb7 Rxb7 46. Nc3 Nb6 47. Rd1 Nc4
    48. Rd8 Rgd7 49. Rc8 Rd2 50. Ne4 Rc2 51. Kg1 Rc1+ 52. Kh2 Rc2 53. b3 Nce3 54.
    Rxc2 Nxc2 55. Nf6+ Kg7 56. b6 Nce3 57. Rg1 Rxb6 58. Ne8+ Kh7 59. Rc1 g5 60. Rc7+
    Kg6 61. Bxe3 Nxe3 62. Rg7+ Kf5 63. Rf7+ Ke4 64. Nd6+ Kd5 65. Kg3 Rxb3 66. Rd7
    gxf4+ 67. Kxf4 Ng2+ 68. Kg4 Kxe5 69. Nc4+ Kf6 70. Nxa5 Rb6 71. Rd2 Rb4+ 72. Kg3
    Ne3 73. Rf2+ Nf5+ 74. Kh2 Ra4 75. Nb3 Re4 76. Nc5 Re3 77. Ra2 Nd4 78. Rf2+ Ke7
    79. Ra2 Kd6 80. Nb7+ Kd5 81. Kg2 e5 82. Ra5+ Ke4 83. Nd6+ Kf4 84. Nf7 h5 85. Ra6
    Rg3+ 86. Kf2 Rf3+ 87. Kg2 e4 88. Ra4 Rg3+ 89. Kf1 Nf5 90. Nd8 Kf3 91. Ke1 Rg1+
    92. Kd2 e3+ 93. Kd3 Rd1+ 94. Kc2 Rxd8

If anyone has any knowledge of what encoding system they used to convert the moves, would really appreciate it. platinum

paradox109

Short game example:

Game

API

Tricky_Dicky

Those calls are to undocumented end points and not part of the API.

The only offical way to do it would be from this endpoint: https://api.chess.com/pub/player/Hikaru/games/2022/11/pgn

 

paradox109
Tricky_Dicky wrote:

Those calls are to undocumented end points and not part of the API.

The only offical way to do it would be from this endpoint: https://api.chess.com/pub/player/Hikaru/games/2022/11/pgn

 

Well, I'm not really asking you to document API. Actually, API has nothing to do with the presented issue. The question relies on a different issue which is decoding the presented hash/notation string, whatever you want to call it, above. 

The links are just for convenience, not necessarily important.

Now I'm just guessing, but unless they did It, in their own way, it should be documented somewhere on the internet.

Tricky_Dicky

Sorry, no. Those calls are not available to anyone but staff officially and are not documented publicly as far as I am aware.

The only documented access is via the link I posted previously to my knowledge.

However it does give direct access to PGN without the need to do any conversion.

paradox109

If anyone is familiar with JavaScript and wants to help, look for generatePgn or generatePgn2 or generateFen functions inside play__stable.client.11d17de8.js

Beautified codeshare.io/DZ4exm

rhymeswithgod

Can you explain your use-case? Why do you need to interpret the moveList notation when you could just directly grab the PGN instead?

paradox109
rhymeswithgod wrote:

Can you explain your use-case? Why do you need to interpret the moveList notation when you could just directly grab the PGN instead?

Hmm, unless I missed something there is no easy way to get direct PGN without this specific API.(callback/live/game/). Also, I'm not the first person asking for direct single-game PGN API. (chess.com/clubs/forum
Feel free to inform me how to do it. 

Also now that you are here, can you please explain the 'moveList' or give some docs about the hash, how to encode/decode it and why chess.com uses it? blogs

paradox109

NVM found out how to encrypt/decrypt. wink

iSubaru

For all that need solution: moveList is encoded with TCN.

Here is encoder: https://www.npmjs.com/package/chess-tcn

Every 2 letters of moveList string represents move {"from":"tile", "to": "tile"} happy.png

paradox109

here function to decode


[JS]

var T = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?{~}(^)[_]@#$,./&-*++=";

function decode(e) {
var c, a, g = e.length, f = [];
for (c = 0; c < g; c += 2) {
    var d = {}, b = T.indexOf(e[c]);
    63 < (a = T.indexOf(e[c + 1])) && (d.promotion = "qnrbkp"[Math.floor((a - 64) / 3)], a = b + (16 > b ? -8 : 8) + (a - 1) % 3 - 1);
    75 < b ? d.drop = "qnrbkp"[b - 79] : d.from = T[b % 8] + (Math.floor(b / 8) + 1);
    d.to = T[a % 8] + (Math.floor(a / 8) + 1);
    f.push(d);
}
return f[0];
}

Can try it in the chrome console. 

Example: decode('Mc') result: {from: 'g5', to: 'c1'}

and here code in [AutoIt] + Optimised

$characters_str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?{~}(^)[_]@#$,./&-*++='
$arr_chars = StringSplit($characters_str, "", 2)
$promotion_piece = StringSplit("qnrbkp", "", 2)

Func decode($move_notation) ; decode TCN algorithm
    $move_notation_arr = StringSplit($move_notation, "", 2)
    $item_n_key = ""
    $b = StringInStr($characters_str, $move_notation_arr[0], 1, 1) - 1
    $a = StringInStr($characters_str, $move_notation_arr[0 + 1], 1, 1) - 1
    If 63 < $a Then
        $item_n_key &= "promotion" & ": '" & $promotion_piece[Floor(($a - 64) / 3)] & "', "
        $a = $b + (16 > $b ? -8 : 8) + Mod(($a - 1), 3) - 1
    EndIf
    If 75 < $b Then
        $item_n_key &= "drop" & ": '" & $promotion_piece[$b - 79] & "', "
    Else
        $item_n_key &= "from" & ": '" & $arr_chars[Mod($b, 8)] & (Floor($b / 8) + 1) & "', "
    EndIf
    $item_n_key &= "to" & ": '" & $arr_chars[Mod($a, 8)] & Floor($a / 8) + 1 & "'"
    Return $item_n_key
EndFunc   ;==>decode

NotAfraid

was looking for this. thanks guys!

tenetisagoodmovie

Hi @paradox109

Do we know what the drop property is for? That property is always blank even after a capture?

Thank you

NotAfraid

@tenetisagoodmovie drop is for variants like crazyhouse where you drop pieces from outside

tenetisagoodmovie

ah I see. Thank you!