]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Fix some move number display issues. Argh.
[remoteglot] / www / js / remoteglot.js
index c9ff8d8291f4f8f2799a6e83a1003868d59fa4b0..7bd7e164e426984a79ed961741aa123a72fcaaf6 100644 (file)
@@ -33,8 +33,12 @@ var request_update = function(board) {
 
 var clear_arrows = function() {
        for (var i = 0; i < arrows.length; ++i) {
-               jsPlumb.detach(arrows[i].connection1);
-               jsPlumb.detach(arrows[i].connection2);
+               if (arrows[i].connection1) {
+                       jsPlumb.detach(arrows[i].connection1);
+               }
+               if (arrows[i].connection2) {
+                       jsPlumb.detach(arrows[i].connection2);
+               }
        }
        arrows = [];
 
@@ -209,7 +213,7 @@ var create_arrow = function(from_square, to_square, fg_color, line_width, arrow_
        arrows.push(arrow);
 }
 
-var compare_by_sort_key = function(refutation_lines, toplay, a, b) {
+var compare_by_sort_key = function(refutation_lines, a, b) {
        var ska = refutation_lines[a].sort_key;
        var skb = refutation_lines[b].sort_key;
        if (ska < skb) return -1;
@@ -217,14 +221,10 @@ var compare_by_sort_key = function(refutation_lines, toplay, a, b) {
        return 0;
 };
        
-var compare_by_score = function(refutation_lines, toplay, a, b) {
+var compare_by_score = function(refutation_lines, a, b) {
        var sa = parseInt(refutation_lines[b].score_sort_key);
        var sb = parseInt(refutation_lines[a].score_sort_key);
-       if (toplay == 'B') {
-               return sb - sa;
-       } else {
-               return sa - sb;
-       }
+       return sa - sb;
 }
 
 // Fake multi-PV using the refutation lines. Find all “relevant” moves,
@@ -285,8 +285,8 @@ var print_pv = function(fen, uci_pv, pretty_pv, move_num, toplay, limit) {
                pv = move_num + '. … ' + move;
                toplay = 'W';
                ++i;    
+               ++move_num;
        }
-       ++move_num;
        for ( ; i < pretty_pv.length; ++i) {
                var move = "<a class=\"move\" href=\"javascript:show_line(" + (display_lines.length - 1) + ", " + i + ");\">" + pretty_pv[i] + "</a>";
 
@@ -317,6 +317,10 @@ var update_highlight = function()  {
 }
 
 var update_refutation_lines = function(board) {
+       if (display_lines.length > 1) {
+               display_lines = [ display_lines[0] ];
+       }
+
        var tbl = $("#refutationlines");
        tbl.empty();
 
@@ -325,7 +329,7 @@ var update_refutation_lines = function(board) {
                moves.push(move);
        }
        var compare = sort_refutation_lines_by_score ? compare_by_score : compare_by_sort_key;
-       moves = moves.sort(function(a, b) { return compare(refutation_lines, toplay, a, b) });
+       moves = moves.sort(function(a, b) { return compare(refutation_lines, a, b) });
        for (var i = 0; i < moves.length; ++i) {
                var line = refutation_lines[moves[i]];
 
@@ -370,12 +374,16 @@ var update_refutation_lines = function(board) {
 }
 
 var update_board = function(board, data, num_viewers) {
+       display_lines = [];
+
        // The headline.
        var headline = 'Analysis';
        if (data.position.last_move !== 'none') {
-               headline += ' after ' + data.position.move_num + '. ';
+               headline += ' after '
                if (data.position.toplay == 'W') {
-                       headline += '… ';
+                       headline += (data.position.move_num-1) + '… ';
+               } else {
+                       headline += data.position.move_num + '. ';
                }
                headline += data.position.last_move;
        }