]> 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 b59c6e4be08f2089d1760fb15a9c18573916d3f6..1b6952db9bb58a75f14b0bccb8ac084ae14b8120 100644 (file)
@@ -642,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();
@@ -650,6 +671,7 @@ var update_board = function(current_data, display_data) {
                refutation_lines = [];
                update_refutation_lines();
                clear_arrows();
+               update_displayed_line();
                return;
        }
 
@@ -688,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']));