Use the prettyprinted files from the protobuf. Leave the old code in place in case...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 20 Nov 2016 21:34:35 +0000 (22:34 +0100)
committerMagne Mæhre <magne@pannekake.samfundet.no>
Sun, 20 Nov 2016 21:34:35 +0000 (22:34 +0100)
server/hash-lookup.js
server/hashprobe.proto

index dd0b0c3..3ee6bd3 100644 (file)
@@ -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;
+}
index bb34806..175cd77 100644 (file)
@@ -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 {