From ae8f2127842079342869c1f818fe0812f0abba9a Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 27 Dec 2023 09:50:25 +0100 Subject: [PATCH] Potentially fix a move-number error in refutation lines. 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 | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index 7135953..039db0e 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -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(); } -- 2.39.2