]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Deal with negative depths.
[remoteglot] / www / js / remoteglot.js
index 24f2fd1503c2234efda99abff60111025ce7c634..7ad1ff02565d904c2080e662a1ad7731b5a5f3e7 100644 (file)
@@ -158,10 +158,12 @@ var display_fen = null;
  *    pretty_pv: Array.<string>,
  *    move_num: number,
  *    toplay: string,
+ *    score: string,
  *    start_display_move_num: number
  * }} DisplayLine
  *
  * "start_display_move_num" is the (half-)move number to start displaying the PV at.
+ * "score" is also evaluated at this point.
  */
 
 /** All PVs that we currently know of.
@@ -623,17 +625,19 @@ var thousands = function(x) {
  * @param {Array.<string>} pretty_pv
  * @param {number} move_num
  * @param {!string} toplay
+ * @param {!string} score
  * @param {number} start_display_move_num
  * @param {number=} opt_limit
  * @param {boolean=} opt_showlast
  */
-var add_pv = function(start_fen, pretty_pv, move_num, toplay, start_display_move_num, opt_limit, opt_showlast) {
+var add_pv = function(start_fen, pretty_pv, move_num, toplay, score, start_display_move_num, opt_limit, opt_showlast) {
        display_lines.push({
                start_fen: start_fen,
                pretty_pv: pretty_pv,
                move_num: parseInt(move_num),
                toplay: toplay,
-               start_display_move_num: start_display_move_num,
+               score: score,
+               start_display_move_num: start_display_move_num
        });
        return print_pv(display_lines.length - 1, opt_limit, opt_showlast);
 }
@@ -801,7 +805,7 @@ var update_refutation_lines = function() {
                        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));
+                       $(pv_td).html(add_pv(base_fen, base_line.concat([ line['pretty_move'] ]), move_num, toplay, line['score'], start_display_move_num));
 
                        tbl.append(tr);
                        continue;
@@ -818,12 +822,16 @@ var update_refutation_lines = function() {
                var depth_td = document.createElement("td");
                tr.appendChild(depth_td);
                $(depth_td).addClass("depth");
-               $(depth_td).text("d" + line['depth']);
+               if (line['depth'] && line['depth'] >= 0) {
+                       $(depth_td).text("d" + line['depth']);
+               } else {
+                       $(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['pv_pretty']), move_num, toplay, start_display_move_num, 10));
+               $(pv_td).html(add_pv(base_fen, base_line.concat(line['pv_pretty']), move_num, toplay, line['score'], start_display_move_num, 10));
 
                tbl.append(tr);
        }
@@ -923,7 +931,7 @@ var update_board = function() {
        // unconditionally taken from current_data (we're not interested in
        // historic history).
        if (current_data['position']['pretty_history']) {
-               add_pv('start', current_data['position']['pretty_history'], 1, 'W', 0, 8, true);
+               add_pv('start', current_data['position']['pretty_history'], 1, 'W', null, 0, 8, true);
        } else {
                display_lines.push(null);
        }
@@ -1065,7 +1073,13 @@ var update_board = function() {
        update_clock();
 
        // The score.
-       if (data['score']) {
+       if (current_display_line) {
+               if (current_display_line.score) {
+                       $("#score").text(format_long_score(current_display_line.score));
+               } else {
+                       $("#score").text("No score for this move");
+               }
+       } else if (data['score']) {
                $("#score").text(format_long_score(data['score']));
        }
 
@@ -1098,7 +1112,7 @@ var update_board = function() {
 
        // Print the PV.
        $("#pvtitle").text("PV:");
-       $("#pv").html(add_pv(data['position']['fen'], data['pv_pretty'], data['position']['move_num'], data['position']['toplay'], 0));
+       $("#pv").html(add_pv(data['position']['fen'], data['pv_pretty'], data['position']['move_num'], data['position']['toplay'], data['score'], 0));
 
        // Update the PV arrow.
        clear_arrows();
@@ -1856,7 +1870,7 @@ var onSnapEnd = function(source, target) {
 
        if (current_display_line &&
            current_display_move < current_display_line.pretty_pv.length - 1 &&
-           current_display_line.pretty_pv[current_display_move] === move.san) {
+           current_display_line.pretty_pv[current_display_move + 1] === move.san) {
                next_move();
                return;
        }
@@ -1897,6 +1911,9 @@ var fmt_cp = function(v) {
 }
 
 var format_short_score = function(score) {
+       if (!score) {
+               return "???";
+       }
        if (score[0] === 'm') {
                if (score[2]) {  // Is a bound.
                        return score[2] + "\u00a0M" + pad(score[1], 3);