From 66ad31721419c43f68a96a30e55eea6132588fba Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 20 Nov 2016 22:34:35 +0100 Subject: [PATCH] Use the prettyprinted files from the protobuf. Leave the old code in place in case we need to switch back to it quickly. --- server/hash-lookup.js | 50 ++++++++++++++++++++++++++++++++++++++++-- server/hashprobe.proto | 2 ++ 2 files changed, 50 insertions(+), 2 deletions(-) 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; +} diff --git a/server/hashprobe.proto b/server/hashprobe.proto index bb34806..175cd77 100644 --- a/server/hashprobe.proto +++ b/server/hashprobe.proto @@ -30,6 +30,8 @@ message HashProbeMove { string from_sq = 1; // a1, a2, etc. string to_sq = 2; string promotion = 3; // Q, R, etc. + + string pretty = 4; // e.g. Rxf6+ } message HashProbeScore { enum ScoreType { -- 2.39.2