* @type {Number}
* @const
* @private */
-let SCRIPT_VERSION = 2021021300;
+let SCRIPT_VERSION = 2023122700;
/**
* The current backend URL.
*/
let hash_refutation_lines = null;
-/** @type {!number} @private */
-let move_num = 1;
-
-/** @type {!string} @private */
-let toplay = 'W';
-
/** @type {number} @private */
let ims = 0;
if (ding && ding.play) {
if (old_data['position'] && old_data['position']['fen'] &&
new_data['position'] && new_data['position']['fen'] &&
- (old_data['position']['fen'] !== new_data['position']['fen'] ||
- old_data['position']['move_num'] !== new_data['position']['move_num'])) {
+ old_data['position']['fen'] !== new_data['position']['fen']) {
ding.play();
}
}
}
}
+/** @param {!string} fen
+ * @return {!string}
+ *
+ * Return whose side it is to play (W or B), given a FEN.
+ * This is in uppercase due to historical reasons, which we
+ * should get rid of.
+ */
+function find_toplay(fen) {
+ return fen.split(' ')[1].toUpperCase();
+}
+
+/** @param {!string} fen
+ * @return {!number}
+ *
+ * Return the move clock, starting from 1. See also find_toplay().
+ */
+function find_move_num(fen) {
+ return parseInt(fen.split(' ')[5]);
+}
+
/** @param {!number} x
* @return {!number}
*/
moves.push(move);
}
}
- moves = moves.sort(function(a, b) { return compare_by_score(data['refutation_lines'], data['position']['toplay'] === 'B', a, b) });
+ let toplay = find_toplay(data['position']['fen']);
+ moves = moves.sort(function(a, b) { return compare_by_score(data['refutation_lines'], toplay, a, b) });
moves.unshift(data['pv'][0]);
return moves;
moves.push(move);
}
+ let move_num = find_move_num(base_fen);
+ let toplay = find_toplay(base_fen);
let invert = (toplay === 'B');
if (current_display_line && current_display_move % 2 == 0 && !current_display_line_is_history) {
invert = !invert;
} else if (data['position']['last_move'] !== 'none') {
// Find the previous move.
let previous_move_num, previous_toplay;
- if (data['position']['toplay'] == 'B') {
- previous_move_num = data['position']['move_num'];
+ let fen = data['position']['fen'];
+ if (find_toplay(fen) === 'B') {
+ previous_move_num = find_move_num(fen);
previous_toplay = 'W';
} else {
- previous_move_num = data['position']['move_num'] - 1;
+ previous_move_num = find_move_num(fen) - 1;
previous_toplay = 'B';
}
document.getElementById("pvtitle").textContent = "PV:";
let scores = [{ first_move: -1, score: data['score'] }];
- document.getElementById("pv").replaceChildren(add_pv(data['position']['fen'], data['pv'], data['position']['move_num'], data['position']['toplay'], scores, 0));
+ document.getElementById("pv").replaceChildren(add_pv(data['position']['fen'], data['pv'], scores, 0));
// Update the PV arrow.
clear_arrows();
+ let toplay = find_toplay(data['position']['fen']);
if (data['pv'].length >= 1) {
let hiddenboard = new Chess(base_fen);
hiddenboard.move(data['pv'][i + 1]); // To keep continuity.
}
- let alt_moves = find_nonstupid_moves(data, 30, data['position']['toplay'] === 'B');
+ let alt_moves = find_nonstupid_moves(data, 30, toplay === 'B');
for (let i = 1; i < alt_moves.length && i < 3; ++i) {
hiddenboard = new Chess(base_fen);
let move = patch_move(hiddenboard.move(alt_moves[i]));
// See if all semi-reasonable moves have only one possible response.
if (data['pv'].length >= 2) {
- let nonstupid_moves = find_nonstupid_moves(data, 300, data['position']['toplay'] === 'B');
+ let nonstupid_moves = find_nonstupid_moves(data, 300, toplay === 'B');
let hiddenboard = new Chess(base_fen);
hiddenboard.move(data['pv'][0]);
let response = hiddenboard.move(data['pv'][1]);
// Update the refutation lines.
base_fen = data['position']['fen'];
- move_num = parseInt(data['position']['move_num']);
- toplay = data['position']['toplay'];
refutation_lines = hash_refutation_lines || data['refutation_lines'];
update_refutation_lines();
}
}
if (first_move_num !== undefined) {
- let last_move_num = data['position']['move_num'] * 2 - 3;
- if (data['position']['toplay'] === 'B') {
+ let fen = data['position']['fen'];
+ let last_move_num = find_move_num(fen) * 2 - 3;
+ if (find_toplay(fen) === 'B') {
++last_move_num;
}