]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Fix the red note on moves where we have no historic analysis.
[remoteglot] / www / js / remoteglot.js
index 738edf0d5d2ffb063d1895455741fd1f0189bbf0..1b6952db9bb58a75f14b0bccb8ac084ae14b8120 100644 (file)
@@ -254,7 +254,7 @@ var position_arrow = function(arrow) {
                arrow.svg.parentElement.removeChild(arrow.svg);
                delete arrow.svg;
        }
-       if (current_display_line !== null) {
+       if (current_display_line !== null && !current_display_line_is_history) {
                return;
        }
 
@@ -489,7 +489,8 @@ var print_pv = function(line_num, pretty_pv, move_num, toplay, opt_limit, opt_sh
 
 var update_highlight = function() {
        $("#board").find('.square-55d63').removeClass('nonuglyhighlight');
-       if (current_display_line === null && highlight_from !== undefined && highlight_to !== undefined) {
+       if ((current_display_line === null || current_display_line_is_history) &&
+           highlight_from !== undefined && highlight_to !== undefined) {
                $("#board").find('.square-' + highlight_from).addClass('nonuglyhighlight');
                $("#board").find('.square-' + highlight_to).addClass('nonuglyhighlight');
        }
@@ -641,6 +642,27 @@ var update_board = function(current_data, display_data) {
                document.title = 'analysis.sesse.net';
        }
 
+       // The last move (shown by highlighting the from and to squares).
+       if (data['position'] && data['position']['last_move_uci']) {
+               highlight_from = data['position']['last_move_uci'].substr(0, 2);
+               highlight_to = data['position']['last_move_uci'].substr(2, 2);
+       } else if (current_display_line_is_history && current_display_move >= 0) {
+               // We don't have historic analysis for this position, but we
+               // can reconstruct what the last move was by just replaying
+               // from the start.
+               var hiddenboard = new Chess();
+               for (var i = 0; i <= current_display_move; ++i) {
+                       hiddenboard.move(current_display_line.pretty_pv[i]);
+               }
+               var moves = hiddenboard.history({ verbose: true });
+               var last_move = moves.pop();
+               highlight_from = last_move.from;
+               highlight_to = last_move.to;
+       } else {
+               highlight_from = highlight_to = undefined;
+       }
+       update_highlight();
+
        if (data['failed']) {
                $("#score").text("No analysis for this move");
                $("#pv").empty();
@@ -648,6 +670,8 @@ var update_board = function(current_data, display_data) {
                $("#refutationlines").empty();
                refutation_lines = [];
                update_refutation_lines();
+               clear_arrows();
+               update_displayed_line();
                return;
        }
 
@@ -686,14 +710,6 @@ var update_board = function(current_data, display_data) {
        fen = data['position']['fen'];
        update_displayed_line();
 
-       if (data['position']['last_move_uci']) {
-               highlight_from = data['position']['last_move_uci'].substr(0, 2);
-               highlight_to = data['position']['last_move_uci'].substr(2, 2);
-       } else {
-               highlight_from = highlight_to = undefined;
-       }
-       update_highlight();
-
        // Print the PV.
        $("#pv").html(add_pv(data['position']['fen'], data['pv_pretty'], data['position']['move_num'], data['position']['toplay']));