]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
A little function split.
[remoteglot] / www / js / remoteglot.js
index 5f3223dc5b8db45357e6c61f80fb4c75ee9d35bb..82f64d9dfd500d950e80d88ce1a29102216df58a 100644 (file)
@@ -1559,28 +1559,7 @@ var update_move_highlight = function() {
                highlighted_move.removeClass('highlight'); 
        }
        if (current_display_line) {
-               // See if the current displayed line is identical to any of the ones
-               // we have on screen. (It might not be if e.g. the analysis reloaded
-               // since we started looking.)
-               var display_line_num = null;
-               for (var i = 0; i < display_lines.length; ++i) {
-                       var line = display_lines[i];
-                       if (line.start_display_move_num > 0) continue;
-                       if (current_display_line.start_fen !== line.start_fen) continue;
-                       if (current_display_line.pretty_pv.length !== line.pretty_pv.length) continue;
-                       var ok = true;
-                       for (var j = 0; j < line.pretty_pv.length; ++j) {
-                               if (current_display_line.pretty_pv[j] !== line.pretty_pv[j]) {
-                                       ok = false;
-                                       break;
-                               }
-                       }
-                       if (ok) {
-                               display_line_num = i;
-                               break;
-                       }
-               }
-
+               var display_line_num = find_display_line_matching_num();
                if (display_line_num === null) {
                        // Replace the PV with the (complete) line.
                        $("#pvtitle").text("Exploring:");
@@ -1595,6 +1574,33 @@ var update_move_highlight = function() {
        }
 }
 
+/**
+ * See if the current displayed line is identical to any of the ones
+ * we have on screen. (It might not be if e.g. the analysis reloaded
+ * since we started looking.)
+ *
+ * @return {?number}
+ */
+var find_display_line_matching_num = function() {
+       for (var i = 0; i < display_lines.length; ++i) {
+               var line = display_lines[i];
+               if (line.start_display_move_num > 0) continue;
+               if (current_display_line.start_fen !== line.start_fen) continue;
+               if (current_display_line.pretty_pv.length !== line.pretty_pv.length) continue;
+               var ok = true;
+               for (var j = 0; j < line.pretty_pv.length; ++j) {
+                       if (current_display_line.pretty_pv[j] !== line.pretty_pv[j]) {
+                               ok = false;
+                               break;
+                       }
+               }
+               if (ok) {
+                       return i;
+               }
+       }
+       return null;
+}
+
 var update_displayed_line = function() {
        if (current_display_line === null) {
                $("#linenav").hide();
@@ -1672,6 +1678,7 @@ var explore_hash = function(fen) {
                clearTimeout(current_hash_display_timer);
                current_hash_display_timer = null;
        }
+       $("#refutationlines").empty();
        current_hash_xhr = $.ajax({
                url: backend_hash_url + "?fen=" + fen
        }).done(function(data, textstatus, xhr) {
@@ -1793,9 +1800,10 @@ var get_best_move = function(game, source, target) {
                }
                var first_move = line['pv_pretty'][0];
                if (move_hash[first_move]) {
-                       if (best_move_score === null || line['score_sort_key'] > best_move_score) {
+                       var score = parseInt(line['score_sort_key'], 10);
+                       if (best_move_score === null || score > best_move_score) {
                                best_move = move_hash[first_move];
-                               best_move_score = line['score_sort_key'];
+                               best_move_score = score;
                        }
                }
        }