]> git.sesse.net Git - remoteglot/commitdiff
Potentially fix a move-number error in refutation lines.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 27 Dec 2023 08:50:25 +0000 (09:50 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 27 Dec 2023 08:50:25 +0000 (09:50 +0100)
Or possibly just mess up everything. This is mainly because
I have too many patches in trying to fix up admin mode,
and none of them work, and I need to clear out a bit :-)

www/js/remoteglot.js

index 7135953fb2298b579393d2a2668a28279fb59436..039db0e8517d9777ca1dc68e3194f0651d8b0729 100644 (file)
@@ -76,6 +76,10 @@ let occupied_by_arrows = [];
 /** Currently displayed refutation lines (on-screen).
  * Can either come from the current_analysis_data, displayed_analysis_data,
  * or hash_refutation_lines.
+ *
+ * TODO: This is a mess, and we should probably just let update_refutation_lines()
+ * decide anew every time instead of storing the state here in multiple global
+ * variables.
  */
 let refutation_lines = [];
 
@@ -86,6 +90,12 @@ let refutation_lines = [];
  */
 let hash_refutation_lines = null;
 
+/**
+ * What FEN refutation_lines is relative to. Will usually be base_fen,
+ * but if another move gets loaded while we are looking, they can diverge.
+ */
+let refutation_lines_base_fen = null;
+
 /** @type {number} @private */
 let ims = 0;
 
@@ -851,7 +861,7 @@ window['collapse_history'] = collapse_history;
  * Also recreates the global "display_lines".
  */
 function update_refutation_lines() {
-       if (base_fen === null) {
+       if (refutation_lines_base_fen === null) {
                return;
        }
        if (display_lines.length > 2) {
@@ -882,7 +892,7 @@ function update_refutation_lines() {
                moves.push(move);
        }
 
-       let invert = (find_toplay(base_fen) === 'b');
+       let invert = (find_toplay(refutation_lines_base_fen) === 'b');
        if (current_display_line && current_display_move % 2 == 0 && !current_display_line_is_history) {
                invert = !invert;
        }
@@ -919,7 +929,7 @@ function update_refutation_lines() {
                        let pv_td = document.createElement("td");
                        tr.appendChild(pv_td);
                        pv_td.classList.add("pv");
-                       pv_td.append(add_pv(base_fen, base_line.concat([ line['move'] ]), scores, start_display_move_num));
+                       pv_td.append(add_pv(refutation_lines_base_fen, base_line.concat([ line['move'] ]), scores, start_display_move_num));
 
                        tbl.append(tr);
                        continue;
@@ -948,7 +958,7 @@ function update_refutation_lines() {
                let pv_td = document.createElement("td");
                tr.appendChild(pv_td);
                pv_td.classList.add("pv");
-               pv_td.append(add_pv(base_fen, base_line.concat(line['pv']), scores, start_display_move_num, 10));
+               pv_td.append(add_pv(refutation_lines_base_fen, base_line.concat(line['pv']), scores, start_display_move_num, 10));
 
                tbl.append(tr);
        }
@@ -1239,6 +1249,7 @@ function update_board() {
                document.getElementById("whiteclock").replaceChildren();
                document.getElementById("blackclock").replaceChildren();
                refutation_lines = [];
+               refutation_lines_base_fen = null;
                update_refutation_lines();
                clear_arrows();
                update_displayed_line();
@@ -1377,7 +1388,10 @@ function update_board() {
 
        // Update the refutation lines.
        base_fen = data['position']['fen'];
-       refutation_lines = hash_refutation_lines || data['refutation_lines'];
+       if (hash_refutation_lines === null) {
+               refutation_lines = data['refutation_lines'];
+               refutation_lines_base_fen = base_fen;
+       }
        update_refutation_lines();
 
        // Update the sparkline last, since its size depends on how everything else reflowed.
@@ -1740,6 +1754,7 @@ function show_line(line_num, move_num) {
                current_display_line = null;
                current_display_move = null;
                hash_refutation_lines = null;
+               refutation_lines_base_fen = base_fen;
                if (displayed_analysis_data) {
                        // TODO: Support exiting to history position if we are in an
                        // analysis line of a history position.
@@ -2065,6 +2080,7 @@ function show_explore_hash_results(data, fen) {
        }
        current_hash_display_timer = null;
        hash_refutation_lines = data['lines'];
+       refutation_lines_base_fen = fen;
        update_board();
 }