4 * Version of this script. If the server returns a version larger than
5 * this, it is a sign we should reload to upgrade ourselves.
10 var SCRIPT_VERSION = 2021021300;
13 * The current backend URL.
18 var backend_url = "/analysis.pl";
19 var backend_hash_url = "/hash";
21 /** @type {window.ChessBoard} @private */
24 /** @type {boolean} @private */
25 var board_is_animating = false;
28 * The most recent analysis data we have from the server
29 * (about the most recent position).
33 var current_analysis_data = null;
36 * If we are displaying previous analysis or from hash, this is non-null,
37 * and will override most of current_analysis_data.
42 var displayed_analysis_data = null;
45 * Games currently in progress, if any.
57 var current_games = null;
72 /** @type {Array.<Array.<boolean>>} */
73 var occupied_by_arrows = [];
75 /** Currently displayed refutation lines (on-screen).
76 * Can either come from the current_analysis_data, displayed_analysis_data,
77 * or hash_refutation_lines.
79 var refutation_lines = [];
81 /** Refutation lines from current hash probe.
83 * If non-null, will override refutation lines from the base position.
84 * Note that these are relative to display_fen, not base_fen.
86 var hash_refutation_lines = null;
88 /** @type {!number} @private */
91 /** @type {!string} @private */
94 /** @type {number} @private */
97 /** @type {boolean} @private */
98 var truncate_display_history = true;
100 /** @type {!string|undefined} @private */
101 var highlight_from = undefined;
103 /** @type {!string|undefined} @private */
104 var highlight_to = undefined;
106 /** The HTML object of the move currently being highlighted (in red).
109 var highlighted_move = null;
111 /** Currently suggested/recommended move when dragging.
112 * @type {?{from: !string, to: !string}}
115 var recommended_move = null;
117 /** If reverse-dragging (dragging from the destination square to the
118 * source square), the destination square.
122 var reverse_dragging_from = null;
124 /** @type {?number} @private */
127 /** @type {boolean} @private */
128 var enable_sound = false;
130 /** @type {!number} @private */
134 * Our best estimate of how many milliseconds we need to add to
135 * new Date() to get the true UTC time. Calibrated against the
141 var client_clock_offset_ms = null;
143 var clock_timer = null;
145 /** The current position being analyzed, represented as a FEN string.
146 * Note that this is not necessarily the same as display_fen.
152 /** The current position on the board, represented as a FEN string.
153 * Note that board.fen() does not contain e.g. who is to play.
157 var display_fen = null;
161 * pv: Array.<string>,
164 * scores: Array<{first_move: number, score: Object}>,
165 * start_display_move_num: number
168 * "start_display_move_num" is the (half-)move number to start displaying the PV at.
169 * "score" is also evaluated at this point.
172 /** All PVs that we currently know of.
174 * Element 0 is history (or null if no history).
175 * Element 1 is current main PV, or explored line if nowhere else on the screen.
176 * All remaining elements are refutation lines (multi-PV).
178 * @type {Array.<DisplayLine>}
181 var display_lines = [];
183 /** @type {?DisplayLine} @private */
184 var current_display_line = null;
186 /** @type {boolean} @private */
187 var current_display_line_is_history = false;
189 /** @type {?number} @private */
190 var current_display_move = null;
193 * The current backend request to get main analysis (not history), if any,
194 * so that we can abort it.
196 * @type {?AbortController}
199 var current_analysis_xhr = null;
202 * The current timer to fire off a request to get main analysis (not history),
203 * if any, so that we can abort it.
208 var current_analysis_request_timer = null;
211 * The current backend request to get historic data, if any.
213 * @type {?AbortController}
216 var current_historic_xhr = null;
219 * The current backend request to get hash probes, if any, so that we can abort it.
221 * @type {?AbortController}
224 var current_hash_xhr = null;
227 * The current timer to display hash probe information (it could be waiting on the
228 * board to stop animating), if any, so that we can abort it.
233 var current_hash_display_timer = null;
235 var supports_html5_storage = function() {
237 return 'localStorage' in window && window['localStorage'] !== null;
243 // Make the unique token persistent so people refreshing the page won't count twice.
244 // Of course, you can never fully protect against people deliberately wanting to spam.
245 var get_unique = function() {
246 var use_local_storage = supports_html5_storage();
247 if (use_local_storage && localStorage['unique']) {
248 return localStorage['unique'];
250 var unique = Math.random();
251 if (use_local_storage) {
252 localStorage['unique'] = unique;
257 var request_update = function() {
258 current_analysis_request_timer = null;
260 let handle_err = () => {
261 // Backend error or similar. Wait ten seconds, then try again.
262 current_analysis_request_timer = setTimeout(function() { request_update(); }, 10000);
265 current_analysis_xhr = new AbortController();
266 const signal = current_analysis_xhr.signal;
267 fetch(backend_url + "?ims=" + ims + "&unique=" + unique, { signal })
268 .then((response) => response.json().then(data => ({ok: response.ok, headers: response.headers, json: data}))) // ick
275 if (delay_ms === 0) {
276 process_update_response(obj.json, obj.headers);
278 setTimeout(function() { process_update_response(obj.json, obj.headers); }, delay_ms);
282 if (!backend_url.match(/history/)) {
284 current_analysis_request_timer = setTimeout(function() { request_update(); }, timeout);
288 if (err.name === 'AbortError') {
289 // Aborted because we are switching backends. Abandon and don't retry,
290 // because another one is already started for us.
298 document.body.style.opacity = null;
303 var process_update_response = function(data, headers) {
304 sync_server_clock(headers.get('Date'));
305 ims = headers.get('X-RGLM');
306 var num_viewers = headers.get('X-RGNV');
308 if (Array.isArray(data)) {
309 new_data = JSON.parse(JSON.stringify(current_analysis_data));
310 JSON_delta.patch(new_data, data);
315 var minimum_version = headers.get('X-RGMV');
316 if (minimum_version && minimum_version > SCRIPT_VERSION) {
317 // Upgrade to latest version with a force-reload.
318 location.reload(true);
321 // Verify that the PV makes sense.
323 if (new_data['pv']) {
324 var hiddenboard = new Chess(new_data['position']['fen']);
325 for (var i = 0; i < new_data['pv'].length; ++i) {
326 if (hiddenboard.move(new_data['pv'][i]) === null) {
334 possibly_play_sound(current_analysis_data, new_data);
335 current_analysis_data = new_data;
337 update_num_viewers(num_viewers);
339 console.log("Received invalid update, waiting five seconds and trying again.");
340 setTimeout(function() { location.reload(true); }, 5000);
344 var possibly_play_sound = function(old_data, new_data) {
348 if (old_data === null) {
351 var ding = document.getElementById('ding');
352 if (ding && ding.play) {
353 if (old_data['position'] && old_data['position']['fen'] &&
354 new_data['position'] && new_data['position']['fen'] &&
355 (old_data['position']['fen'] !== new_data['position']['fen'] ||
356 old_data['position']['move_num'] !== new_data['position']['move_num'])) {
363 * @type {!string} server_date_string
365 var sync_server_clock = function(server_date_string) {
366 var server_time_ms = new Date(server_date_string).getTime();
367 var client_time_ms = new Date().getTime();
368 var estimated_offset_ms = server_time_ms - client_time_ms;
370 // In order not to let the noise move us too much back and forth
371 // (the server only has one-second resolution anyway), we only
372 // change an existing skew if we are at least five seconds off.
373 if (client_clock_offset_ms === null ||
374 Math.abs(estimated_offset_ms - client_clock_offset_ms) > 5000) {
375 client_clock_offset_ms = estimated_offset_ms;
379 var clear_arrows = function() {
380 for (var i = 0; i < arrows.length; ++i) {
382 if (arrows[i].svg.parentElement) {
383 arrows[i].svg.parentElement.removeChild(arrows[i].svg);
385 delete arrows[i].svg;
390 occupied_by_arrows = [];
391 for (var y = 0; y < 8; ++y) {
392 occupied_by_arrows.push([false, false, false, false, false, false, false, false]);
396 var redraw_arrows = function() {
397 for (var i = 0; i < arrows.length; ++i) {
398 position_arrow(arrows[i]);
402 /** @param {!number} x
405 var sign = function(x) {
415 /** See if drawing this arrow on the board would cause unduly amount of confusion.
416 * @param {!string} from The square the arrow is from (e.g. e4).
417 * @param {!string} to The square the arrow is to (e.g. e4).
420 var interfering_arrow = function(from, to) {
421 var from_col = from.charCodeAt(0) - "a1".charCodeAt(0);
422 var from_row = from.charCodeAt(1) - "a1".charCodeAt(1);
423 var to_col = to.charCodeAt(0) - "a1".charCodeAt(0);
424 var to_row = to.charCodeAt(1) - "a1".charCodeAt(1);
426 occupied_by_arrows[from_row][from_col] = true;
428 // Knight move: Just check that we haven't been at the destination before.
429 if ((Math.abs(to_col - from_col) == 2 && Math.abs(to_row - from_row) == 1) ||
430 (Math.abs(to_col - from_col) == 1 && Math.abs(to_row - from_row) == 2)) {
431 return occupied_by_arrows[to_row][to_col];
434 // Sliding piece: Check if anything except the from-square is seen before.
435 var dx = sign(to_col - from_col);
436 var dy = sign(to_row - from_row);
442 if (occupied_by_arrows[y][x]) {
445 occupied_by_arrows[y][x] = true;
446 } while (x != to_col || y != to_row);
451 /** Find a point along the coordinate system given by the given line,
452 * <t> units forward from the start of the line, <u> units to the right of it.
453 * @param {!number} x1
454 * @param {!number} x2
455 * @param {!number} y1
456 * @param {!number} y2
459 * @return {!string} The point in "x y" form, suitable for SVG paths.
461 var point_from_start = function(x1, y1, x2, y2, t, u) {
465 var norm = 1.0 / Math.sqrt(dx * dx + dy * dy);
469 var x = x1 + dx * t + dy * u;
470 var y = y1 + dy * t - dx * u;
474 /** Find a point along the coordinate system given by the given line,
475 * <t> units forward from the end of the line, <u> units to the right of it.
476 * @param {!number} x1
477 * @param {!number} x2
478 * @param {!number} y1
479 * @param {!number} y2
482 * @return {!string} The point in "x y" form, suitable for SVG paths.
484 var point_from_end = function(x1, y1, x2, y2, t, u) {
488 var norm = 1.0 / Math.sqrt(dx * dx + dy * dy);
492 var x = x2 + dx * t + dy * u;
493 var y = y2 + dy * t - dx * u;
497 var position_arrow = function(arrow) {
499 if (arrow.svg.parentElement) {
500 arrow.svg.parentElement.removeChild(arrow.svg);
504 if (current_display_line !== null && !current_display_line_is_history) {
508 var zoom_factor = document.getElementById("board").getBoundingClientRect().width / 400.0;
509 var line_width = arrow.line_width * zoom_factor;
510 var arrow_size = arrow.arrow_size * zoom_factor;
512 var square_width = document.querySelector(".square-a8").getBoundingClientRect().width;
513 var pos, from_y, to_y, from_x, to_x;
514 if (board.orientation() === 'black') {
515 pos = document.querySelector(".square-h1").getBoundingClientRect(); // FIXME: margin?
516 from_y = (arrow.from_row + 0.5)*square_width;
517 to_y = (arrow.to_row + 0.5)*square_width;
518 from_x = (7 - arrow.from_col + 0.5)*square_width;
519 to_x = (7 - arrow.to_col + 0.5)*square_width;
521 pos = document.querySelector(".square-a8").getBoundingClientRect(); // FIXME: margin?
522 from_y = (7 - arrow.from_row + 0.5)*square_width;
523 to_y = (7 - arrow.to_row + 0.5)*square_width;
524 from_x = (arrow.from_col + 0.5)*square_width;
525 to_x = (arrow.to_col + 0.5)*square_width;
528 var SVG_NS = "http://www.w3.org/2000/svg";
529 var XHTML_NS = "http://www.w3.org/1999/xhtml";
530 var svg = document.createElementNS(SVG_NS, "svg");
531 svg.setAttribute("width", /** @type{number} */ (document.getElementById("board").getBoundingClientRect().width));
532 svg.setAttribute("height", /** @type{number} */ (document.getElementById("board").getBoundingClientRect().height));
533 svg.setAttribute("style", "position: absolute");
534 svg.setAttribute("position", "absolute");
535 svg.setAttribute("version", "1.1");
536 svg.setAttribute("class", "c1");
537 svg.setAttribute("xmlns", XHTML_NS);
545 var outline = document.createElementNS(SVG_NS, "path");
546 outline.setAttribute("d", "M " + point_from_start(x1, y1, x2, y2, arrow_size / 2, 0) + " L " + point_from_end(x1, y1, x2, y2, -arrow_size / 2, 0));
547 outline.setAttribute("xmlns", XHTML_NS);
548 outline.setAttribute("stroke", "#666");
549 outline.setAttribute("stroke-width", line_width + 2);
550 outline.setAttribute("fill", "none");
551 svg.appendChild(outline);
553 var path = document.createElementNS(SVG_NS, "path");
554 path.setAttribute("d", "M " + point_from_start(x1, y1, x2, y2, arrow_size / 2, 0) + " L " + point_from_end(x1, y1, x2, y2, -arrow_size / 2, 0));
555 path.setAttribute("xmlns", XHTML_NS);
556 path.setAttribute("stroke", arrow.fg_color);
557 path.setAttribute("stroke-width", line_width);
558 path.setAttribute("fill", "none");
559 svg.appendChild(path);
561 // Then the arrow head.
562 var head = document.createElementNS(SVG_NS, "path");
563 head.setAttribute("d",
564 "M " + point_from_end(x1, y1, x2, y2, 0, 0) +
565 " L " + point_from_end(x1, y1, x2, y2, -arrow_size, -arrow_size / 2) +
566 " L " + point_from_end(x1, y1, x2, y2, -arrow_size * .623, 0.0) +
567 " L " + point_from_end(x1, y1, x2, y2, -arrow_size, arrow_size / 2) +
568 " L " + point_from_end(x1, y1, x2, y2, 0, 0));
569 head.setAttribute("xmlns", XHTML_NS);
570 head.setAttribute("stroke", "#000");
571 head.setAttribute("stroke-width", "1");
572 head.setAttribute("fill", arrow.fg_color);
573 svg.appendChild(head);
575 svg.style.top = pos.top;
576 svg.style.left = pos.left;
577 svg.style.pointerEvents = 'none';
578 document.body.appendChild(svg);
583 * @param {!string} from_square
584 * @param {!string} to_square
585 * @param {!string} fg_color
586 * @param {number} line_width
587 * @param {number} arrow_size
589 var create_arrow = function(from_square, to_square, fg_color, line_width, arrow_size) {
590 var from_col = from_square.charCodeAt(0) - "a1".charCodeAt(0);
591 var from_row = from_square.charCodeAt(1) - "a1".charCodeAt(1);
592 var to_col = to_square.charCodeAt(0) - "a1".charCodeAt(0);
593 var to_row = to_square.charCodeAt(1) - "a1".charCodeAt(1);
601 line_width: line_width,
602 arrow_size: arrow_size,
606 position_arrow(arrow);
610 var compare_by_score = function(refutation_lines, invert, a, b) {
611 var sa = compute_score_sort_key(refutation_lines[b]['score'], refutation_lines[b]['depth'], invert);
612 var sb = compute_score_sort_key(refutation_lines[a]['score'], refutation_lines[a]['depth'], invert);
617 * Fake multi-PV using the refutation lines. Find all “relevant” moves,
618 * sorted by quality, descending.
620 * @param {!Object} data
621 * @param {number} margin The maximum number of centipawns worse than the
622 * best move can be and still be included.
623 * @param {boolean} invert Whether black is to play.
624 * @return {Array.<string>} The FEN representation (e.g. Ne4) of all
625 * moves, in score order.
627 var find_nonstupid_moves = function(data, margin, invert) {
628 // First of all, if there are any moves that are more than 0.5 ahead of
629 // the primary move, the refutation lines are probably bunk, so just
631 var best_score = undefined;
632 var pv_score = undefined;
633 for (var move in data['refutation_lines']) {
634 var line = data['refutation_lines'][move];
635 var score = compute_score_sort_key(line['score'], line['depth'], invert, false);
636 if (move == data['pv'][0]) {
639 if (best_score === undefined || score > best_score) {
642 if (line['depth'] < 8) {
647 if (best_score - pv_score > 50) {
651 // Now find all moves that are within “margin” of the best score.
652 // The PV move will always be first.
654 for (var move in data['refutation_lines']) {
655 var line = data['refutation_lines'][move];
656 var score = compute_score_sort_key(line['score'], line['depth'], invert);
657 if (move != data['pv'][0] && best_score - score <= margin) {
661 moves = moves.sort(function(a, b) { return compare_by_score(data['refutation_lines'], data['position']['toplay'] === 'B', a, b) });
662 moves.unshift(data['pv'][0]);
671 var thousands = function(x) {
672 return String(x).split('').reverse().join('').replace(/(\d{3}\B)/g, '$1,').split('').reverse().join('');
676 * @param {!string} start_fen
677 * @param {Array.<string>} pv
678 * @param {number} move_num
679 * @param {!string} toplay
680 * @param {Array<{ first_move: integer, score: Object }>} scores
681 * @param {number} start_display_move_num
682 * @param {number=} opt_limit
683 * @param {boolean=} opt_showlast
685 var add_pv = function(start_fen, pv, move_num, toplay, scores, start_display_move_num, opt_limit, opt_showlast) {
687 start_fen: start_fen,
689 move_num: parseInt(move_num),
692 start_display_move_num: start_display_move_num
694 var splicepos = null;
695 if (scores !== null && scores.length >= 1 &&
696 scores[scores.length - 1].score !== undefined &&
697 scores[scores.length - 1].score !== null &&
698 (scores[scores.length - 1].score[0] === 'T' ||
699 scores[scores.length - 1].score[0] === 't')) {
700 splicepos = scores[scores.length - 1].score[1];
702 return print_pv(display_lines.length - 1, splicepos, opt_limit, opt_showlast);
706 * @param {number} line_num
707 * @param {?number} splicepos If non-null, where the tablebase-spliced portion of the TB starts.
708 * @param {number=} opt_limit If set, show at most this number of moves.
709 * @param {boolean=} opt_showlast If limit is set, show the last moves instead of the first ones.
711 var print_pv = function(line_num, splicepos, opt_limit, opt_showlast) {
712 var display_line = display_lines[line_num];
713 var pv = display_line.pv;
714 var move_num = display_line.move_num;
715 var toplay = display_line.toplay;
717 // Truncate PV at the start if needed.
718 var start_display_move_num = display_line.start_display_move_num;
719 if (start_display_move_num > 0) {
720 pv = pv.slice(start_display_move_num);
721 var to_add = start_display_move_num;
722 if (toplay === 'B') {
727 if (to_add % 2 == 1) {
731 move_num += to_add / 2;
732 if (splicepos !== null && splicepos > 0) {
740 if (opt_limit && opt_showlast && pv.length > opt_limit) {
741 // Truncate the PV at the beginning (instead of at the end).
742 // We assume here that toplay is 'W'. We also assume that if
743 // opt_showlast is set, then it is the history, and thus,
744 // the UI should be to expand the history.
745 ret = '(<a class="move" href="javascript:collapse_history(false)">…</a>) ';
746 i = pv.length - opt_limit;
751 } else if (toplay == 'B' && pv.length > 0) {
753 if (splicepos === 0) {
757 move += "<a class=\"move\" id=\"automove" + line_num + "-0\" href=\"javascript:show_line(" + line_num + ", " + 0 + ");\">" + pv[0] + "</a>";
758 ret = move_num + '. … ' + move;
763 for ( ; i < pv.length; ++i) {
764 var move = "<a class=\"move\" id=\"automove" + line_num + "-" + i + "\" href=\"javascript:show_line(" + line_num + ", " + i + ");\">" + pv[i] + "</a>";
765 if (splicepos === i) {
771 if (i > opt_limit && !opt_showlast) {
780 ret += move_num + '. ' + move;
794 /** Update the highlighted to/from squares on the board.
795 * Based on the global "highlight_from" and "highlight_to" variables.
797 var update_board_highlight = function() {
798 document.getElementById("board").querySelector('.square-55d63').classList.remove('nonuglyhighlight');
799 if ((current_display_line === null || current_display_line_is_history) &&
800 highlight_from !== undefined && highlight_to !== undefined) {
801 document.getElementById("board").querySelector('.square-' + highlight_from).classList.add('nonuglyhighlight');
802 document.getElementById("board").querySelector('.square-' + highlight_to).classList.add('nonuglyhighlight');
806 var update_history = function() {
807 if (display_lines[0] === null || display_lines[0].pv.length == 0) {
808 document.getElementById("history").innerHTML = "No history";
809 } else if (truncate_display_history) {
810 document.getElementById("history").innerHTML = print_pv(0, null, 8, true);
812 document.getElementById("history").html(
813 '(<a class="move" href="javascript:collapse_history(true)">collapse</a>) ' +
819 * @param {!boolean} truncate_history
821 var collapse_history = function(truncate_history) {
822 truncate_display_history = truncate_history;
825 window['collapse_history'] = collapse_history;
827 /** Update the HTML display of multi-PV from the global "refutation_lines".
829 * Also recreates the global "display_lines".
831 var update_refutation_lines = function() {
832 if (base_fen === null) {
835 if (display_lines.length > 2) {
836 // Truncate so that only the history and PV is left.
837 display_lines = [ display_lines[0], display_lines[1] ];
839 var tbl = document.getElementById("refutationlines");
840 tbl.replaceChildren();
842 if (display_lines.length < 2) {
846 // Find out where the lines start from.
848 var base_scores = display_lines[1].scores;
849 var start_display_move_num = 0;
850 if (hash_refutation_lines) {
851 base_line = current_display_line.pv.slice(0, current_display_move + 1);
852 base_scores = current_display_line.scores;
853 start_display_move_num = base_line.length;
857 for (var move in refutation_lines) {
861 var invert = (toplay === 'B');
862 if (current_display_line && current_display_move % 2 == 0 && !current_display_line_is_history) {
865 moves = moves.sort(function(a, b) { return compare_by_score(refutation_lines, invert, a, b) });
866 for (var i = 0; i < moves.length; ++i) {
867 var line = refutation_lines[moves[i]];
869 var tr = document.createElement("tr");
871 var move_td = document.createElement("td");
872 tr.appendChild(move_td);
873 move_td.classList.add("move");
875 var scores = base_scores.concat([{ first_move: start_display_move_num, score: line['score'] }]);
877 if (line['pv'].length == 0) {
878 // Not found, so just make a one-move PV.
879 var move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['move'] + "</a>";
880 move_td.innerHTML = move;
881 var score_td = document.createElement("td");
883 score_td.classList.add("score");
884 score_td.textContent = "—";
885 tr.appendChild(score_td);
887 var depth_td = document.createElement("td");
888 tr.appendChild(depth_td);
889 depth_td.classList.add("depth");
890 depth_td.textContent = "—";
892 var pv_td = document.createElement("td");
893 tr.appendChild(pv_td);
894 pv_td.classList.add("pv");
895 pv_td.innerHTML = add_pv(base_fen, base_line.concat([ line['move'] ]), move_num, toplay, scores, start_display_move_num);
901 var move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['move'] + "</a>";
902 move_td.innerHTML = move;
904 var score_td = document.createElement("td");
905 tr.appendChild(score_td);
906 score_td.classList.add("score");
907 score_td.textContent = format_short_score(line['score']);
909 var depth_td = document.createElement("td");
910 tr.appendChild(depth_td);
911 depth_td.classList.add("depth");
912 if (line['depth'] && line['depth'] >= 0) {
913 depth_td.textContent = "d" + line['depth'];
915 depth_td.textContent = "—";
918 var pv_td = document.createElement("td");
919 tr.appendChild(pv_td);
920 pv_td.classList.add("pv");
921 pv_td.innerHTML = add_pv(base_fen, base_line.concat(line['pv']), move_num, toplay, scores, start_display_move_num, 10);
926 // Update the move highlight, as we've rewritten all the HTML.
927 update_move_highlight();
931 * Create a Chess.js board object, containing the given position plus the given moves,
932 * up to the given limit.
934 * @param {?string} fen
935 * @param {Array.<string>} moves
936 * @param {number} last_move
938 var chess_from = function(fen, moves, last_move) {
939 var hiddenboard = new Chess();
940 if (fen !== null && fen !== undefined) {
941 hiddenboard.load(fen);
943 for (var i = 0; i <= last_move; ++i) {
944 if (moves[i] === '0-0') {
945 hiddenboard.move('O-O');
946 } else if (moves[i] === '0-0-0') {
947 hiddenboard.move('O-O-O');
949 hiddenboard.move(moves[i]);
955 var update_game_list = function(games) {
956 document.getElementById("games").textContent = "";
957 if (games === null) {
961 var games_div = document.getElementById('games');
962 for (var game_num = 0; game_num < games.length; ++game_num) {
963 var game = games[game_num];
964 var game_span = document.createElement("span");
965 game_span.setAttribute("class", "game");
967 var game_name = document.createTextNode(game['name']);
968 if (game['url'] === backend_url) {
970 game_span.appendChild(game_name);
972 if (current_analysis_data && current_analysis_data['position']) {
974 if (current_analysis_data['position']['result']) {
975 score = " (" + current_analysis_data['position']['result'] + ")";
977 score = " (" + format_short_score(current_analysis_data['score']) + ")";
979 game_span.appendChild(document.createTextNode(score));
983 var game_a = document.createElement("a");
984 game_a.setAttribute("href", "#" + game['id']);
985 game_a.appendChild(game_name);
986 game_span.appendChild(game_a);
989 if (game['result']) {
990 score = " (" + game['result'] + ")";
992 score = " (" + format_short_score(game['score']) + ")";
994 game_span.appendChild(document.createTextNode(score));
997 games_div.appendChild(game_span);
1002 * Try to find a running game that matches with the current hash,
1003 * and switch to it if we're not already displaying it.
1005 var possibly_switch_game_from_hash = function() {
1006 var history_match = window.location.hash.match(/^#history=([a-zA-Z0-9_-]+)/);
1007 if (history_match !== null) {
1008 var game_id = history_match[1];
1010 url: '/history/' + game_id + '.json',
1012 id: 'history=' + game_id
1014 switch_backend(fake_game);
1018 if (current_games === null) {
1022 var hash = window.location.hash.replace(/^#/,'');
1023 for (var i = 0; i < current_games.length; ++i) {
1024 if (current_games[i]['id'] === hash) {
1025 if (backend_url !== current_games[i]['url']) {
1026 switch_backend(current_games[i]);
1034 * If this is a Chess960 castling which doesn't move the king,
1035 * move the rook instead.
1037 var patch_move = function(move) {
1038 if (move === null) return null;
1039 if (move.from !== move.to) return move;
1041 var f = move.rook_sq & 15;
1042 var r = move.rook_sq >> 4;
1043 var from = ('abcdefgh'.substring(f,f+1) + '87654321'.substring(r,r+1));
1046 if (move.to === 'g1') {
1048 } else if (move.to === 'g8') {
1050 } else if (move.to === 'b1') {
1052 } else if (move.to === 'b8') {
1056 return { from: from, to: to };
1059 /** Update all the HTML on the page, based on current global state.
1061 var update_board = function() {
1062 document.body.style.opacity = null;
1064 var data = displayed_analysis_data || current_analysis_data;
1065 var current_data = current_analysis_data; // Convenience alias.
1069 // Print the history. This is pretty much the only thing that's
1070 // unconditionally taken from current_data (we're not interested in
1071 // historic history).
1072 if (current_data['position']['history']) {
1073 var start = (current_data['position'] && current_data['position']['start_fen']) ? current_data['position']['start_fen'] : 'start';
1074 add_pv(start, current_data['position']['history'], 1, 'W', null, 0, 8, true);
1076 display_lines.push(null);
1080 // Games currently in progress, if any.
1081 if (current_data['games']) {
1082 current_games = current_data['games'];
1083 possibly_switch_game_from_hash();
1085 current_games = null;
1087 update_game_list(current_games);
1089 // The headline. Names are always fetched from current_data;
1090 // the rest can depend a bit.
1093 current_data['position']['player_w'] && current_data['position']['player_b']) {
1094 headline = current_data['position']['player_w'] + '–' +
1095 current_data['position']['player_b'] + ', analysis';
1097 headline = 'Analysis';
1100 // Credits, where applicable. Note that we don't want the footer to change a lot
1101 // when e.g. viewing history, so if any of these changed during the game,
1102 // use the current one still.
1103 if (current_data['using_lomonosov']) {
1104 document.getElementById("lomonosov").style.display = null;
1106 document.getElementById("lomonosov").style.display = 'none';
1109 // Credits: The engine name/version.
1110 if (current_data['engine'] && current_data['engine']['name'] !== null) {
1111 document.getElementById("engineid").textContent = current_data['engine']['name'];
1114 // Credits: The engine URL.
1115 if (current_data['engine'] && current_data['engine']['url']) {
1116 document.getElementById("engineid").setAttribute("href", current_data['engine']['url']);
1118 document.getElementById("engineid").removeAttribute("href");
1121 // Credits: Engine details.
1122 if (current_data['engine'] && current_data['engine']['details']) {
1123 document.getElementById("enginedetails").textContent = " (" + current_data['engine']['details'] + ")";
1125 document.getElementById("enginedetails").textContent = "";
1128 // Credits: Move source, possibly with URL.
1129 if (current_data['move_source'] && current_data['move_source_url']) {
1130 document.getElementById("movesource").textContent = "Moves provided by ";
1131 var movesource_a = document.createElement("a");
1132 movesource_a.setAttribute("href", current_data['move_source_url']);
1133 var movesource_text = document.createTextNode(current_data['move_source']);
1134 movesource_a.appendChild(movesource_text);
1135 var movesource_period = document.createTextNode(".");
1136 document.getElementById("movesource").appendChild(movesource_a);
1137 document.getElementById("movesource").appendChild(movesource_period);
1138 } else if (current_data['move_source']) {
1139 document.getElementById("movesource").textContent = "Moves provided by " + current_data['move_source'] + ".";
1141 document.getElementById("movesource").textContent = "";
1145 if (displayed_analysis_data) {
1146 // Displaying some non-current position, pick out the last move
1147 // from the history. This will work even if the fetch failed.
1148 if (current_display_move !== -1) {
1149 last_move = format_halfmove_with_number(
1150 current_display_line.pv[current_display_move],
1151 current_display_move);
1152 headline += ' after ' + last_move;
1154 } else if (data['position']['last_move'] !== 'none') {
1155 // Find the previous move.
1156 var previous_move_num, previous_toplay;
1157 if (data['position']['toplay'] == 'B') {
1158 previous_move_num = data['position']['move_num'];
1159 previous_toplay = 'W';
1161 previous_move_num = data['position']['move_num'] - 1;
1162 previous_toplay = 'B';
1165 last_move = format_move_with_number(
1166 data['position']['last_move'],
1168 previous_toplay == 'W');
1169 headline += ' after ' + last_move;
1173 document.getElementById("headline").textContent = headline;
1175 // The <title> contains a very brief headline.
1176 var title_elems = [];
1177 if (data['position'] && data['position']['result']) {
1178 title_elems.push(data['position']['result']);
1179 } else if (data['score']) {
1180 title_elems.push(format_short_score(data['score']));
1182 if (last_move !== null) {
1183 title_elems.push(last_move);
1186 if (title_elems.length != 0) {
1187 document.title = '(' + title_elems.join(', ') + ') analysis.sesse.net';
1189 document.title = 'analysis.sesse.net';
1192 // The last move (shown by highlighting the from and to squares).
1193 if (data['position'] && data['position']['last_move_uci']) {
1194 highlight_from = data['position']['last_move_uci'].substr(0, 2);
1195 highlight_to = data['position']['last_move_uci'].substr(2, 2);
1196 } else if (current_display_line_is_history && current_display_line && current_display_move >= 0) {
1197 // We don't have historic analysis for this position, but we
1198 // can reconstruct what the last move was by just replaying
1200 var position = (data['position'] && data['position']['start_fen']) ? data['position']['start_fen'] : null;
1201 var hiddenboard = chess_from(position, current_display_line.pv, current_display_move);
1202 var moves = hiddenboard.history({ verbose: true });
1203 last_move = moves.pop();
1204 highlight_from = last_move.from;
1205 highlight_to = last_move.to;
1207 highlight_from = highlight_to = undefined;
1209 update_board_highlight();
1211 if (data['failed']) {
1212 document.getElementById("score").textContent = "No analysis for this move";
1213 document.getElementById("pvtitle").textContent = "PV:";
1214 document.getElementById("pv").replaceChildren();
1215 document.getElementById("searchstats").innerHTML = " ";
1216 document.getElementById("refutationlines").replaceChildren();
1217 document.getElementById("whiteclock").replaceChildren();
1218 document.getElementById("blackclock").replaceChildren();
1219 refutation_lines = [];
1220 update_refutation_lines();
1222 update_displayed_line();
1223 update_move_highlight();
1230 if (current_display_line && !current_display_line_is_history) {
1232 if (current_display_line.scores && current_display_line.scores.length > 0) {
1233 for (var i = 0; i < current_display_line.scores.length; ++i) {
1234 if (current_display_move < current_display_line.scores[i].first_move) {
1237 score = current_display_line.scores[i].score;
1241 document.getElementById("score").textContent = format_long_score(score);
1243 document.getElementById("score").textContent = "No score for this line";
1245 } else if (data['score']) {
1246 document.getElementById("score").textContent = format_long_score(data['score']);
1249 // The search stats.
1250 if (data['searchstats']) {
1251 document.getElementById("searchstats").innerHTML = data['searchstats'];
1252 } else if (data['tablebase'] == 1) {
1253 document.getElementById("searchstats").textContent = "Tablebase result";
1254 } else if (data['nodes'] && data['nps'] && data['depth']) {
1255 var stats = thousands(data['nodes']) + ' nodes, ' + thousands(data['nps']) + ' nodes/sec, depth ' + data['depth'] + ' ply';
1256 if (data['seldepth']) {
1257 stats += ' (' + data['seldepth'] + ' selective)';
1259 if (data['tbhits'] && data['tbhits'] > 0) {
1260 if (data['tbhits'] == 1) {
1261 stats += ', one Syzygy hit';
1263 stats += ', ' + thousands(data['tbhits']) + ' Syzygy hits';
1267 document.getElementById("searchstats").textContent = stats;
1269 document.getElementById("searchstats").textContent = "";
1272 // Update the board itself.
1273 base_fen = data['position']['fen'];
1274 update_displayed_line();
1277 document.getElementById("pvtitle").textContent = "PV:";
1279 var scores = [{ first_move: -1, score: data['score'] }];
1280 document.getElementById("pv").innerHTML = add_pv(data['position']['fen'], data['pv'], data['position']['move_num'], data['position']['toplay'], scores, 0);
1282 // Update the PV arrow.
1284 if (data['pv'].length >= 1) {
1285 var hiddenboard = new Chess(base_fen);
1287 // draw a continuation arrow as long as it's the same piece
1289 for (var i = 0; i < data['pv'].length; i += 2) {
1290 var move = patch_move(hiddenboard.move(data['pv'][i]));
1292 if ((i >= 2 && move.from != last_to) ||
1293 interfering_arrow(move.from, move.to)) {
1296 create_arrow(move.from, move.to, '#f66', 6, 20);
1298 hiddenboard.move(data['pv'][i + 1]); // To keep continuity.
1301 var alt_moves = find_nonstupid_moves(data, 30, data['position']['toplay'] === 'B');
1302 for (var i = 1; i < alt_moves.length && i < 3; ++i) {
1303 hiddenboard = new Chess(base_fen);
1304 var move = patch_move(hiddenboard.move(alt_moves[i]));
1305 if (move !== null) {
1306 create_arrow(move.from, move.to, '#f66', 1, 10);
1311 // See if all semi-reasonable moves have only one possible response.
1312 if (data['pv'].length >= 2) {
1313 var nonstupid_moves = find_nonstupid_moves(data, 300, data['position']['toplay'] === 'B');
1316 var hiddenboard = new Chess(base_fen);
1317 hiddenboard.move(data['pv'][0]);
1318 response = hiddenboard.move(data['pv'][1]);
1320 for (var i = 0; i < nonstupid_moves.length; ++i) {
1321 if (nonstupid_moves[i] == data['pv'][0]) {
1322 // ignore the PV move for refutation lines.
1325 if (!data['refutation_lines'] ||
1326 !data['refutation_lines'][nonstupid_moves[i]] ||
1327 !data['refutation_lines'][nonstupid_moves[i]]['pv'] ||
1328 data['refutation_lines'][nonstupid_moves[i]]['pv'].length < 2) {
1329 // Incomplete PV, abort.
1330 response = undefined;
1333 var line = data['refutation_lines'][nonstupid_moves[i]];
1334 hiddenboard = new Chess(base_fen);
1335 hiddenboard.move(line['pv'][0]);
1336 var this_response = hiddenboard.move(line['pv'][1]);
1337 if (this_response === null) {
1338 console.log("BUG: ", i);
1340 console.log(line['pv']);
1342 if (response.from !== this_response.from || response.to !== this_response.to) {
1343 // Different response depending on lines, abort.
1344 response = undefined;
1349 if (nonstupid_moves.length > 0 && response !== undefined) {
1350 create_arrow(response.from, response.to, '#66f', 6, 20);
1354 // Update the refutation lines.
1355 base_fen = data['position']['fen'];
1356 move_num = parseInt(data['position']['move_num']);
1357 toplay = data['position']['toplay'];
1358 refutation_lines = hash_refutation_lines || data['refutation_lines'];
1359 update_refutation_lines();
1361 // Update the sparkline last, since its size depends on how everything else reflowed.
1362 update_sparkline(data);
1365 var update_sparkline = function(data) {
1366 if (data && data['score_history']) {
1367 var first_move_num = undefined;
1368 for (var halfmove_num in data['score_history']) {
1369 halfmove_num = parseInt(halfmove_num);
1370 if (first_move_num === undefined || halfmove_num < first_move_num) {
1371 first_move_num = halfmove_num;
1374 if (first_move_num !== undefined) {
1375 var last_move_num = data['position']['move_num'] * 2 - 3;
1376 if (data['position']['toplay'] === 'B') {
1380 // Possibly truncate some moves if we don't have enough width.
1381 // FIXME: Sometimes width() for #scorecontainer (and by extent,
1382 // #scoresparkcontainer) on Chrome for mobile seems to start off
1383 // at something very small, and then suddenly snap back into place.
1385 var max_moves = Math.floor(document.getElementById("scoresparkcontainer").getBoundingClientRect().width / 5) - 5;
1386 if (last_move_num - first_move_num > max_moves) {
1387 first_move_num = last_move_num - max_moves;
1390 var min_score = -100;
1391 var max_score = 100;
1392 var last_score = null;
1394 for (var halfmove_num = first_move_num; halfmove_num <= last_move_num; ++halfmove_num) {
1395 if (data['score_history'][halfmove_num]) {
1396 var score = compute_plot_score(data['score_history'][halfmove_num]);
1398 if (score < min_score) min_score = score;
1399 if (score > max_score) max_score = score;
1401 scores.push(last_score);
1403 if (data['score']) {
1404 scores.push(compute_plot_score(data['score']));
1406 // FIXME: at some widths, calling sparkline() seems to push
1407 // #scorecontainer under the board.
1408 $('#scorespark').unbind('sparklineClick');
1409 $('#scorespark').sparkline(scores, {
1412 chartRangeMin: min_score,
1413 chartRangeMax: max_score,
1414 tooltipFormatter: function(sparkline, options, fields) {
1415 // score_history contains the Nth _position_, but format_tooltip
1416 // wants to format the Nth _move_; thus the -1.
1417 return format_tooltip(data, fields[0].offset + first_move_num - 1);
1420 $('#scorespark').unbind('sparklineClick');
1421 $('#scorespark').bind('sparklineClick', function(event) {
1422 var sparkline = event.sparklines[0];
1423 var region = sparkline.getCurrentRegionFields();
1424 if (region[0].offset !== undefined) {
1425 show_line(0, first_move_num + region[0].offset - 1);
1429 document.getElementById("scorespark").textContent = "";
1432 document.getElementById("scorespark").textContent = "";
1437 * @param {number} num_viewers
1439 var update_num_viewers = function(num_viewers) {
1441 if (num_viewers === null) {
1443 } else if (num_viewers == 1) {
1444 text = "You are the only current viewer";
1446 text = num_viewers + " current viewers";
1448 if (display_fen !== null) {
1449 var counter = Math.floor(display_fen.split(" ")[4] / 2);
1450 if (counter >= 20) {
1451 text = text.replace("current ", "");
1452 text += " | 50-move rule: " + counter;
1455 document.getElementById("numviewers").textContent = text;
1458 var update_clock = function() {
1459 clearTimeout(clock_timer);
1461 var data = displayed_analysis_data || current_analysis_data;
1464 if (data['position']) {
1465 var result = data['position']['result'];
1466 if (result === '1-0') {
1467 document.getElementById("whiteclock").textContent = "1";
1468 document.getElementById("blackclock").textContent = "0";
1469 document.getElementById("whiteclock").classList.remove("running-clock");
1470 document.getElementById("blackclock").classList.remove("running-clock");
1473 if (result === '1/2-1/2') {
1474 document.getElementById("whiteclock").textContent = "1/2";
1475 document.getElementById("blackclock").textContent = "1/2";
1476 document.getElementById("whiteclock").classList.remove("running-clock");
1477 document.getElementById("blackclock").classList.remove("running-clock");
1480 if (result === '0-1') {
1481 document.getElementById("whiteclock").textContent = "0";
1482 document.getElementById("blackclock").textContent = "1";
1483 document.getElementById("whiteclock").classList.remove("running-clock");
1484 document.getElementById("blackclock").classList.remove("running-clock");
1489 var white_clock_ms = null;
1490 var black_clock_ms = null;
1493 if (data['position'] &&
1494 data['position']['white_clock'] &&
1495 data['position']['black_clock']) {
1496 white_clock_ms = data['position']['white_clock'] * 1000;
1497 black_clock_ms = data['position']['black_clock'] * 1000;
1500 // Dynamic clock (only one, obviously).
1502 if (data['position']['white_clock_target']) {
1504 document.getElementById("whiteclock").classList.add("running-clock");
1505 document.getElementById("blackclock").classList.remove("running-clock");
1506 } else if (data['position']['black_clock_target']) {
1508 document.getElementById("whiteclock").classList.remove("running-clock");
1509 document.getElementById("blackclock").classList.add("running-clock");
1511 document.getElementById("whiteclock").classList.remove("running-clock");
1512 document.getElementById("blackclock").classList.remove("running-clock");
1516 var now = new Date().getTime() + client_clock_offset_ms;
1517 remaining_ms = data['position'][color + '_clock_target'] * 1000 - now;
1518 if (color === "white") {
1519 white_clock_ms = remaining_ms;
1521 black_clock_ms = remaining_ms;
1525 if (white_clock_ms === null || black_clock_ms === null) {
1526 document.getElementById("whiteclock").replaceChildren();
1527 document.getElementById("blackclock").replaceChildren();
1531 // If either player has twenty minutes or less left, add the second counters.
1532 // This matches what DGT clocks do.
1533 var show_seconds = (white_clock_ms < 60 * 20 * 1000 || black_clock_ms < 60 * 20 * 1000);
1536 // See when the clock will change next, and update right after that.
1539 next_update_ms = remaining_ms % 1000 + 100;
1541 next_update_ms = remaining_ms % 60000 + 100;
1543 clock_timer = setTimeout(update_clock, next_update_ms);
1546 document.getElementById("whiteclock").textContent = format_clock(white_clock_ms, show_seconds);
1547 document.getElementById("blackclock").textContent = format_clock(black_clock_ms, show_seconds);
1551 * @param {Number} remaining_ms
1552 * @param {boolean} show_seconds
1554 var format_clock = function(remaining_ms, show_seconds) {
1555 if (remaining_ms <= 0) {
1563 var remaining = Math.floor(remaining_ms / 1000);
1564 var seconds = remaining % 60;
1565 remaining = (remaining - seconds) / 60;
1566 var minutes = remaining % 60;
1567 remaining = (remaining - minutes) / 60;
1568 var hours = remaining;
1570 return format_2d(hours) + ":" + format_2d(minutes) + ":" + format_2d(seconds);
1572 return format_2d(hours) + ":" + format_2d(minutes);
1579 var format_2d = function(x) {
1588 * @param {string} move
1589 * @param {Number} move_num Move number of this move.
1590 * @param {boolean} white_to_play Whether white is to play this move.
1592 var format_move_with_number = function(move, move_num, white_to_play) {
1594 if (white_to_play) {
1595 ret = move_num + '. ';
1597 ret = move_num + '… ';
1604 * @param {string} move
1605 * @param {Number} halfmove_num Half-move number that is to be played,
1608 var format_halfmove_with_number = function(move, halfmove_num) {
1609 return format_move_with_number(
1611 Math.floor(halfmove_num / 2) + 1,
1612 halfmove_num % 2 == 0);
1616 * @param {Object} data
1617 * @param {Number} halfmove_num
1619 var format_tooltip = function(data, halfmove_num) {
1620 if (data['score_history'][halfmove_num + 1] ||
1621 (halfmove_num + 1) === data['position']['history'].length) {
1622 // Position is in the history, or it is the current position
1623 // (which is implicitly tacked onto the history).
1626 if ((halfmove_num + 1) === data['position']['history'].length) {
1627 move = data['position']['last_move'];
1628 short_score = format_short_score(data['score']);
1630 move = data['position']['history'][halfmove_num];
1631 short_score = format_short_score(data['score_history'][halfmove_num + 1]);
1633 if (halfmove_num === -1) {
1634 return "Start position: " + short_score;
1636 var move_with_number = format_halfmove_with_number(move, halfmove_num);
1637 return "After " + move_with_number + ": " + short_score;
1640 for (var i = halfmove_num; i --> -1; ) {
1641 if (data['score_history'][i]) {
1642 var move = data['position']['history'][i];
1644 return "[Analysis kept from start position]";
1646 return "[Analysis kept from " + format_halfmove_with_number(move, i) + "]";
1654 * @param {boolean} truncate_history
1656 var set_truncate_history = function(truncate_history) {
1657 truncate_display_history = truncate_history;
1658 update_refutation_lines();
1660 window['set_truncate_history'] = set_truncate_history;
1663 * @param {number} line_num
1664 * @param {number} move_num
1666 var show_line = function(line_num, move_num) {
1667 if (line_num == -1) {
1668 current_display_line = null;
1669 current_display_move = null;
1670 hash_refutation_lines = null;
1671 if (displayed_analysis_data) {
1672 // TODO: Support exiting to history position if we are in an
1673 // analysis line of a history position.
1674 displayed_analysis_data = null;
1679 current_display_line = jQuery.extend({}, display_lines[line_num]); // Shallow clone.
1680 current_display_move = move_num + current_display_line.start_display_move_num;
1682 current_display_line_is_history = (line_num == 0);
1684 update_historic_analysis();
1685 update_displayed_line();
1686 update_board_highlight();
1687 update_move_highlight();
1690 window['show_line'] = show_line;
1692 var prev_move = function() {
1693 if (current_display_line &&
1694 current_display_move >= current_display_line.start_display_move_num) {
1695 --current_display_move;
1697 update_historic_analysis();
1698 update_displayed_line();
1699 update_move_highlight();
1701 window['prev_move'] = prev_move;
1703 var next_move = function() {
1704 if (current_display_line &&
1705 current_display_move < current_display_line.pv.length - 1) {
1706 ++current_display_move;
1708 update_historic_analysis();
1709 update_displayed_line();
1710 update_move_highlight();
1712 window['next_move'] = next_move;
1714 var next_game = function() {
1715 if (current_games === null) {
1719 // Try to find the game we are currently looking at.
1720 for (var game_num = 0; game_num < current_games.length; ++game_num) {
1721 var game = current_games[game_num];
1722 if (game['url'] === backend_url) {
1723 var next_game_num = (game_num + 1) % current_games.length;
1724 switch_backend(current_games[next_game_num]);
1729 // Couldn't find it; give up.
1732 var update_historic_analysis = function() {
1733 if (!current_display_line_is_history) {
1736 if (current_display_move == current_display_line.pv.length - 1) {
1737 displayed_analysis_data = null;
1741 // Fetch old analysis for this line if it exists.
1742 var hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pv, current_display_move);
1743 var filename = "/history/move" + (current_display_move + 1) + "-" +
1744 hiddenboard.fen().replace(/ /g, '_').replace(/\//g, '-') + ".json";
1746 let handle_err = () => {
1747 displayed_analysis_data = {'failed': true};
1751 current_historic_xhr = new AbortController();
1752 const signal = current_analysis_xhr.signal;
1753 fetch(filename, { signal })
1754 .then((response) => response.json().then(data => ({ok: response.ok, json: data}))) // ick
1760 displayed_analysis_data = obj.json;
1764 if (err.name === 'AbortError') {
1765 // Aborted because we are switching backends. Abandon and don't retry,
1766 // because another one is already started for us.
1775 * @param {string} fen
1777 var update_imbalance = function(fen) {
1778 var hiddenboard = new Chess(fen);
1779 var imbalance = {'k': 0, 'q': 0, 'r': 0, 'b': 0, 'n': 0, 'p': 0};
1780 for (var row = 0; row < 8; ++row) {
1781 for (var col = 0; col < 8; ++col) {
1782 var col_text = String.fromCharCode('a1'.charCodeAt(0) + col);
1783 var row_text = String.fromCharCode('a1'.charCodeAt(1) + row);
1784 var square = col_text + row_text;
1785 var contents = hiddenboard.get(square);
1786 if (contents !== null) {
1787 if (contents.color === 'w') {
1788 ++imbalance[contents.type];
1790 --imbalance[contents.type];
1795 var white_imbalance = '';
1796 var black_imbalance = '';
1797 for (var piece in imbalance) {
1798 for (var i = 0; i < imbalance[piece]; ++i) {
1799 white_imbalance += '<img src="' + svg_pieces['w' + piece.toUpperCase()] + '" alt="" style="width: 15px;height: 15px;" class="imbalance-piece">';
1800 white_imbalance += '<img src="' + svg_pieces['b' + piece.toUpperCase()] + '" alt="" style="width: 15px;height: 15px;" class="imbalance-inverted-piece">';
1802 for (var i = 0; i < -imbalance[piece]; ++i) {
1803 black_imbalance += '<img src="' + svg_pieces['b' + piece.toUpperCase()] + '" alt="" style="width: 15px;height: 15px;" class="imbalance-piece">';
1804 black_imbalance += '<img src="' + svg_pieces['w' + piece.toUpperCase()] + '" alt="" style="width: 15px;height: 15px;" class="imbalance-inverted-piece">';
1807 document.getElementById('whiteimbalance').innerHTML = white_imbalance;
1808 document.getElementById('blackimbalance').innerHTML = black_imbalance;
1811 /** Mark the currently selected move in red.
1812 * Also replaces the PV with the current displayed line if it's not shown
1813 * anywhere else on the screen.
1815 var update_move_highlight = function() {
1816 if (highlighted_move !== null) {
1817 highlighted_move.classList.remove('highlight');
1819 if (current_display_line) {
1820 var display_line_num = find_display_line_matching_num();
1821 if (display_line_num === null) {
1822 // Replace the PV with the (complete) line.
1823 document.getElementById("pvtitle").textContent = "Exploring:";
1824 current_display_line.start_display_move_num = 0;
1825 display_lines.push(current_display_line);
1826 document.getElementById("pv").innerHTML = print_pv(display_lines.length - 1, null); // FIXME
1827 display_line_num = display_lines.length - 1;
1829 // Clear out the PV, so it's not selected by anything later.
1830 display_lines[1].pv = [];
1833 highlighted_move = document.getElementById("automove" + display_line_num + "-" + (current_display_move - current_display_line.start_display_move_num));
1834 if (highlighted_move !== null) {
1835 highlighted_move.classList.add('highlight');
1841 * See if the current displayed line is identical to any of the ones
1842 * we have on screen. (It might not be if e.g. the analysis reloaded
1843 * since we started looking.)
1847 var find_display_line_matching_num = function() {
1848 for (var i = 0; i < display_lines.length; ++i) {
1849 var line = display_lines[i];
1850 if (line.start_display_move_num > 0) continue;
1851 if (current_display_line.start_fen !== line.start_fen) continue;
1852 if (current_display_line.pv.length !== line.pv.length) continue;
1854 for (var j = 0; j < line.pv.length; ++j) {
1855 if (current_display_line.pv[j] !== line.pv[j]) {
1867 /** Update the board based on the currently displayed line.
1869 * TODO: This should really be called only whenever something changes,
1870 * instead of all the time.
1872 var update_displayed_line = function() {
1873 if (current_display_line === null) {
1874 document.getElementById("linenav").style.display = 'none';
1875 document.getElementById("linemsg").style.display = 'revert';
1876 display_fen = base_fen;
1877 set_board_position(base_fen);
1878 update_imbalance(base_fen);
1882 document.getElementById("linenav").style.display = 'revert';
1883 document.getElementById("linemsg").style.display = 'none';
1885 if (current_display_move <= 0) {
1886 document.getElementById("prevmove").innerHTML = "Previous";
1888 document.getElementById("prevmove").innerHTML = "<a href=\"javascript:prev_move();\">Previous</a></span>";
1890 if (current_display_move == current_display_line.pv.length - 1) {
1891 document.getElementById("nextmove").innerHTML = "Next";
1893 document.getElementById("nextmove").innerHTML = "<a href=\"javascript:next_move();\">Next</a></span>";
1896 var hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pv, current_display_move);
1897 set_board_position(hiddenboard.fen());
1898 if (display_fen !== hiddenboard.fen() && !current_display_line_is_history) {
1899 // Fire off a hash request, since we're now off the main position
1900 // and it just changed.
1901 explore_hash(hiddenboard.fen());
1903 display_fen = hiddenboard.fen();
1904 update_imbalance(hiddenboard.fen());
1907 var set_board_position = function(new_fen) {
1908 board_is_animating = true;
1909 var old_fen = board.fen();
1910 board.position(new_fen);
1911 if (board.fen() === old_fen) {
1912 board_is_animating = false;
1917 * @param {boolean} param_enable_sound
1919 var set_sound = function(param_enable_sound) {
1920 enable_sound = param_enable_sound;
1922 document.getElementById("soundon").innerHTML = "<strong>On</strong>";
1923 document.getElementById("soundoff").innerHTML = "<a href=\"javascript:set_sound(false)\">Off</a>";
1925 // Seemingly at least Firefox prefers MP3 over Opus; tell it otherwise,
1926 // and also preload the file since the user has selected audio.
1927 var ding = document.getElementById('ding');
1928 if (ding && ding.canPlayType && ding.canPlayType('audio/ogg; codecs="opus"') === 'probably') {
1929 ding.src = 'ding.opus';
1933 document.getElementById("soundon").innerHTML = "<a href=\"javascript:set_sound(true)\">On</a>";
1934 document.getElementById("soundoff").innerHTML = "<strong>Off</strong>";
1936 if (supports_html5_storage()) {
1937 localStorage['enable_sound'] = enable_sound ? 1 : 0;
1940 window['set_sound'] = set_sound;
1942 /** Send off a hash probe request to the backend.
1943 * @param {string} fen
1945 var explore_hash = function(fen) {
1946 // If we already have a backend response going, abort it.
1947 if (current_hash_xhr) {
1948 current_hash_xhr.abort();
1950 if (current_hash_display_timer) {
1951 clearTimeout(current_hash_display_timer);
1952 current_hash_display_timer = null;
1954 document.getElementById("refutationlines").replaceChildren();
1956 current_hash_xhr = new AbortController();
1957 const signal = current_analysis_xhr.signal;
1958 fetch(backend_hash_url + "?fen=" + fen, { signal })
1959 .then((response) => response.json())
1960 .then((data) => { show_explore_hash_results(data, fen); });
1963 /** Process the JSON response from a hash probe request.
1964 * @param {!Object} data
1965 * @param {string} fen
1967 var show_explore_hash_results = function(data, fen) {
1968 if (board_is_animating) {
1969 // Updating while the animation is still going causes
1970 // the animation to jerk. This is pretty crude, but it will do.
1971 current_hash_display_timer = setTimeout(function() { show_explore_hash_results(data, fen); }, 100);
1974 current_hash_display_timer = null;
1975 hash_refutation_lines = data['lines'];
1979 // almost all of this stuff comes from the chessboard.js example page
1980 var onDragStart = function(source, piece, position, orientation) {
1981 var pseudogame = new Chess(display_fen);
1982 if (pseudogame.game_over() === true ||
1983 (pseudogame.turn() === 'w' && piece.search(/^b/) !== -1) ||
1984 (pseudogame.turn() === 'b' && piece.search(/^w/) !== -1)) {
1988 recommended_move = get_best_move(pseudogame, source, null, pseudogame.turn() === 'b');
1989 if (recommended_move) {
1990 var squareEl = document.querySelector('#board .square-' + recommended_move.to);
1991 squareEl.classList.add('highlight1-32417');
1996 var mousedownSquare = function(e) {
1997 if (!e.target || !e.target.matches('.square-55d63')) {
2001 reverse_dragging_from = null;
2002 var square = e.target.getAttribute('data-square');
2004 var pseudogame = new Chess(display_fen);
2005 if (pseudogame.game_over() === true) {
2009 // If the square is empty, or has a piece of the side not to move,
2010 // we handle it. If not, normal piece dragging will take it.
2011 var position = board.position();
2012 if (!position.hasOwnProperty(square) ||
2013 (pseudogame.turn() === 'w' && position[square].search(/^b/) !== -1) ||
2014 (pseudogame.turn() === 'b' && position[square].search(/^w/) !== -1)) {
2015 reverse_dragging_from = square;
2016 recommended_move = get_best_move(pseudogame, null, square, pseudogame.turn() === 'b');
2017 if (recommended_move) {
2018 var squareEl = document.querySelector('#board .square-' + recommended_move.from);
2019 squareEl.classList.add('highlight1-32417');
2020 squareEl = document.querySelector('#board .square-' + recommended_move.to);
2021 squareEl.classList.add('highlight1-32417');
2026 var mouseupSquare = function(e) {
2027 if (!e.target || !e.target.matches('.square-55d63')) {
2030 if (reverse_dragging_from === null) {
2033 var source = e.target.getAttribute('data-square');
2034 var target = reverse_dragging_from;
2035 reverse_dragging_from = null;
2036 if (onDrop(source, target) !== 'snapback') {
2037 onSnapEnd(source, target);
2039 document.getElementById("board").querySelectorAll('.square-55d63.highlight1-32417').forEach((square) => {
2040 square.classList.remove('highlight1-32417');
2044 var get_best_move = function(game, source, target, invert) {
2045 var moves = game.moves({ verbose: true });
2046 if (source !== null) {
2047 moves = moves.filter(function(move) { return move.from == source; });
2049 if (target !== null) {
2050 moves = moves.filter(function(move) { return move.to == target; });
2052 if (moves.length == 0) {
2055 if (moves.length == 1) {
2059 // More than one move. Use the display lines (if we have them)
2060 // to disambiguate; otherwise, we have no information.
2062 for (var i = 0; i < moves.length; ++i) {
2063 move_hash[moves[i].san] = moves[i];
2066 // See if we're already exploring some line.
2067 if (current_display_line &&
2068 current_display_move < current_display_line.pv.length - 1) {
2069 var first_move = current_display_line.pv[current_display_move + 1];
2070 if (move_hash[first_move]) {
2071 return move_hash[first_move];
2075 // History and PV take priority over the display lines.
2076 for (var i = 0; i < 2; ++i) {
2077 var line = display_lines[i];
2078 var first_move = line.pv[line.start_display_move_num];
2079 if (move_hash[first_move]) {
2080 return move_hash[first_move];
2084 var best_move = null;
2085 var best_move_score = null;
2087 for (var move in refutation_lines) {
2088 var line = refutation_lines[move];
2089 if (!line['score']) {
2092 var first_move = line['pv'][0];
2093 if (move_hash[first_move]) {
2094 var score = compute_score_sort_key(line['score'], line['depth'], invert);
2095 if (best_move_score === null || score > best_move_score) {
2096 best_move = move_hash[first_move];
2097 best_move_score = score;
2104 var onDrop = function(source, target) {
2105 if (source === target) {
2106 if (recommended_move === null) {
2109 // Accept the move. It will be changed in onSnapEnd.
2113 // Suggestion not asked for.
2114 recommended_move = null;
2117 // see if the move is legal
2118 var pseudogame = new Chess(display_fen);
2119 var move = pseudogame.move({
2122 promotion: 'q' // NOTE: always promote to a queen for example simplicity
2126 if (move === null) return 'snapback';
2129 var onSnapEnd = function(source, target) {
2130 if (source === target && recommended_move !== null) {
2131 source = recommended_move.from;
2132 target = recommended_move.to;
2134 recommended_move = null;
2135 var pseudogame = new Chess(display_fen);
2136 var move = pseudogame.move({
2139 promotion: 'q' // NOTE: always promote to a queen for example simplicity
2142 if (current_display_line &&
2143 current_display_move < current_display_line.pv.length - 1 &&
2144 current_display_line.pv[current_display_move + 1] === move.san) {
2149 // Walk down the displayed lines until we find one that starts with
2150 // this move, then select that. Note that this gives us a good priority
2151 // order (history first, then PV, then multi-PV lines).
2152 for (var i = 0; i < display_lines.length; ++i) {
2153 if (i == 1 && current_display_line) {
2154 // Do not choose PV if not on it.
2157 var line = display_lines[i];
2158 if (line.pv[line.start_display_move_num] === move.san) {
2164 // Shouldn't really be here if we have hash probes, but there's really
2165 // nothing we can do.
2167 // End of dragging-related code.
2169 var fmt_cp = function(v) {
2173 return "+" + (v / 100).toFixed(2);
2176 return "-" + (v / 100).toFixed(2);
2180 var format_short_score = function(score) {
2184 if (score[0] === 'T' || score[0] === 't') {
2185 var ret = "TB\u00a0";
2186 if (score[2]) { // Is a bound.
2187 ret = score[2] + "\u00a0TB\u00a0";
2189 if (score[0] === 'T') {
2190 return ret + Math.ceil(score[1] / 2);
2192 return ret + "-" + Math.ceil(score[1] / 2);
2194 } else if (score[0] === 'M' || score[0] === 'm') {
2195 var sign = (score[0] === 'm') ? '-' : '';
2196 if (score[2]) { // Is a bound.
2197 return score[2] + "\u00a0M " + sign + score[1];
2199 return "M " + sign + score[1];
2201 } else if (score[0] === 'd') {
2203 } else if (score[0] === 'cp') {
2204 if (score[2]) { // Is a bound.
2205 return score[2] + "\u00a0" + fmt_cp(score[1]);
2207 return fmt_cp(score[1]);
2213 var format_long_score = function(score) {
2217 if (score[0] === 'T') {
2218 if (score[1] == 0) {
2219 return "Won for white (tablebase)";
2221 return "White wins in " + Math.ceil(score[1] / 2);
2223 } else if (score[0] === 't') {
2224 if (score[1] == -1) {
2225 return "Won for black (tablebase)";
2227 return "Black wins in " + Math.ceil(score[1] / 2);
2229 } else if (score[0] === 'M') {
2230 if (score[1] == 0) {
2231 return "White wins by checkmate";
2233 return "White mates in " + score[1];
2235 } else if (score[0] === 'm') {
2236 if (score[1] == 0) {
2237 return "Black wins by checkmate";
2239 return "Black mates in " + score[1];
2241 } else if (score[0] === 'd') {
2242 return "Theoretical draw";
2243 } else if (score[0] === 'cp') {
2244 return "Score: " + format_short_score(score);
2249 var compute_plot_score = function(score) {
2250 if (score[0] === 'M' || score[0] === 'T') {
2252 } else if (score[0] === 'm' || score[0] === 't') {
2254 } else if (score[0] === 'd') {
2256 } else if (score[0] === 'cp') {
2257 if (score[1] > 500) {
2259 } else if (score[1] < -500) {
2269 * @param score The score digest tuple.
2270 * @param {?number} depth Depth the move has been computed to, or null.
2271 * @param {boolean} invert Whether black is to play.
2272 * @param {boolean=} depth_secondary_key
2275 var compute_score_sort_key = function(score, depth, invert, depth_secondary_key) {
2280 if (score[0] === 'T') {
2281 // White reaches TB win.
2282 s = 89999 - score[1];
2283 } else if (score[0] === 't') {
2284 // Black reaches TB win.
2285 s = -(89999 - score[1]);
2286 } else if (score[0] === 'M') {
2288 s = 99999 - score[1];
2289 } else if (score[0] === 'm') {
2291 s = -(99999 - score[1]);
2292 } else if (score[0] === 'd') {
2294 } else if (score[0] === 'cp') {
2299 if (depth_secondary_key) {
2300 return s * 200 + (depth || 0);
2310 * @param {Object} game
2312 var switch_backend = function(game) {
2313 // Stop looking at historic data.
2314 current_display_line = null;
2315 current_display_move = null;
2316 displayed_analysis_data = null;
2317 if (current_historic_xhr) {
2318 current_historic_xhr.abort();
2321 // If we already have a backend response going, abort it.
2322 if (current_analysis_xhr) {
2323 current_analysis_xhr.abort();
2325 if (current_hash_xhr) {
2326 current_hash_xhr.abort();
2329 // Otherwise, we should have a timer going to start a new one.
2331 if (current_analysis_request_timer) {
2332 clearTimeout(current_analysis_request_timer);
2333 current_analysis_request_timer = null;
2335 if (current_hash_display_timer) {
2336 clearTimeout(current_hash_display_timer);
2337 current_hash_display_timer = null;
2340 // Request an immediate fetch with the new backend.
2341 backend_url = game['url'];
2342 backend_hash_url = game['hashurl'];
2343 window.location.hash = '#' + game['id'];
2344 current_analysis_data = null;
2348 window['switch_backend'] = switch_backend;
2350 window['flip'] = function() { board.flip(); redraw_arrows(); };
2351 window['set_delay_ms'] = function(ms) { delay_ms = ms; console.log('Delay is now ' + ms + ' ms.'); };
2353 // Mostly from Wikipedia's chess set as of October 2022, but some pieces are from
2354 // the 2013 version, as I like those better (and it matches the 2014 PNGs; nobody
2355 // really likes change, do they?). That is wK, bK, bQ. wQ is also slightly different,
2356 // but not enough to notice.
2357 const svg_pieces = {
2358 'wK': 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSI0NSIgaGVpZ2h0PSI0NSI+CiAgPGcgc3R5bGU9ImZpbGw6bm9uZTsgZmlsbC1vcGFjaXR5OjE7IGZpbGwtcnVsZTpldmVub2RkOyBzdHJva2U6IzAwMDAwMDsgc3Ryb2tlLXdpZHRoOjEuNTsgc3Ryb2tlLWxpbmVjYXA6cm91bmQ7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS1taXRlcmxpbWl0OjQ7IHN0cm9rZS1kYXNoYXJyYXk6bm9uZTsgc3Ryb2tlLW9wYWNpdHk6MTsiPgogICAgPHBhdGgKICAgICAgZD0iTSAyMi41LDExLjYzIEwgMjIuNSw2IgogICAgICBzdHlsZT0iZmlsbDpub25lOyBzdHJva2U6IzAwMDAwMDsgc3Ryb2tlLWxpbmVqb2luOm1pdGVyOyIgLz4KICAgIDxwYXRoCiAgICAgIGQ9Ik0gMjAsOCBMIDI1LDgiCiAgICAgIHN0eWxlPSJmaWxsOm5vbmU7IHN0cm9rZTojMDAwMDAwOyBzdHJva2UtbGluZWpvaW46bWl0ZXI7IiAvPgogICAgPHBhdGgKICAgICAgZD0iTSAyMi41LDI1IEMgMjIuNSwyNSAyNywxNy41IDI1LjUsMTQuNSBDIDI1LjUsMTQuNSAyNC41LDEyIDIyLjUsMTIgQyAyMC41LDEyIDE5L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EzIGMgMCwtMi4yMSAtMS43OSwtNCAtNCwtNCB6IiBzdHlsZT0ib3BhY2l0eToxOyBmaWxsOiMwMDAwMDA7IGZpbGwtb3BhY2l0eToxOyBmaWxsLXJ1bGU6bm9uemVybzsgc3Ryb2tlOiMwMDAwMDA7IHN0cm9rZS13aWR0aDoxLjU7IHN0cm9rZS1saW5lY2FwOnJvdW5kOyBzdHJva2UtbGluZWpvaW46bWl0ZXI7IHN0cm9rZS1taXRlcmxpbWl0OjQ7IHN0cm9rZS1kYXNoYXJyYXk6bm9uZTsgc3Ryb2tlLW9wYWNpdHk6MTsiLz4KPC9zdmc+Cg==',
2372 var svg_piece_theme = function(piece) {
2373 return svg_pieces[piece];
2376 var init = function() {
2377 unique = get_unique();
2379 // Load settings from HTML5 local storage if available.
2380 if (supports_html5_storage() && localStorage['enable_sound']) {
2381 set_sound(parseInt(localStorage['enable_sound']));
2387 board = new window.ChessBoard('board', {
2388 onMoveEnd: function() { board_is_animating = false; },
2391 pieceTheme: svg_piece_theme,
2392 onDragStart: onDragStart,
2394 onSnapEnd: onSnapEnd
2396 document.getElementById("board").addEventListener('mousedown', mousedownSquare);
2397 document.getElementById("board").addEventListener('mouseup', mouseupSquare);
2400 window.addEventListener('resize', function() {
2402 update_sparkline(displayed_analysis_data || current_analysis_data);
2403 update_board_highlight();
2406 window.addEventListener('keyup', function(event) {
2407 if (event.which == 39) { // Left arrow.
2409 } else if (event.which == 37) { // Right arrow.
2411 } else if (event.which >= 49 && event.which <= 57) { // 1-9.
2412 var num = event.which - 49;
2413 if (current_games && current_games.length >= num) {
2414 switch_backend(current_games[num]);
2416 } else if (event.which == 78) { // N.
2420 window.addEventListener('hashchange', possibly_switch_game_from_hash, false);
2421 possibly_switch_game_from_hash();
2423 document.addEventListener('DOMContentLoaded', init);