* Version of this script. If the server returns a version larger than
* this, it is a sign we should reload to upgrade ourselves.
*
- * @type {Number}
+ * @type {number}
* @const
* @private */
let SCRIPT_VERSION = 2023122700;
/** 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.
+ *
+ * @type {Array.<{
+ * score: Array,
+ * depth: string,
+ * pv: Array.<string>,
+ * move: string
+ * }>}
+ * @private
*/
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;
* toplay: string,
* scores: Array<{first_move: number, score: Object}>,
* 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.
*/
+var DisplayLine;
/** All PVs that we currently know of.
*
* The current timer to fire off a request to get main analysis (not history),
* if any, so that we can abort it.
*
- * @type {?Number}
+ * @type {?number}
* @private
*/
let current_analysis_request_timer = null;
* The current timer to display hash probe information (it could be waiting on the
* board to stop animating), if any, so that we can abort it.
*
- * @type {?Number}
+ * @type {?number}
* @private
*/
let current_hash_display_timer = null;
/**
* @param {!string} start_fen
* @param {Array.<string>} pv
- * @param {Array<{ first_move: integer, score: Object }>} scores
+ * @param {Array<{ first_move: number, score: Object }>} scores
* @param {number} start_display_move_num
* @param {number=} opt_limit
* @param {boolean=} opt_showlast
* 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) {
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;
}
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;
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);
}
document.getElementById("whiteclock").replaceChildren();
document.getElementById("blackclock").replaceChildren();
refutation_lines = [];
+ refutation_lines_base_fen = null;
update_refutation_lines();
clear_arrows();
update_displayed_line();
// 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.
}
/**
- * @param {Number} remaining_ms
+ * @param {number} remaining_ms
* @param {boolean} show_seconds
*/
function format_clock(remaining_ms, show_seconds) {
}
/**
- * @param {Number} x
+ * @param {number} x
*/
function format_2d(x) {
if (x >= 10) {
/**
* @param {string} move
- * @param {Number} move_num Move number of this move.
+ * @param {number} move_num Move number of this move.
* @param {boolean} white_to_play Whether white is to play this move.
*/
function format_move_with_number(move, move_num, white_to_play) {
/**
* @param {string} move
- * @param {Number} halfmove_num Half-move number that is to be played,
+ * @param {number} halfmove_num Half-move number that is to be played,
* starting from 0.
*/
function format_halfmove_with_number(move, halfmove_num) {
/**
* @param {Object} data
- * @param {Number} halfmove_num
+ * @param {number} halfmove_num
*/
function format_tooltip(data, halfmove_num) {
if (data['score_history'][halfmove_num + 1] ||
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.
}
current_hash_display_timer = null;
hash_refutation_lines = data['lines'];
+ refutation_lines_base_fen = fen;
update_board();
}
if (move === null) return 'snapback';
}
+/**
+ * If we are in admin mode, send this move to the backend.
+ *
+ * @param {string} fen
+ * @param {string} move
+ */
+function send_chosen_move(fen, move) {
+ if (admin_password !== null) {
+ let history = current_analysis_data['position']['history'];
+ let url = '/manual-override.pl';
+ url += '?fen=' + encodeURIComponent(fen);
+ url += '&history=' + encodeURIComponent(JSON.stringify(history));
+ url += '&move=' + encodeURIComponent(move);
+ url += '&player_w=' + encodeURIComponent(current_analysis_data['position']['player_w']);
+ url += '&player_b=' + encodeURIComponent(current_analysis_data['position']['player_b']);
+ url += '&password=' + encodeURIComponent(admin_password);
+
+ console.log(fen, history);
+ fetch(url); // Ignore the result.
+ }
+}
+
function onSnapEnd(source, target) {
if (source === target && recommended_move !== null) {
source = recommended_move.from;
});
if (admin_password !== null) {
- let url = '/manual-override.pl';
- url += '?fen=' + encodeURIComponent(display_fen);
- url += '&history=' + encodeURIComponent(JSON.stringify(current_analysis_data['position']['history']));
- url += '&move=' + encodeURIComponent(move.san);
- url += '&player_w=' + encodeURIComponent(current_analysis_data['position']['player_w']);
- url += '&player_b=' + encodeURIComponent(current_analysis_data['position']['player_b']);
- url += '&password=' + encodeURIComponent(admin_password);
- fetch(url);
+ send_chosen_move(display_fen, move.san);
return;
}