X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=www%2Fjs%2Fhash-lookup.js;h=8fe12970bb0e5ac5f75dc8b730a3a6586fa0d882;hp=9ecca5389009227a14bef7d785af39f52a989ba3;hb=ed756fd94f3bb3e155402268c562016c842c4217;hpb=95264bb7edad2a22c3a4db6a91082389732a26c8 diff --git a/www/js/hash-lookup.js b/www/js/hash-lookup.js index 9ecca53..8fe1297 100644 --- a/www/js/hash-lookup.js +++ b/www/js/hash-lookup.js @@ -29,11 +29,11 @@ exports.handle_request = handle_request; var handle_response = function(fen, response, probe_response) { var lines = {}; - var root = translate_line(board, fen, probe_response['root'], true); + var root = translate_line(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, false); + lines[uci_move] = translate_line(board, fen, line); } var text = JSON.stringify({ @@ -49,20 +49,24 @@ var handle_response = function(fen, response, probe_response) { response.end(); } -var translate_line = function(board, fen, line, pretty_score) { +var translate_line = function(board, fen, line) { var r = {}; board.load(fen); var toplay = board.turn(); if (line['move'] && line['move']['from_sq']) { - r['pretty_move'] = board.move({ from: line['move']['from_sq'], to: line['move']['to_sq'], promotion: line['move']['promotion'] }).san; + var promo = line['move']['promotion']; + if (promo) { + r['pretty_move'] = board.move({ from: line['move']['from_sq'], to: line['move']['to_sq'], promotion: promo.toLowerCase() }).san; + } else { + r['pretty_move'] = board.move({ from: line['move']['from_sq'], to: line['move']['to_sq'] }).san; + } } else { r['pretty_move'] = ''; } r['sort_key'] = r['pretty_move']; if (!line['found']) { r['pv_pretty'] = []; - r['score_sort_key'] = -100000000; return r; } r['depth'] = line['depth']; @@ -82,54 +86,22 @@ var translate_line = function(board, fen, line, pretty_score) { } r['pv_pretty'] = pv; - // Write out the pretty score. - // TODO: mates! - var score = pretty_score ? 'Score: ' : ''; - - if (line['bound'] === 'BOUND_UPPER') { - score += '≤\u00a0'; - } else if (line['bound'] === 'BOUND_LOWER') { - score += '≥\u00a0'; - } - - var value = line['value']['score_cp']; - if (value > 0) { - score += '+' + (value / 100.0).toFixed(2); - } else if (value < 0) { - score += (value / 100.0).toFixed(2); - } else if (value == 0) { - score += '0.00'; - } else { - score += ''; + // Convert the score. + var score = null; + if (line['value']['score_type'] === 'SCORE_CP') { + score = ['cp', line['value']['score_cp']]; + } else if (line['value']['score_type'] === 'SCORE_MATE') { + score = ['m', line['value']['score_mate']]; } - r['pretty_score'] = score; - r['score_sort_key'] = score_sort_key(line['value'], toplay === 'b') * 200 + r['depth']; - - return r; -} - -var score_sort_key = function(score, invert) { - if (score['score_type'] === 'SCORE_MATE') { - var mate = score['score_mate']; - var score; - if (mate > 0) { - // Side to move mates - score = 99999 - mate; - } else { - // Side to move is getting mated (note the double negative for mate) - score = -99999 - mate; - } - if (invert) { - score = -score; + if (score) { + if (line['bound'] === 'BOUND_UPPER') { + score.push('≤'); + } else if (line['bound'] === 'BOUND_LOWER') { + score.push('≥'); } - return score; - } else if (score['score_type'] === 'SCORE_CP') { - var score = score['score_cp']; - if (invert) { - score = -score; - } - return score; } - return null; + r['score'] = score; + + return r; }