Deal with a world where there are no more non-pretty moves in the protobufs.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 20 Nov 2016 22:05:19 +0000 (23:05 +0100)
committerMagne Mæhre <magne@pannekake.samfundet.no>
Sun, 20 Nov 2016 22:05:19 +0000 (23:05 +0100)
server/hash-lookup.js

index 3ee6bd3..7d7daeb 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_use_pretty(board, fen, probe_response['root']);
+       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_use_pretty(board, fen, line);
+               var pretty_move = line['move']['pretty'];
+               lines[pretty_move] = translate_line(board, fen, line);
        }
 
        var text = JSON.stringify({
@@ -105,12 +105,12 @@ var reconcile_responses = function(probe_responses) {
        for (var i = 0; i < probe_responses.length; ++i) {
                for (var j = 0; j < probe_responses[i]['line'].length; ++j) {
                        var line = probe_responses[i]['line'][j];
-                       var uci_move = line['move']['from_sq'] + line['move']['to_sq'] + line['move']['promotion'];
+                       var pretty_move = line['move']['pretty'];
 
-                       if (!moves[uci_move]) {
-                               moves[uci_move] = line;
+                       if (!moves[pretty_move]) {
+                               moves[pretty_move] = line;
                        } else {
-                               moves[uci_move] = reconcile_moves(line, moves[uci_move]);
+                               moves[pretty_move] = reconcile_moves(line, moves[pretty_move]);
                        }
                }
        }
@@ -143,63 +143,6 @@ var reconcile_moves = function(a, b) {
 
 var translate_line = function(board, fen, line) {
        var r = {};
-       board.load(fen);
-       var toplay = board.turn();
-
-       if (line['move'] && line['move']['from_sq']) {
-               var promo = line['move']['promotion'];
-               if (promo) {
-                       r['move'] = board.move({ from: line['move']['from_sq'], to: line['move']['to_sq'], promotion: promo.toLowerCase() }).san;
-               } else {
-                       r['move'] = board.move({ from: line['move']['from_sq'], to: line['move']['to_sq'] }).san;
-               }
-       } 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];
-               var decoded = board.move({ from: move['from_sq'], to: move['to_sq'], promotion: move['promotion'] });
-               if (decoded === null) {
-                       break;
-               }
-               pv.push(decoded.san);
-       }
-       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;
-}
-
-var translate_line_use_pretty = function(board, fen, line) {
-       var r = {};
 
        if (line['move'] && line['move']['pretty']) {
                r['move'] = line['move']['pretty']