X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Fjs%2Fremoteglot.js;h=d36bf9e5117bed15911ea36263ed5084fc6f0c48;hb=5a1f6c832883367ca4925443c63ed2aefb6514fd;hp=2e66c82fb03fb406a0ec8180762593501134e836;hpb=79966cb518085499da9ea884d9d99dd74d2f9514;p=remoteglot
diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js
index 2e66c82..d36bf9e 100644
--- a/www/js/remoteglot.js
+++ b/www/js/remoteglot.js
@@ -174,8 +174,13 @@ let display_fen = null;
* start_display_move_num: number
* }}
*
- * "start_display_move_num" is the (half-)move number to start displaying the PV at.
- * "score" is also evaluated at this point.
+ * "start_display_move_num" is the (half-)move number to start displaying the PV at,
+ * i.e., the index into pv.
+ *
+ * "score" is also evaluated at this point. scores can be empty and is frequently
+ * sparse; it's generally only really useful for history (we obviously don't know
+ * much about how the score will * move during e.g. a PV, except that a mate/TB
+ * counter might go down).
*/
var DisplayLine;
@@ -196,7 +201,11 @@ let current_display_line = null;
/** @type {boolean} @private */
let current_display_line_is_history = false;
-/** @type {?number} @private */
+/** @type {?number} @private
+ *
+ * The highlighted/used/shown move in current_display_line.pv, in terms of absolute index
+ * (not relative to e.g. the start FEN).
+ */
let current_display_move = null;
/**
@@ -424,6 +433,17 @@ function find_move_num(fen) {
return parseInt(fen.split(' ')[5]);
}
+/** @param {!string} fen
+ * @return {!number}
+ *
+ * Return the half-move clock, starting from 0 (and never resetting).
+ */
+function find_halfmove_num(fen) {
+ let move_num = find_move_num(fen);
+ let toplay = find_toplay(fen);
+ return (move_num - 1) * 2 + (toplay === 'w' ? 0 : 1);
+}
+
/** @param {!number} x
* @return {!number}
*/
@@ -731,9 +751,8 @@ function add_pv(start_fen, pv, scores, start_display_move_num, opt_limit, opt_sh
function print_pv(line_num, splicepos, opt_limit, opt_showlast) {
let display_line = display_lines[line_num];
let pv = display_line.pv;
- let move_num = find_move_num(display_line.start_fen);
- let toplay = find_toplay(display_line.start_fen);
- let halfmove_num = move_num * 2 + (toplay === 'w' ? 0 : 1); // From two, for simplicity.
+ let halfmove_num = find_halfmove_num(display_line.start_fen) + 2; // From two, for simplicity.
+ let start_halfmove_num = halfmove_num;
let ret = document.createDocumentFragment();
@@ -794,9 +813,9 @@ function print_pv(line_num, splicepos, opt_limit, opt_showlast) {
let link = document.createElement('a');
link.className = 'move';
- link.setAttribute('id', 'automove' + line_num + '-' + i);
+ link.setAttribute('id', 'automove' + line_num + '-' + (halfmove_num - start_halfmove_num));
link.textContent = pv[i];
- link.href = 'javascript:show_line(' + line_num + ', ' + i + ');';
+ link.href = 'javascript:show_line(' + line_num + ', ' + (halfmove_num - start_halfmove_num) + ');';
ret.appendChild(link);
}
if (in_tb) {
@@ -1300,7 +1319,7 @@ function update_board() {
document.getElementById("searchstats").textContent = "";
}
if (admin_password !== null) {
- document.getElementById("searchstats").innerHTML += " | ADMIN MODE (if password is right)";
+ document.getElementById("searchstats").innerHTML += " | ADMIN MODE (if password is right) | Undo move";
}
// Update the board itself.
@@ -1746,7 +1765,7 @@ function show_line(line_num, move_num) {
return;
} else {
current_display_line = {...display_lines[line_num]}; // Shallow clone.
- current_display_move = move_num + current_display_line.start_display_move_num;
+ current_display_move = move_num;
}
current_display_line_is_history = (line_num == 0);
@@ -1913,7 +1932,7 @@ function update_move_highlight() {
display_lines[1].pv = [];
}
- highlighted_move = document.getElementById("automove" + display_line_num + "-" + (current_display_move - current_display_line.start_display_move_num));
+ highlighted_move = document.getElementById("automove" + display_line_num + "-" + current_display_move);
if (highlighted_move !== null) {
highlighted_move.classList.add('highlight');
}
@@ -2239,6 +2258,29 @@ function send_chosen_move(fen, move) {
}
}
+function undo_move() {
+ if (admin_password !== null) {
+ let history = current_analysis_data['position']['history'];
+ history = history.slice(0, history.length - 1);
+
+ let position = current_analysis_data['position']['start_fen'];
+ let hiddenboard = chess_from(position, history, history.length);
+ let fen = hiddenboard.fen();
+
+ let url = '/manual-override.pl';
+ url += '?fen=' + encodeURIComponent(fen);
+ url += '&history=' + encodeURIComponent(JSON.stringify(history));
+ url += '&move=null';
+ 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.
+ }
+}
+window['undo_move'] = undo_move;
+
function onSnapEnd(source, target) {
if (source === target && recommended_move !== null) {
source = recommended_move.from;
@@ -2277,7 +2319,7 @@ function onSnapEnd(source, target) {
}
let line = display_lines[i];
if (line.pv[line.start_display_move_num] === move.san) {
- show_line(i, 0);
+ show_line(i, line.start_display_move_num);
return;
}
}