X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=server%2Fhash-lookup.js;h=3ee6bd3ad1643a1ef4ea711e34ad80604c3587ad;hp=dd0b0c3160633d643271606cd397916584a907b0;hb=66ad31721419c43f68a96a30e55eea6132588fba;hpb=19afd6bdb8c2d498dd9dd5887ea33c33185443a5 diff --git a/server/hash-lookup.js b/server/hash-lookup.js index dd0b0c3..3ee6bd3 100644 --- a/server/hash-lookup.js +++ b/server/hash-lookup.js @@ -68,11 +68,11 @@ var handle_response = function(fen, response, probe_responses) { var probe_response = reconcile_responses(probe_responses); var lines = {}; - var root = translate_line(board, fen, probe_response['root']); + var root = translate_line_use_pretty(board, fen, probe_response['root']); for (var i = 0; i < probe_response['line'].length; ++i) { var line = probe_response['line'][i]; var uci_move = line['move']['from_sq'] + line['move']['to_sq'] + line['move']['promotion']; - lines[uci_move] = translate_line(board, fen, line); + lines[uci_move] = translate_line_use_pretty(board, fen, line); } var text = JSON.stringify({ @@ -197,3 +197,49 @@ var translate_line = function(board, fen, line) { return r; } + +var translate_line_use_pretty = function(board, fen, line) { + var r = {}; + + if (line['move'] && line['move']['pretty']) { + r['move'] = line['move']['pretty'] + } else { + r['move'] = ''; + } + if (!line['found']) { + r['pv'] = []; + return r; + } + r['depth'] = line['depth']; + + // Convert the PV. + var pv = []; + if (r['move']) { + pv.push(r['move']); + } + for (var j = 0; j < line['pv'].length; ++j) { + var move = line['pv'][j]; + pv.push(move['pretty']); + } + r['pv'] = pv; + + // Convert the score. Use the static eval if no search. + var value = line['value'] || line['eval']; + var score = null; + if (value['score_type'] === 'SCORE_CP') { + score = ['cp', value['score_cp']]; + } else if (value['score_type'] === 'SCORE_MATE') { + score = ['m', value['score_mate']]; + } + if (score) { + if (line['bound'] === 'BOUND_UPPER') { + score.push('≤'); + } else if (line['bound'] === 'BOUND_LOWER') { + score.push('≥'); + } + } + + r['score'] = score; + + return r; +}