]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Fix score sorting (sigh).
[remoteglot] / www / js / remoteglot.js
index 984404044fada1114f58039d71325263d563ea15..bba9ad5735bc1cf0249c63e70700fa13ac54e334 100644 (file)
@@ -777,8 +777,9 @@ var update_refutation_lines = function() {
                $(move_td).addClass("move");
 
                if (line['pv_pretty'].length == 0) {
-                       // Not found.
-                       $(move_td).text(line['pretty_move']);
+                       // Not found, so just make a one-move PV.
+                       var move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['pretty_move'] + "</a>";
+                       $(move_td).html(move);
                        var score_td = document.createElement("td");
 
                        $(score_td).addClass("score");
@@ -790,16 +791,17 @@ var update_refutation_lines = function() {
                        $(depth_td).addClass("depth");
                        $(depth_td).text("—");
 
+                       var pv_td = document.createElement("td");
+                       tr.appendChild(pv_td);
+                       $(pv_td).addClass("pv");
+                       $(pv_td).html(add_pv(base_fen, base_line.concat([ line['pretty_move'] ]), move_num, toplay, start_display_move_num));
+
                        tbl.append(tr);
                        continue;
                }
 
-               if (line['pv_pretty'].length == 0) {
-                       $(move_td).text(line['pretty_move']);
-               } else {
-                       var move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['pretty_move'] + "</a>";
-                       $(move_td).html(move);
-               }
+               var move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['pretty_move'] + "</a>";
+               $(move_td).html(move);
 
                var score_td = document.createElement("td");
                tr.appendChild(score_td);
@@ -1771,6 +1773,15 @@ var get_best_move = function(game, source, target) {
                move_hash[moves[i].san] = moves[i];
        }
 
+       // History and PV take priority over the display lines.
+       for (var i = 0; i < 2; ++i) {
+               var line = display_lines[i];
+               var first_move = line.pretty_pv[line.start_display_move_num];
+               if (move_hash[first_move]) {
+                       return move_hash[first_move];
+               }
+       }
+
        var best_move = null;
        var best_move_score = null;
 
@@ -1782,9 +1793,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;
                        }
                }
        }