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;
131 * Our best estimate of how many milliseconds we need to add to
132 * new Date() to get the true UTC time. Calibrated against the
138 var client_clock_offset_ms = null;
140 var clock_timer = null;
142 /** The current position being analyzed, represented as a FEN string.
143 * Note that this is not necessarily the same as display_fen.
149 /** The current position on the board, represented as a FEN string.
150 * Note that board.fen() does not contain e.g. who is to play.
154 var display_fen = null;
158 * pv: Array.<string>,
161 * scores: Array<{first_move: number, score: Object}>,
162 * start_display_move_num: number
165 * "start_display_move_num" is the (half-)move number to start displaying the PV at.
166 * "score" is also evaluated at this point.
169 /** All PVs that we currently know of.
171 * Element 0 is history (or null if no history).
172 * Element 1 is current main PV, or explored line if nowhere else on the screen.
173 * All remaining elements are refutation lines (multi-PV).
175 * @type {Array.<DisplayLine>}
178 var display_lines = [];
180 /** @type {?DisplayLine} @private */
181 var current_display_line = null;
183 /** @type {boolean} @private */
184 var current_display_line_is_history = false;
186 /** @type {?number} @private */
187 var current_display_move = null;
190 * The current backend request to get main analysis (not history), if any,
191 * so that we can abort it.
196 var current_analysis_xhr = null;
199 * The current timer to fire off a request to get main analysis (not history),
200 * if any, so that we can abort it.
205 var current_analysis_request_timer = null;
208 * The current backend request to get historic data, if any.
213 var current_historic_xhr = null;
216 * The current backend request to get hash probes, if any, so that we can abort it.
221 var current_hash_xhr = null;
224 * The current timer to display hash probe information (it could be waiting on the
225 * board to stop animating), if any, so that we can abort it.
230 var current_hash_display_timer = null;
232 var supports_html5_storage = function() {
234 return 'localStorage' in window && window['localStorage'] !== null;
240 // Make the unique token persistent so people refreshing the page won't count twice.
241 // Of course, you can never fully protect against people deliberately wanting to spam.
242 var get_unique = function() {
243 var use_local_storage = supports_html5_storage();
244 if (use_local_storage && localStorage['unique']) {
245 return localStorage['unique'];
247 var unique = Math.random();
248 if (use_local_storage) {
249 localStorage['unique'] = unique;
254 var request_update = function() {
255 current_analysis_request_timer = null;
257 current_analysis_xhr = $.ajax({
258 url: backend_url + "?ims=" + ims + "&unique=" + unique
259 }).done(function(data, textstatus, xhr) {
260 sync_server_clock(xhr.getResponseHeader('Date'));
261 ims = xhr.getResponseHeader('X-RGLM');
262 var num_viewers = xhr.getResponseHeader('X-RGNV');
264 if (Array.isArray(data)) {
265 new_data = JSON.parse(JSON.stringify(current_analysis_data));
266 JSON_delta.patch(new_data, data);
271 var minimum_version = xhr.getResponseHeader('X-RGMV');
272 if (minimum_version && minimum_version > SCRIPT_VERSION) {
273 // Upgrade to latest version with a force-reload.
274 location.reload(true);
277 // Verify that the PV makes sense.
279 if (new_data['pv']) {
280 var hiddenboard = new Chess(new_data['position']['fen']);
281 for (var i = 0; i < new_data['pv'].length; ++i) {
282 if (hiddenboard.move(new_data['pv'][i]) === null) {
291 possibly_play_sound(current_analysis_data, new_data);
292 current_analysis_data = new_data;
294 update_num_viewers(num_viewers);
296 console.log("Received invalid update, waiting five seconds and trying again.");
297 setTimeout(function() { location.reload(true); }, 5000);
301 if (!backend_url.match(/history/)) {
302 current_analysis_request_timer = setTimeout(function() { request_update(); }, timeout);
304 }).fail(function(jqXHR, textStatus, errorThrown) {
305 if (textStatus === "abort") {
306 // Aborted because we are switching backends. Abandon and don't retry,
307 // because another one is already started for us.
309 // Backend error or similar. Wait ten seconds, then try again.
310 current_analysis_request_timer = setTimeout(function() { request_update(); }, 10000);
315 var possibly_play_sound = function(old_data, new_data) {
319 if (old_data === null) {
322 var ding = document.getElementById('ding');
323 if (ding && ding.play) {
324 if (old_data['position'] && old_data['position']['fen'] &&
325 new_data['position'] && new_data['position']['fen'] &&
326 (old_data['position']['fen'] !== new_data['position']['fen'] ||
327 old_data['position']['move_num'] !== new_data['position']['move_num'])) {
334 * @type {!string} server_date_string
336 var sync_server_clock = function(server_date_string) {
337 var server_time_ms = new Date(server_date_string).getTime();
338 var client_time_ms = new Date().getTime();
339 var estimated_offset_ms = server_time_ms - client_time_ms;
341 // In order not to let the noise move us too much back and forth
342 // (the server only has one-second resolution anyway), we only
343 // change an existing skew if we are at least five seconds off.
344 if (client_clock_offset_ms === null ||
345 Math.abs(estimated_offset_ms - client_clock_offset_ms) > 5000) {
346 client_clock_offset_ms = estimated_offset_ms;
350 var clear_arrows = function() {
351 for (var i = 0; i < arrows.length; ++i) {
353 if (arrows[i].svg.parentElement) {
354 arrows[i].svg.parentElement.removeChild(arrows[i].svg);
356 delete arrows[i].svg;
361 occupied_by_arrows = [];
362 for (var y = 0; y < 8; ++y) {
363 occupied_by_arrows.push([false, false, false, false, false, false, false, false]);
367 var redraw_arrows = function() {
368 for (var i = 0; i < arrows.length; ++i) {
369 position_arrow(arrows[i]);
373 /** @param {!number} x
376 var sign = function(x) {
386 /** See if drawing this arrow on the board would cause unduly amount of confusion.
387 * @param {!string} from The square the arrow is from (e.g. e4).
388 * @param {!string} to The square the arrow is to (e.g. e4).
391 var interfering_arrow = function(from, to) {
392 var from_col = from.charCodeAt(0) - "a1".charCodeAt(0);
393 var from_row = from.charCodeAt(1) - "a1".charCodeAt(1);
394 var to_col = to.charCodeAt(0) - "a1".charCodeAt(0);
395 var to_row = to.charCodeAt(1) - "a1".charCodeAt(1);
397 occupied_by_arrows[from_row][from_col] = true;
399 // Knight move: Just check that we haven't been at the destination before.
400 if ((Math.abs(to_col - from_col) == 2 && Math.abs(to_row - from_row) == 1) ||
401 (Math.abs(to_col - from_col) == 1 && Math.abs(to_row - from_row) == 2)) {
402 return occupied_by_arrows[to_row][to_col];
405 // Sliding piece: Check if anything except the from-square is seen before.
406 var dx = sign(to_col - from_col);
407 var dy = sign(to_row - from_row);
413 if (occupied_by_arrows[y][x]) {
416 occupied_by_arrows[y][x] = true;
417 } while (x != to_col || y != to_row);
422 /** Find a point along the coordinate system given by the given line,
423 * <t> units forward from the start of the line, <u> units to the right of it.
424 * @param {!number} x1
425 * @param {!number} x2
426 * @param {!number} y1
427 * @param {!number} y2
430 * @return {!string} The point in "x y" form, suitable for SVG paths.
432 var point_from_start = function(x1, y1, x2, y2, t, u) {
436 var norm = 1.0 / Math.sqrt(dx * dx + dy * dy);
440 var x = x1 + dx * t + dy * u;
441 var y = y1 + dy * t - dx * u;
445 /** Find a point along the coordinate system given by the given line,
446 * <t> units forward from the end of the line, <u> units to the right of it.
447 * @param {!number} x1
448 * @param {!number} x2
449 * @param {!number} y1
450 * @param {!number} y2
453 * @return {!string} The point in "x y" form, suitable for SVG paths.
455 var point_from_end = function(x1, y1, x2, y2, t, u) {
459 var norm = 1.0 / Math.sqrt(dx * dx + dy * dy);
463 var x = x2 + dx * t + dy * u;
464 var y = y2 + dy * t - dx * u;
468 var position_arrow = function(arrow) {
470 if (arrow.svg.parentElement) {
471 arrow.svg.parentElement.removeChild(arrow.svg);
475 if (current_display_line !== null && !current_display_line_is_history) {
479 var zoom_factor = $("#board").width() / 400.0;
480 var line_width = arrow.line_width * zoom_factor;
481 var arrow_size = arrow.arrow_size * zoom_factor;
483 var square_width = $(".square-a8").width();
484 var pos, from_y, to_y, from_x, to_x;
485 if (board.orientation() === 'black') {
486 pos = $(".square-h1").position();
487 from_y = (arrow.from_row + 0.5)*square_width;
488 to_y = (arrow.to_row + 0.5)*square_width;
489 from_x = (7 - arrow.from_col + 0.5)*square_width;
490 to_x = (7 - arrow.to_col + 0.5)*square_width;
492 pos = $(".square-a8").position();
493 from_y = (7 - arrow.from_row + 0.5)*square_width;
494 to_y = (7 - arrow.to_row + 0.5)*square_width;
495 from_x = (arrow.from_col + 0.5)*square_width;
496 to_x = (arrow.to_col + 0.5)*square_width;
499 var SVG_NS = "http://www.w3.org/2000/svg";
500 var XHTML_NS = "http://www.w3.org/1999/xhtml";
501 var svg = document.createElementNS(SVG_NS, "svg");
502 svg.setAttribute("width", /** @type{number} */ ($("#board").width()));
503 svg.setAttribute("height", /** @type{number} */ ($("#board").height()));
504 svg.setAttribute("style", "position: absolute");
505 svg.setAttribute("position", "absolute");
506 svg.setAttribute("version", "1.1");
507 svg.setAttribute("class", "c1");
508 svg.setAttribute("xmlns", XHTML_NS);
516 var outline = document.createElementNS(SVG_NS, "path");
517 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));
518 outline.setAttribute("xmlns", XHTML_NS);
519 outline.setAttribute("stroke", "#666");
520 outline.setAttribute("stroke-width", line_width + 2);
521 outline.setAttribute("fill", "none");
522 svg.appendChild(outline);
524 var path = document.createElementNS(SVG_NS, "path");
525 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));
526 path.setAttribute("xmlns", XHTML_NS);
527 path.setAttribute("stroke", arrow.fg_color);
528 path.setAttribute("stroke-width", line_width);
529 path.setAttribute("fill", "none");
530 svg.appendChild(path);
532 // Then the arrow head.
533 var head = document.createElementNS(SVG_NS, "path");
534 head.setAttribute("d",
535 "M " + point_from_end(x1, y1, x2, y2, 0, 0) +
536 " L " + point_from_end(x1, y1, x2, y2, -arrow_size, -arrow_size / 2) +
537 " L " + point_from_end(x1, y1, x2, y2, -arrow_size * .623, 0.0) +
538 " L " + point_from_end(x1, y1, x2, y2, -arrow_size, arrow_size / 2) +
539 " L " + point_from_end(x1, y1, x2, y2, 0, 0));
540 head.setAttribute("xmlns", XHTML_NS);
541 head.setAttribute("stroke", "#000");
542 head.setAttribute("stroke-width", "1");
543 head.setAttribute("fill", arrow.fg_color);
544 svg.appendChild(head);
546 $(svg).css({ top: pos.top, left: pos.left, 'pointer-events': 'none' });
547 document.body.appendChild(svg);
552 * @param {!string} from_square
553 * @param {!string} to_square
554 * @param {!string} fg_color
555 * @param {number} line_width
556 * @param {number} arrow_size
558 var create_arrow = function(from_square, to_square, fg_color, line_width, arrow_size) {
559 var from_col = from_square.charCodeAt(0) - "a1".charCodeAt(0);
560 var from_row = from_square.charCodeAt(1) - "a1".charCodeAt(1);
561 var to_col = to_square.charCodeAt(0) - "a1".charCodeAt(0);
562 var to_row = to_square.charCodeAt(1) - "a1".charCodeAt(1);
570 line_width: line_width,
571 arrow_size: arrow_size,
575 position_arrow(arrow);
579 var compare_by_score = function(refutation_lines, invert, a, b) {
580 var sa = compute_score_sort_key(refutation_lines[b]['score'], refutation_lines[b]['depth'], invert);
581 var sb = compute_score_sort_key(refutation_lines[a]['score'], refutation_lines[a]['depth'], invert);
586 * Fake multi-PV using the refutation lines. Find all “relevant” moves,
587 * sorted by quality, descending.
589 * @param {!Object} data
590 * @param {number} margin The maximum number of centipawns worse than the
591 * best move can be and still be included.
592 * @param {boolean} invert Whether black is to play.
593 * @return {Array.<string>} The FEN representation (e.g. Ne4) of all
594 * moves, in score order.
596 var find_nonstupid_moves = function(data, margin, invert) {
597 // First of all, if there are any moves that are more than 0.5 ahead of
598 // the primary move, the refutation lines are probably bunk, so just
600 var best_score = undefined;
601 var pv_score = undefined;
602 for (var move in data['refutation_lines']) {
603 var line = data['refutation_lines'][move];
604 var score = compute_score_sort_key(line['score'], line['depth'], invert, false);
605 if (move == data['pv'][0]) {
608 if (best_score === undefined || score > best_score) {
611 if (line['depth'] < 8) {
616 if (best_score - pv_score > 50) {
620 // Now find all moves that are within “margin” of the best score.
621 // The PV move will always be first.
623 for (var move in data['refutation_lines']) {
624 var line = data['refutation_lines'][move];
625 var score = compute_score_sort_key(line['score'], line['depth'], invert);
626 if (move != data['pv'][0] && best_score - score <= margin) {
630 moves = moves.sort(function(a, b) { return compare_by_score(data['refutation_lines'], data['position']['toplay'] === 'B', a, b) });
631 moves.unshift(data['pv'][0]);
640 var thousands = function(x) {
641 return String(x).split('').reverse().join('').replace(/(\d{3}\B)/g, '$1,').split('').reverse().join('');
645 * @param {!string} start_fen
646 * @param {Array.<string>} pv
647 * @param {number} move_num
648 * @param {!string} toplay
649 * @param {Array<{ first_move: integer, score: Object }>} scores
650 * @param {number} start_display_move_num
651 * @param {number=} opt_limit
652 * @param {boolean=} opt_showlast
654 var add_pv = function(start_fen, pv, move_num, toplay, scores, start_display_move_num, opt_limit, opt_showlast) {
656 start_fen: start_fen,
658 move_num: parseInt(move_num),
661 start_display_move_num: start_display_move_num
663 var splicepos = null;
664 if (scores !== null && scores.length >= 1 &&
665 scores[scores.length - 1].score !== undefined &&
666 scores[scores.length - 1].score !== null &&
667 (scores[scores.length - 1].score[0] === 'T' ||
668 scores[scores.length - 1].score[0] === 't')) {
669 splicepos = scores[scores.length - 1].score[1];
671 return print_pv(display_lines.length - 1, splicepos, opt_limit, opt_showlast);
675 * @param {number} line_num
676 * @param {?number} splicepos If non-null, where the tablebase-spliced portion of the TB starts.
677 * @param {number=} opt_limit If set, show at most this number of moves.
678 * @param {boolean=} opt_showlast If limit is set, show the last moves instead of the first ones.
680 var print_pv = function(line_num, splicepos, opt_limit, opt_showlast) {
681 var display_line = display_lines[line_num];
682 var pv = display_line.pv;
683 var move_num = display_line.move_num;
684 var toplay = display_line.toplay;
686 // Truncate PV at the start if needed.
687 var start_display_move_num = display_line.start_display_move_num;
688 if (start_display_move_num > 0) {
689 pv = pv.slice(start_display_move_num);
690 var to_add = start_display_move_num;
691 if (toplay === 'B') {
696 if (to_add % 2 == 1) {
700 move_num += to_add / 2;
701 if (splicepos !== null && splicepos > 0) {
709 if (opt_limit && opt_showlast && pv.length > opt_limit) {
710 // Truncate the PV at the beginning (instead of at the end).
711 // We assume here that toplay is 'W'. We also assume that if
712 // opt_showlast is set, then it is the history, and thus,
713 // the UI should be to expand the history.
714 ret = '(<a class="move" href="javascript:collapse_history(false)">…</a>) ';
715 i = pv.length - opt_limit;
720 } else if (toplay == 'B' && pv.length > 0) {
722 if (splicepos === 0) {
726 move += "<a class=\"move\" id=\"automove" + line_num + "-0\" href=\"javascript:show_line(" + line_num + ", " + 0 + ");\">" + pv[0] + "</a>";
727 ret = move_num + '. … ' + move;
732 for ( ; i < pv.length; ++i) {
733 var move = "<a class=\"move\" id=\"automove" + line_num + "-" + i + "\" href=\"javascript:show_line(" + line_num + ", " + i + ");\">" + pv[i] + "</a>";
734 if (splicepos === i) {
740 if (i > opt_limit && !opt_showlast) {
749 ret += move_num + '. ' + move;
763 /** Update the highlighted to/from squares on the board.
764 * Based on the global "highlight_from" and "highlight_to" variables.
766 var update_board_highlight = function() {
767 $("#board").find('.square-55d63').removeClass('nonuglyhighlight');
768 if ((current_display_line === null || current_display_line_is_history) &&
769 highlight_from !== undefined && highlight_to !== undefined) {
770 $("#board").find('.square-' + highlight_from).addClass('nonuglyhighlight');
771 $("#board").find('.square-' + highlight_to).addClass('nonuglyhighlight');
775 var update_history = function() {
776 if (display_lines[0] === null || display_lines[0].pv.length == 0) {
777 $("#history").html("No history");
778 } else if (truncate_display_history) {
779 $("#history").html(print_pv(0, null, 8, true));
782 '(<a class="move" href="javascript:collapse_history(true)">collapse</a>) ' +
788 * @param {!boolean} truncate_history
790 var collapse_history = function(truncate_history) {
791 truncate_display_history = truncate_history;
794 window['collapse_history'] = collapse_history;
796 /** Update the HTML display of multi-PV from the global "refutation_lines".
798 * Also recreates the global "display_lines".
800 var update_refutation_lines = function() {
801 if (base_fen === null) {
804 if (display_lines.length > 2) {
805 // Truncate so that only the history and PV is left.
806 display_lines = [ display_lines[0], display_lines[1] ];
808 var tbl = $("#refutationlines");
811 if (display_lines.length < 2) {
815 // Find out where the lines start from.
817 var base_scores = display_lines[1].scores;
818 var start_display_move_num = 0;
819 if (hash_refutation_lines) {
820 base_line = current_display_line.pv.slice(0, current_display_move + 1);
821 base_scores = current_display_line.scores;
822 start_display_move_num = base_line.length;
826 for (var move in refutation_lines) {
830 var invert = (toplay === 'B');
831 if (current_display_line && current_display_move % 2 == 0 && !current_display_line_is_history) {
834 moves = moves.sort(function(a, b) { return compare_by_score(refutation_lines, invert, a, b) });
835 for (var i = 0; i < moves.length; ++i) {
836 var line = refutation_lines[moves[i]];
838 var tr = document.createElement("tr");
840 var move_td = document.createElement("td");
841 tr.appendChild(move_td);
842 $(move_td).addClass("move");
844 var scores = base_scores.concat([{ first_move: start_display_move_num, score: line['score'] }]);
846 if (line['pv'].length == 0) {
847 // Not found, so just make a one-move PV.
848 var move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['move'] + "</a>";
849 $(move_td).html(move);
850 var score_td = document.createElement("td");
852 $(score_td).addClass("score");
853 $(score_td).text("—");
854 tr.appendChild(score_td);
856 var depth_td = document.createElement("td");
857 tr.appendChild(depth_td);
858 $(depth_td).addClass("depth");
859 $(depth_td).text("—");
861 var pv_td = document.createElement("td");
862 tr.appendChild(pv_td);
863 $(pv_td).addClass("pv");
864 $(pv_td).html(add_pv(base_fen, base_line.concat([ line['move'] ]), move_num, toplay, scores, start_display_move_num));
870 var move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['move'] + "</a>";
871 $(move_td).html(move);
873 var score_td = document.createElement("td");
874 tr.appendChild(score_td);
875 $(score_td).addClass("score");
876 $(score_td).text(format_short_score(line['score']));
878 var depth_td = document.createElement("td");
879 tr.appendChild(depth_td);
880 $(depth_td).addClass("depth");
881 if (line['depth'] && line['depth'] >= 0) {
882 $(depth_td).text("d" + line['depth']);
884 $(depth_td).text("—");
887 var pv_td = document.createElement("td");
888 tr.appendChild(pv_td);
889 $(pv_td).addClass("pv");
890 $(pv_td).html(add_pv(base_fen, base_line.concat(line['pv']), move_num, toplay, scores, start_display_move_num, 10));
895 // Update the move highlight, as we've rewritten all the HTML.
896 update_move_highlight();
900 * Create a Chess.js board object, containing the given position plus the given moves,
901 * up to the given limit.
903 * @param {?string} fen
904 * @param {Array.<string>} moves
905 * @param {number} last_move
907 var chess_from = function(fen, moves, last_move) {
908 var hiddenboard = new Chess();
909 if (fen !== null && fen !== undefined) {
910 hiddenboard.load(fen);
912 for (var i = 0; i <= last_move; ++i) {
913 if (moves[i] === '0-0') {
914 hiddenboard.move('O-O');
915 } else if (moves[i] === '0-0-0') {
916 hiddenboard.move('O-O-O');
918 hiddenboard.move(moves[i]);
924 var update_game_list = function(games) {
925 $("#games").text("");
926 if (games === null) {
930 var games_div = document.getElementById('games');
931 for (var game_num = 0; game_num < games.length; ++game_num) {
932 var game = games[game_num];
933 var game_span = document.createElement("span");
934 game_span.setAttribute("class", "game");
936 var game_name = document.createTextNode(game['name']);
937 if (game['url'] === backend_url) {
939 game_span.appendChild(game_name);
941 if (current_analysis_data && current_analysis_data['position']) {
943 if (current_analysis_data['position']['result']) {
944 score = " (" + current_analysis_data['position']['result'] + ")";
946 score = " (" + format_short_score(current_analysis_data['score']) + ")";
948 game_span.appendChild(document.createTextNode(score));
952 var game_a = document.createElement("a");
953 game_a.setAttribute("href", "#" + game['id']);
954 game_a.appendChild(game_name);
955 game_span.appendChild(game_a);
958 if (game['result']) {
959 score = " (" + game['result'] + ")";
961 score = " (" + format_short_score(game['score']) + ")";
963 game_span.appendChild(document.createTextNode(score));
966 games_div.appendChild(game_span);
971 * Try to find a running game that matches with the current hash,
972 * and switch to it if we're not already displaying it.
974 var possibly_switch_game_from_hash = function() {
975 var history_match = window.location.hash.match(/^#history=([a-zA-Z0-9_-]+)/);
976 if (history_match !== null) {
977 var game_id = history_match[1];
979 url: '/history/' + game_id + '.json',
981 id: 'history=' + game_id
983 switch_backend(fake_game);
987 if (current_games === null) {
991 var hash = window.location.hash.replace(/^#/,'');
992 for (var i = 0; i < current_games.length; ++i) {
993 if (current_games[i]['id'] === hash) {
994 if (backend_url !== current_games[i]['url']) {
995 switch_backend(current_games[i]);
1003 * If this is a Chess960 castling which doesn't move the king,
1004 * move the rook instead.
1006 var patch_move = function(move) {
1007 if (move === null) return null;
1008 if (move.from !== move.to) return move;
1010 var f = move.rook_sq & 15;
1011 var r = move.rook_sq >> 4;
1012 var from = ('abcdefgh'.substring(f,f+1) + '87654321'.substring(r,r+1));
1015 if (move.to === 'g1') {
1017 } else if (move.to === 'g8') {
1019 } else if (move.to === 'b1') {
1021 } else if (move.to === 'b8') {
1025 return { from: from, to: to };
1028 /** Update all the HTML on the page, based on current global state.
1030 var update_board = function() {
1031 var data = displayed_analysis_data || current_analysis_data;
1032 var current_data = current_analysis_data; // Convenience alias.
1036 // Print the history. This is pretty much the only thing that's
1037 // unconditionally taken from current_data (we're not interested in
1038 // historic history).
1039 if (current_data['position']['history']) {
1040 var start = (current_data['position'] && current_data['position']['start_fen']) ? current_data['position']['start_fen'] : 'start';
1041 add_pv(start, current_data['position']['history'], 1, 'W', null, 0, 8, true);
1043 display_lines.push(null);
1047 // Games currently in progress, if any.
1048 if (current_data['games']) {
1049 current_games = current_data['games'];
1050 possibly_switch_game_from_hash();
1052 current_games = null;
1054 update_game_list(current_games);
1056 // The headline. Names are always fetched from current_data;
1057 // the rest can depend a bit.
1060 current_data['position']['player_w'] && current_data['position']['player_b']) {
1061 headline = current_data['position']['player_w'] + '–' +
1062 current_data['position']['player_b'] + ', analysis';
1064 headline = 'Analysis';
1067 // Credits, where applicable. Note that we don't want the footer to change a lot
1068 // when e.g. viewing history, so if any of these changed during the game,
1069 // use the current one still.
1070 if (current_data['using_lomonosov']) {
1071 $("#lomonosov").show();
1073 $("#lomonosov").hide();
1076 // Credits: The engine name/version.
1077 if (current_data['engine'] && current_data['engine']['name'] !== null) {
1078 $("#engineid").text(current_data['engine']['name']);
1081 // Credits: The engine URL.
1082 if (current_data['engine'] && current_data['engine']['url']) {
1083 $("#engineid").attr("href", current_data['engine']['url']);
1085 $("#engineid").removeAttr("href");
1088 // Credits: Engine details.
1089 if (current_data['engine'] && current_data['engine']['details']) {
1090 $("#enginedetails").text(" (" + current_data['engine']['details'] + ")");
1092 $("#enginedetails").text("");
1095 // Credits: Move source, possibly with URL.
1096 if (current_data['move_source'] && current_data['move_source_url']) {
1097 $("#movesource").text("Moves provided by ");
1098 var movesource_a = document.createElement("a");
1099 movesource_a.setAttribute("href", current_data['move_source_url']);
1100 var movesource_text = document.createTextNode(current_data['move_source']);
1101 movesource_a.appendChild(movesource_text);
1102 var movesource_period = document.createTextNode(".");
1103 document.getElementById("movesource").appendChild(movesource_a);
1104 document.getElementById("movesource").appendChild(movesource_period);
1105 } else if (current_data['move_source']) {
1106 $("#movesource").text("Moves provided by " + current_data['move_source'] + ".");
1108 $("#movesource").text("");
1112 if (displayed_analysis_data) {
1113 // Displaying some non-current position, pick out the last move
1114 // from the history. This will work even if the fetch failed.
1115 if (current_display_move !== -1) {
1116 last_move = format_halfmove_with_number(
1117 current_display_line.pv[current_display_move],
1118 current_display_move);
1119 headline += ' after ' + last_move;
1121 } else if (data['position']['last_move'] !== 'none') {
1122 // Find the previous move.
1123 var previous_move_num, previous_toplay;
1124 if (data['position']['toplay'] == 'B') {
1125 previous_move_num = data['position']['move_num'];
1126 previous_toplay = 'W';
1128 previous_move_num = data['position']['move_num'] - 1;
1129 previous_toplay = 'B';
1132 last_move = format_move_with_number(
1133 data['position']['last_move'],
1135 previous_toplay == 'W');
1136 headline += ' after ' + last_move;
1140 $("#headline").text(headline);
1142 // The <title> contains a very brief headline.
1143 var title_elems = [];
1144 if (data['position'] && data['position']['result']) {
1145 title_elems.push(data['position']['result']);
1146 } else if (data['score']) {
1147 title_elems.push(format_short_score(data['score']));
1149 if (last_move !== null) {
1150 title_elems.push(last_move);
1153 if (title_elems.length != 0) {
1154 document.title = '(' + title_elems.join(', ') + ') analysis.sesse.net';
1156 document.title = 'analysis.sesse.net';
1159 // The last move (shown by highlighting the from and to squares).
1160 if (data['position'] && data['position']['last_move_uci']) {
1161 highlight_from = data['position']['last_move_uci'].substr(0, 2);
1162 highlight_to = data['position']['last_move_uci'].substr(2, 2);
1163 } else if (current_display_line_is_history && current_display_line && current_display_move >= 0) {
1164 // We don't have historic analysis for this position, but we
1165 // can reconstruct what the last move was by just replaying
1167 var position = (data['position'] && data['position']['start_fen']) ? data['position']['start_fen'] : null;
1168 var hiddenboard = chess_from(position, current_display_line.pv, current_display_move);
1169 var moves = hiddenboard.history({ verbose: true });
1170 last_move = moves.pop();
1171 highlight_from = last_move.from;
1172 highlight_to = last_move.to;
1174 highlight_from = highlight_to = undefined;
1176 update_board_highlight();
1178 if (data['failed']) {
1179 $("#score").text("No analysis for this move");
1180 $("#pvtitle").text("PV:");
1182 $("#searchstats").html(" ");
1183 $("#refutationlines").empty();
1184 $("#whiteclock").empty();
1185 $("#blackclock").empty();
1186 refutation_lines = [];
1187 update_refutation_lines();
1189 update_displayed_line();
1190 update_move_highlight();
1197 if (current_display_line && !current_display_line_is_history) {
1199 if (current_display_line.scores && current_display_line.scores.length > 0) {
1200 for (var i = 0; i < current_display_line.scores.length; ++i) {
1201 if (current_display_move < current_display_line.scores[i].first_move) {
1204 score = current_display_line.scores[i].score;
1208 $("#score").text(format_long_score(score));
1210 $("#score").text("No score for this line");
1212 } else if (data['score']) {
1213 $("#score").text(format_long_score(data['score']));
1216 // The search stats.
1217 if (data['searchstats']) {
1218 $("#searchstats").html(data['searchstats']);
1219 } else if (data['tablebase'] == 1) {
1220 $("#searchstats").text("Tablebase result");
1221 } else if (data['nodes'] && data['nps'] && data['depth']) {
1222 var stats = thousands(data['nodes']) + ' nodes, ' + thousands(data['nps']) + ' nodes/sec, depth ' + data['depth'] + ' ply';
1223 if (data['seldepth']) {
1224 stats += ' (' + data['seldepth'] + ' selective)';
1226 if (data['tbhits'] && data['tbhits'] > 0) {
1227 if (data['tbhits'] == 1) {
1228 stats += ', one Syzygy hit';
1230 stats += ', ' + thousands(data['tbhits']) + ' Syzygy hits';
1234 $("#searchstats").text(stats);
1236 $("#searchstats").text("");
1239 // Update the board itself.
1240 base_fen = data['position']['fen'];
1241 update_displayed_line();
1244 $("#pvtitle").text("PV:");
1246 var scores = [{ first_move: -1, score: data['score'] }];
1247 $("#pv").html(add_pv(data['position']['fen'], data['pv'], data['position']['move_num'], data['position']['toplay'], scores, 0));
1249 // Update the PV arrow.
1251 if (data['pv'].length >= 1) {
1252 var hiddenboard = new Chess(base_fen);
1254 // draw a continuation arrow as long as it's the same piece
1256 for (var i = 0; i < data['pv'].length; i += 2) {
1257 var move = patch_move(hiddenboard.move(data['pv'][i]));
1259 if ((i >= 2 && move.from != last_to) ||
1260 interfering_arrow(move.from, move.to)) {
1263 create_arrow(move.from, move.to, '#f66', 6, 20);
1265 hiddenboard.move(data['pv'][i + 1]); // To keep continuity.
1268 var alt_moves = find_nonstupid_moves(data, 30, data['position']['toplay'] === 'B');
1269 for (var i = 1; i < alt_moves.length && i < 3; ++i) {
1270 hiddenboard = new Chess(base_fen);
1271 var move = patch_move(hiddenboard.move(alt_moves[i]));
1272 if (move !== null) {
1273 create_arrow(move.from, move.to, '#f66', 1, 10);
1278 // See if all semi-reasonable moves have only one possible response.
1279 if (data['pv'].length >= 2) {
1280 var nonstupid_moves = find_nonstupid_moves(data, 300, data['position']['toplay'] === 'B');
1283 var hiddenboard = new Chess(base_fen);
1284 hiddenboard.move(data['pv'][0]);
1285 response = hiddenboard.move(data['pv'][1]);
1287 for (var i = 0; i < nonstupid_moves.length; ++i) {
1288 if (nonstupid_moves[i] == data['pv'][0]) {
1289 // ignore the PV move for refutation lines.
1292 if (!data['refutation_lines'] ||
1293 !data['refutation_lines'][nonstupid_moves[i]] ||
1294 !data['refutation_lines'][nonstupid_moves[i]]['pv'] ||
1295 data['refutation_lines'][nonstupid_moves[i]]['pv'].length < 2) {
1296 // Incomplete PV, abort.
1297 response = undefined;
1300 var line = data['refutation_lines'][nonstupid_moves[i]];
1301 hiddenboard = new Chess(base_fen);
1302 hiddenboard.move(line['pv'][0]);
1303 var this_response = hiddenboard.move(line['pv'][1]);
1304 if (this_response === null) {
1305 console.log("BUG: ", i);
1307 console.log(line['pv']);
1309 if (response.from !== this_response.from || response.to !== this_response.to) {
1310 // Different response depending on lines, abort.
1311 response = undefined;
1316 if (nonstupid_moves.length > 0 && response !== undefined) {
1317 create_arrow(response.from, response.to, '#66f', 6, 20);
1321 // Update the refutation lines.
1322 base_fen = data['position']['fen'];
1323 move_num = parseInt(data['position']['move_num']);
1324 toplay = data['position']['toplay'];
1325 refutation_lines = hash_refutation_lines || data['refutation_lines'];
1326 update_refutation_lines();
1328 // Update the sparkline last, since its size depends on how everything else reflowed.
1329 update_sparkline(data);
1332 var update_sparkline = function(data) {
1333 if (data && data['score_history']) {
1334 var first_move_num = undefined;
1335 for (var halfmove_num in data['score_history']) {
1336 halfmove_num = parseInt(halfmove_num);
1337 if (first_move_num === undefined || halfmove_num < first_move_num) {
1338 first_move_num = halfmove_num;
1341 if (first_move_num !== undefined) {
1342 var last_move_num = data['position']['move_num'] * 2 - 3;
1343 if (data['position']['toplay'] === 'B') {
1347 // Possibly truncate some moves if we don't have enough width.
1348 // FIXME: Sometimes width() for #scorecontainer (and by extent,
1349 // #scoresparkcontainer) on Chrome for mobile seems to start off
1350 // at something very small, and then suddenly snap back into place.
1352 var max_moves = Math.floor($("#scoresparkcontainer").width() / 5) - 5;
1353 if (last_move_num - first_move_num > max_moves) {
1354 first_move_num = last_move_num - max_moves;
1357 var min_score = -100;
1358 var max_score = 100;
1359 var last_score = null;
1361 for (var halfmove_num = first_move_num; halfmove_num <= last_move_num; ++halfmove_num) {
1362 if (data['score_history'][halfmove_num]) {
1363 var score = compute_plot_score(data['score_history'][halfmove_num]);
1365 if (score < min_score) min_score = score;
1366 if (score > max_score) max_score = score;
1368 scores.push(last_score);
1370 if (data['score']) {
1371 scores.push(compute_plot_score(data['score']));
1373 // FIXME: at some widths, calling sparkline() seems to push
1374 // #scorecontainer under the board.
1375 $('#scorespark').unbind('sparklineClick');
1376 $("#scorespark").sparkline(scores, {
1379 chartRangeMin: min_score,
1380 chartRangeMax: max_score,
1381 tooltipFormatter: function(sparkline, options, fields) {
1382 // score_history contains the Nth _position_, but format_tooltip
1383 // wants to format the Nth _move_; thus the -1.
1384 return format_tooltip(data, fields[0].offset + first_move_num - 1);
1387 $('#scorespark').unbind('sparklineClick');
1388 $('#scorespark').bind('sparklineClick', function(event) {
1389 var sparkline = event.sparklines[0];
1390 var region = sparkline.getCurrentRegionFields();
1391 if (region[0].offset !== undefined) {
1392 show_line(0, first_move_num + region[0].offset - 1);
1396 $("#scorespark").text("");
1399 $("#scorespark").text("");
1404 * @param {number} num_viewers
1406 var update_num_viewers = function(num_viewers) {
1408 if (num_viewers === null) {
1410 } else if (num_viewers == 1) {
1411 text = "You are the only current viewer";
1413 text = num_viewers + " current viewers";
1415 if (display_fen !== null) {
1416 var counter = Math.floor(display_fen.split(" ")[4] / 2);
1417 if (counter >= 20) {
1418 text = text.replace("current ", "");
1419 text += " | 50-move rule: " + counter;
1422 $("#numviewers").text(text);
1425 var update_clock = function() {
1426 clearTimeout(clock_timer);
1428 var data = displayed_analysis_data || current_analysis_data;
1431 if (data['position']) {
1432 var result = data['position']['result'];
1433 if (result === '1-0') {
1434 $("#whiteclock").text("1");
1435 $("#blackclock").text("0");
1436 $("#whiteclock").removeClass("running-clock");
1437 $("#blackclock").removeClass("running-clock");
1440 if (result === '1/2-1/2') {
1441 $("#whiteclock").text("1/2");
1442 $("#blackclock").text("1/2");
1443 $("#whiteclock").removeClass("running-clock");
1444 $("#blackclock").removeClass("running-clock");
1447 if (result === '0-1') {
1448 $("#whiteclock").text("0");
1449 $("#blackclock").text("1");
1450 $("#whiteclock").removeClass("running-clock");
1451 $("#blackclock").removeClass("running-clock");
1456 var white_clock_ms = null;
1457 var black_clock_ms = null;
1460 if (data['position'] &&
1461 data['position']['white_clock'] &&
1462 data['position']['black_clock']) {
1463 white_clock_ms = data['position']['white_clock'] * 1000;
1464 black_clock_ms = data['position']['black_clock'] * 1000;
1467 // Dynamic clock (only one, obviously).
1469 if (data['position']['white_clock_target']) {
1471 $("#whiteclock").addClass("running-clock");
1472 $("#blackclock").removeClass("running-clock");
1473 } else if (data['position']['black_clock_target']) {
1475 $("#whiteclock").removeClass("running-clock");
1476 $("#blackclock").addClass("running-clock");
1478 $("#whiteclock").removeClass("running-clock");
1479 $("#blackclock").removeClass("running-clock");
1483 var now = new Date().getTime() + client_clock_offset_ms;
1484 remaining_ms = data['position'][color + '_clock_target'] * 1000 - now;
1485 if (color === "white") {
1486 white_clock_ms = remaining_ms;
1488 black_clock_ms = remaining_ms;
1492 if (white_clock_ms === null || black_clock_ms === null) {
1493 $("#whiteclock").empty();
1494 $("#blackclock").empty();
1498 // If either player has twenty minutes or less left, add the second counters.
1499 // This matches what DGT clocks do.
1500 var show_seconds = (white_clock_ms < 60 * 20 * 1000 || black_clock_ms < 60 * 20 * 1000);
1503 // See when the clock will change next, and update right after that.
1506 next_update_ms = remaining_ms % 1000 + 100;
1508 next_update_ms = remaining_ms % 60000 + 100;
1510 clock_timer = setTimeout(update_clock, next_update_ms);
1513 $("#whiteclock").text(format_clock(white_clock_ms, show_seconds));
1514 $("#blackclock").text(format_clock(black_clock_ms, show_seconds));
1518 * @param {Number} remaining_ms
1519 * @param {boolean} show_seconds
1521 var format_clock = function(remaining_ms, show_seconds) {
1522 if (remaining_ms <= 0) {
1530 var remaining = Math.floor(remaining_ms / 1000);
1531 var seconds = remaining % 60;
1532 remaining = (remaining - seconds) / 60;
1533 var minutes = remaining % 60;
1534 remaining = (remaining - minutes) / 60;
1535 var hours = remaining;
1537 return format_2d(hours) + ":" + format_2d(minutes) + ":" + format_2d(seconds);
1539 return format_2d(hours) + ":" + format_2d(minutes);
1546 var format_2d = function(x) {
1555 * @param {string} move
1556 * @param {Number} move_num Move number of this move.
1557 * @param {boolean} white_to_play Whether white is to play this move.
1559 var format_move_with_number = function(move, move_num, white_to_play) {
1561 if (white_to_play) {
1562 ret = move_num + '. ';
1564 ret = move_num + '… ';
1571 * @param {string} move
1572 * @param {Number} halfmove_num Half-move number that is to be played,
1575 var format_halfmove_with_number = function(move, halfmove_num) {
1576 return format_move_with_number(
1578 Math.floor(halfmove_num / 2) + 1,
1579 halfmove_num % 2 == 0);
1583 * @param {Object} data
1584 * @param {Number} halfmove_num
1586 var format_tooltip = function(data, halfmove_num) {
1587 if (data['score_history'][halfmove_num + 1] ||
1588 (halfmove_num + 1) === data['position']['history'].length) {
1589 // Position is in the history, or it is the current position
1590 // (which is implicitly tacked onto the history).
1593 if ((halfmove_num + 1) === data['position']['history'].length) {
1594 move = data['position']['last_move'];
1595 short_score = format_short_score(data['score']);
1597 move = data['position']['history'][halfmove_num];
1598 short_score = format_short_score(data['score_history'][halfmove_num + 1]);
1600 if (halfmove_num === -1) {
1601 return "Start position: " + short_score;
1603 var move_with_number = format_halfmove_with_number(move, halfmove_num);
1604 return "After " + move_with_number + ": " + short_score;
1607 for (var i = halfmove_num; i --> -1; ) {
1608 if (data['score_history'][i]) {
1609 var move = data['position']['history'][i];
1611 return "[Analysis kept from start position]";
1613 return "[Analysis kept from " + format_halfmove_with_number(move, i) + "]";
1621 * @param {boolean} truncate_history
1623 var set_truncate_history = function(truncate_history) {
1624 truncate_display_history = truncate_history;
1625 update_refutation_lines();
1627 window['set_truncate_history'] = set_truncate_history;
1630 * @param {number} line_num
1631 * @param {number} move_num
1633 var show_line = function(line_num, move_num) {
1634 if (line_num == -1) {
1635 current_display_line = null;
1636 current_display_move = null;
1637 hash_refutation_lines = null;
1638 if (displayed_analysis_data) {
1639 // TODO: Support exiting to history position if we are in an
1640 // analysis line of a history position.
1641 displayed_analysis_data = null;
1646 current_display_line = jQuery.extend({}, display_lines[line_num]); // Shallow clone.
1647 current_display_move = move_num + current_display_line.start_display_move_num;
1649 current_display_line_is_history = (line_num == 0);
1651 update_historic_analysis();
1652 update_displayed_line();
1653 update_board_highlight();
1654 update_move_highlight();
1657 window['show_line'] = show_line;
1659 var prev_move = function() {
1660 if (current_display_line &&
1661 current_display_move >= current_display_line.start_display_move_num) {
1662 --current_display_move;
1664 update_historic_analysis();
1665 update_displayed_line();
1666 update_move_highlight();
1668 window['prev_move'] = prev_move;
1670 var next_move = function() {
1671 if (current_display_line &&
1672 current_display_move < current_display_line.pv.length - 1) {
1673 ++current_display_move;
1675 update_historic_analysis();
1676 update_displayed_line();
1677 update_move_highlight();
1679 window['next_move'] = next_move;
1681 var next_game = function() {
1682 if (current_games === null) {
1686 // Try to find the game we are currently looking at.
1687 for (var game_num = 0; game_num < current_games.length; ++game_num) {
1688 var game = current_games[game_num];
1689 if (game['url'] === backend_url) {
1690 var next_game_num = (game_num + 1) % current_games.length;
1691 switch_backend(current_games[next_game_num]);
1696 // Couldn't find it; give up.
1699 var update_historic_analysis = function() {
1700 if (!current_display_line_is_history) {
1703 if (current_display_move == current_display_line.pv.length - 1) {
1704 displayed_analysis_data = null;
1708 // Fetch old analysis for this line if it exists.
1709 var hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pv, current_display_move);
1710 var filename = "/history/move" + (current_display_move + 1) + "-" +
1711 hiddenboard.fen().replace(/ /g, '_').replace(/\//g, '-') + ".json";
1713 current_historic_xhr = $.ajax({
1715 }).done(function(data, textstatus, xhr) {
1716 displayed_analysis_data = data;
1718 }).fail(function(jqXHR, textStatus, errorThrown) {
1719 if (textStatus === "abort") {
1720 // Aborted because we are switching backends. Don't do anything;
1721 // we will already have been cleared.
1723 displayed_analysis_data = {'failed': true};
1730 * @param {string} fen
1732 var update_imbalance = function(fen) {
1733 var hiddenboard = new Chess(fen);
1734 var imbalance = {'k': 0, 'q': 0, 'r': 0, 'b': 0, 'n': 0, 'p': 0};
1735 for (var row = 0; row < 8; ++row) {
1736 for (var col = 0; col < 8; ++col) {
1737 var col_text = String.fromCharCode('a1'.charCodeAt(0) + col);
1738 var row_text = String.fromCharCode('a1'.charCodeAt(1) + row);
1739 var square = col_text + row_text;
1740 var contents = hiddenboard.get(square);
1741 if (contents !== null) {
1742 if (contents.color === 'w') {
1743 ++imbalance[contents.type];
1745 --imbalance[contents.type];
1750 var white_imbalance = '';
1751 var black_imbalance = '';
1752 for (var piece in imbalance) {
1753 for (var i = 0; i < imbalance[piece]; ++i) {
1754 white_imbalance += '<img src="' + svg_pieces['w' + piece.toUpperCase()] + '" alt="" style="width: 15px;height: 15px;" class="imbalance-piece">';
1755 white_imbalance += '<img src="' + svg_pieces['b' + piece.toUpperCase()] + '" alt="" style="width: 15px;height: 15px;" class="imbalance-inverted-piece">';
1757 for (var i = 0; i < -imbalance[piece]; ++i) {
1758 black_imbalance += '<img src="' + svg_pieces['b' + piece.toUpperCase()] + '" alt="" style="width: 15px;height: 15px;" class="imbalance-piece">';
1759 black_imbalance += '<img src="' + svg_pieces['w' + piece.toUpperCase()] + '" alt="" style="width: 15px;height: 15px;" class="imbalance-inverted-piece">';
1762 $('#whiteimbalance').html(white_imbalance);
1763 $('#blackimbalance').html(black_imbalance);
1766 /** Mark the currently selected move in red.
1767 * Also replaces the PV with the current displayed line if it's not shown
1768 * anywhere else on the screen.
1770 var update_move_highlight = function() {
1771 if (highlighted_move !== null) {
1772 highlighted_move.removeClass('highlight');
1774 if (current_display_line) {
1775 var display_line_num = find_display_line_matching_num();
1776 if (display_line_num === null) {
1777 // Replace the PV with the (complete) line.
1778 $("#pvtitle").text("Exploring:");
1779 current_display_line.start_display_move_num = 0;
1780 display_lines.push(current_display_line);
1781 $("#pv").html(print_pv(display_lines.length - 1, null)); // FIXME
1782 display_line_num = display_lines.length - 1;
1784 // Clear out the PV, so it's not selected by anything later.
1785 display_lines[1].pv = [];
1788 highlighted_move = $("#automove" + display_line_num + "-" + (current_display_move - current_display_line.start_display_move_num));
1789 highlighted_move.addClass('highlight');
1794 * See if the current displayed line is identical to any of the ones
1795 * we have on screen. (It might not be if e.g. the analysis reloaded
1796 * since we started looking.)
1800 var find_display_line_matching_num = function() {
1801 for (var i = 0; i < display_lines.length; ++i) {
1802 var line = display_lines[i];
1803 if (line.start_display_move_num > 0) continue;
1804 if (current_display_line.start_fen !== line.start_fen) continue;
1805 if (current_display_line.pv.length !== line.pv.length) continue;
1807 for (var j = 0; j < line.pv.length; ++j) {
1808 if (current_display_line.pv[j] !== line.pv[j]) {
1820 /** Update the board based on the currently displayed line.
1822 * TODO: This should really be called only whenever something changes,
1823 * instead of all the time.
1825 var update_displayed_line = function() {
1826 if (current_display_line === null) {
1827 $("#linenav").hide();
1828 $("#linemsg").show();
1829 display_fen = base_fen;
1830 set_board_position(base_fen);
1831 update_imbalance(base_fen);
1835 $("#linenav").show();
1836 $("#linemsg").hide();
1838 if (current_display_move <= 0) {
1839 $("#prevmove").html("Previous");
1841 $("#prevmove").html("<a href=\"javascript:prev_move();\">Previous</a></span>");
1843 if (current_display_move == current_display_line.pv.length - 1) {
1844 $("#nextmove").html("Next");
1846 $("#nextmove").html("<a href=\"javascript:next_move();\">Next</a></span>");
1849 var hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pv, current_display_move);
1850 set_board_position(hiddenboard.fen());
1851 if (display_fen !== hiddenboard.fen() && !current_display_line_is_history) {
1852 // Fire off a hash request, since we're now off the main position
1853 // and it just changed.
1854 explore_hash(hiddenboard.fen());
1856 display_fen = hiddenboard.fen();
1857 update_imbalance(hiddenboard.fen());
1860 var set_board_position = function(new_fen) {
1861 board_is_animating = true;
1862 var old_fen = board.fen();
1863 board.position(new_fen);
1864 if (board.fen() === old_fen) {
1865 board_is_animating = false;
1870 * @param {boolean} param_enable_sound
1872 var set_sound = function(param_enable_sound) {
1873 enable_sound = param_enable_sound;
1875 $("#soundon").html("<strong>On</strong>");
1876 $("#soundoff").html("<a href=\"javascript:set_sound(false)\">Off</a>");
1878 // Seemingly at least Firefox prefers MP3 over Opus; tell it otherwise,
1879 // and also preload the file since the user has selected audio.
1880 var ding = document.getElementById('ding');
1881 if (ding && ding.canPlayType && ding.canPlayType('audio/ogg; codecs="opus"') === 'probably') {
1882 ding.src = 'ding.opus';
1886 $("#soundon").html("<a href=\"javascript:set_sound(true)\">On</a>");
1887 $("#soundoff").html("<strong>Off</strong>");
1889 if (supports_html5_storage()) {
1890 localStorage['enable_sound'] = enable_sound ? 1 : 0;
1893 window['set_sound'] = set_sound;
1895 /** Send off a hash probe request to the backend.
1896 * @param {string} fen
1898 var explore_hash = function(fen) {
1899 // If we already have a backend response going, abort it.
1900 if (current_hash_xhr) {
1901 current_hash_xhr.abort();
1903 if (current_hash_display_timer) {
1904 clearTimeout(current_hash_display_timer);
1905 current_hash_display_timer = null;
1907 $("#refutationlines").empty();
1908 current_hash_xhr = $.ajax({
1909 url: backend_hash_url + "?fen=" + fen
1910 }).done(function(data, textstatus, xhr) {
1911 show_explore_hash_results(data, fen);
1915 /** Process the JSON response from a hash probe request.
1916 * @param {!Object} data
1917 * @param {string} fen
1919 var show_explore_hash_results = function(data, fen) {
1920 if (board_is_animating) {
1921 // Updating while the animation is still going causes
1922 // the animation to jerk. This is pretty crude, but it will do.
1923 current_hash_display_timer = setTimeout(function() { show_explore_hash_results(data, fen); }, 100);
1926 current_hash_display_timer = null;
1927 hash_refutation_lines = data['lines'];
1931 // almost all of this stuff comes from the chessboard.js example page
1932 var onDragStart = function(source, piece, position, orientation) {
1933 var pseudogame = new Chess(display_fen);
1934 if (pseudogame.game_over() === true ||
1935 (pseudogame.turn() === 'w' && piece.search(/^b/) !== -1) ||
1936 (pseudogame.turn() === 'b' && piece.search(/^w/) !== -1)) {
1940 recommended_move = get_best_move(pseudogame, source, null, pseudogame.turn() === 'b');
1941 if (recommended_move) {
1942 var squareEl = $('#board .square-' + recommended_move.to);
1943 squareEl.addClass('highlight1-32417');
1948 var mousedownSquare = function(e) {
1949 reverse_dragging_from = null;
1950 var square = $(this).attr('data-square');
1952 var pseudogame = new Chess(display_fen);
1953 if (pseudogame.game_over() === true) {
1957 // If the square is empty, or has a piece of the side not to move,
1958 // we handle it. If not, normal piece dragging will take it.
1959 var position = board.position();
1960 if (!position.hasOwnProperty(square) ||
1961 (pseudogame.turn() === 'w' && position[square].search(/^b/) !== -1) ||
1962 (pseudogame.turn() === 'b' && position[square].search(/^w/) !== -1)) {
1963 reverse_dragging_from = square;
1964 recommended_move = get_best_move(pseudogame, null, square, pseudogame.turn() === 'b');
1965 if (recommended_move) {
1966 var squareEl = $('#board .square-' + recommended_move.from);
1967 squareEl.addClass('highlight1-32417');
1968 squareEl = $('#board .square-' + recommended_move.to);
1969 squareEl.addClass('highlight1-32417');
1974 var mouseupSquare = function(e) {
1975 if (reverse_dragging_from === null) {
1978 var source = $(this).attr('data-square');
1979 var target = reverse_dragging_from;
1980 reverse_dragging_from = null;
1981 if (onDrop(source, target) !== 'snapback') {
1982 onSnapEnd(source, target);
1984 $("#board").find('.square-55d63').removeClass('highlight1-32417');
1987 var get_best_move = function(game, source, target, invert) {
1988 var moves = game.moves({ verbose: true });
1989 if (source !== null) {
1990 moves = moves.filter(function(move) { return move.from == source; });
1992 if (target !== null) {
1993 moves = moves.filter(function(move) { return move.to == target; });
1995 if (moves.length == 0) {
1998 if (moves.length == 1) {
2002 // More than one move. Use the display lines (if we have them)
2003 // to disambiguate; otherwise, we have no information.
2005 for (var i = 0; i < moves.length; ++i) {
2006 move_hash[moves[i].san] = moves[i];
2009 // See if we're already exploring some line.
2010 if (current_display_line &&
2011 current_display_move < current_display_line.pv.length - 1) {
2012 var first_move = current_display_line.pv[current_display_move + 1];
2013 if (move_hash[first_move]) {
2014 return move_hash[first_move];
2018 // History and PV take priority over the display lines.
2019 for (var i = 0; i < 2; ++i) {
2020 var line = display_lines[i];
2021 var first_move = line.pv[line.start_display_move_num];
2022 if (move_hash[first_move]) {
2023 return move_hash[first_move];
2027 var best_move = null;
2028 var best_move_score = null;
2030 for (var move in refutation_lines) {
2031 var line = refutation_lines[move];
2032 if (!line['score']) {
2035 var first_move = line['pv'][0];
2036 if (move_hash[first_move]) {
2037 var score = compute_score_sort_key(line['score'], line['depth'], invert);
2038 if (best_move_score === null || score > best_move_score) {
2039 best_move = move_hash[first_move];
2040 best_move_score = score;
2047 var onDrop = function(source, target) {
2048 if (source === target) {
2049 if (recommended_move === null) {
2052 // Accept the move. It will be changed in onSnapEnd.
2056 // Suggestion not asked for.
2057 recommended_move = null;
2060 // see if the move is legal
2061 var pseudogame = new Chess(display_fen);
2062 var move = pseudogame.move({
2065 promotion: 'q' // NOTE: always promote to a queen for example simplicity
2069 if (move === null) return 'snapback';
2072 var onSnapEnd = function(source, target) {
2073 if (source === target && recommended_move !== null) {
2074 source = recommended_move.from;
2075 target = recommended_move.to;
2077 recommended_move = null;
2078 var pseudogame = new Chess(display_fen);
2079 var move = pseudogame.move({
2082 promotion: 'q' // NOTE: always promote to a queen for example simplicity
2085 if (current_display_line &&
2086 current_display_move < current_display_line.pv.length - 1 &&
2087 current_display_line.pv[current_display_move + 1] === move.san) {
2092 // Walk down the displayed lines until we find one that starts with
2093 // this move, then select that. Note that this gives us a good priority
2094 // order (history first, then PV, then multi-PV lines).
2095 for (var i = 0; i < display_lines.length; ++i) {
2096 if (i == 1 && current_display_line) {
2097 // Do not choose PV if not on it.
2100 var line = display_lines[i];
2101 if (line.pv[line.start_display_move_num] === move.san) {
2107 // Shouldn't really be here if we have hash probes, but there's really
2108 // nothing we can do.
2110 // End of dragging-related code.
2112 var fmt_cp = function(v) {
2116 return "+" + (v / 100).toFixed(2);
2119 return "-" + (v / 100).toFixed(2);
2123 var format_short_score = function(score) {
2127 if (score[0] === 'T' || score[0] === 't') {
2128 var ret = "TB\u00a0";
2129 if (score[2]) { // Is a bound.
2130 ret = score[2] + "\u00a0TB\u00a0";
2132 if (score[0] === 'T') {
2133 return ret + Math.ceil(score[1] / 2);
2135 return ret + "-" + Math.ceil(score[1] / 2);
2137 } else if (score[0] === 'M' || score[0] === 'm') {
2138 var sign = (score[0] === 'm') ? '-' : '';
2139 if (score[2]) { // Is a bound.
2140 return score[2] + "\u00a0M " + sign + score[1];
2142 return "M " + sign + score[1];
2144 } else if (score[0] === 'd') {
2146 } else if (score[0] === 'cp') {
2147 if (score[2]) { // Is a bound.
2148 return score[2] + "\u00a0" + fmt_cp(score[1]);
2150 return fmt_cp(score[1]);
2156 var format_long_score = function(score) {
2160 if (score[0] === 'T') {
2161 if (score[1] == 0) {
2162 return "Won for white (tablebase)";
2164 return "White wins in " + Math.ceil(score[1] / 2);
2166 } else if (score[0] === 't') {
2167 if (score[1] == -1) {
2168 return "Won for black (tablebase)";
2170 return "Black wins in " + Math.ceil(score[1] / 2);
2172 } else if (score[0] === 'M') {
2173 if (score[1] == 0) {
2174 return "White wins by checkmate";
2176 return "White mates in " + score[1];
2178 } else if (score[0] === 'm') {
2179 if (score[1] == 0) {
2180 return "Black wins by checkmate";
2182 return "Black mates in " + score[1];
2184 } else if (score[0] === 'd') {
2185 return "Theoretical draw";
2186 } else if (score[0] === 'cp') {
2187 return "Score: " + format_short_score(score);
2192 var compute_plot_score = function(score) {
2193 if (score[0] === 'M' || score[0] === 'T') {
2195 } else if (score[0] === 'm' || score[0] === 't') {
2197 } else if (score[0] === 'd') {
2199 } else if (score[0] === 'cp') {
2200 if (score[1] > 500) {
2202 } else if (score[1] < -500) {
2212 * @param score The score digest tuple.
2213 * @param {?number} depth Depth the move has been computed to, or null.
2214 * @param {boolean} invert Whether black is to play.
2215 * @param {boolean=} depth_secondary_key
2218 var compute_score_sort_key = function(score, depth, invert, depth_secondary_key) {
2223 if (score[0] === 'T') {
2224 // White reaches TB win.
2225 s = 89999 - score[1];
2226 } else if (score[0] === 't') {
2227 // Black reaches TB win.
2228 s = -(89999 - score[1]);
2229 } else if (score[0] === 'M') {
2231 s = 99999 - score[1];
2232 } else if (score[0] === 'm') {
2234 s = -(99999 - score[1]);
2235 } else if (score[0] === 'd') {
2237 } else if (score[0] === 'cp') {
2242 if (depth_secondary_key) {
2243 return s * 200 + (depth || 0);
2253 * @param {Object} game
2255 var switch_backend = function(game) {
2256 // Stop looking at historic data.
2257 current_display_line = null;
2258 current_display_move = null;
2259 displayed_analysis_data = null;
2260 if (current_historic_xhr) {
2261 current_historic_xhr.abort();
2264 // If we already have a backend response going, abort it.
2265 if (current_analysis_xhr) {
2266 current_analysis_xhr.abort();
2268 if (current_hash_xhr) {
2269 current_hash_xhr.abort();
2272 // Otherwise, we should have a timer going to start a new one.
2274 if (current_analysis_request_timer) {
2275 clearTimeout(current_analysis_request_timer);
2276 current_analysis_request_timer = null;
2278 if (current_hash_display_timer) {
2279 clearTimeout(current_hash_display_timer);
2280 current_hash_display_timer = null;
2283 // Request an immediate fetch with the new backend.
2284 backend_url = game['url'];
2285 backend_hash_url = game['hashurl'];
2286 window.location.hash = '#' + game['id'];
2287 current_analysis_data = null;
2291 window['switch_backend'] = switch_backend;
2293 window['flip'] = function() { board.flip(); redraw_arrows(); };
2295 // Mostly from Wikipedia's chess set as of October 2022, but some pieces are from
2296 // the 2013 version, as I like those better (and it matches the 2014 PNGs; nobody
2297 // really likes change, do they?). That is wK, bK, bQ. wQ is also slightly different,
2298 // but not enough to notice.
2299 const svg_pieces = {
2300 'wK': 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhRE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HN0cm9rZS13aWR0aDoxLjU7IHN0cm9rZS1saW5lY2FwOnJvdW5kOyBzdHJva2UtbGluZWpvaW46bWl0ZXI7IHN0cm9rZS1taXRlcmxpbWl0OjQ7IHN0cm9rZS1kYXNoYXJyYXk6bm9uZTsgc3Ryb2tlLW9wYWNpdHk6MTsiLz4KPC9zdmc+Cg==',
2314 var svg_piece_theme = function(piece) {
2315 return svg_pieces[piece];
2318 var init = function() {
2319 unique = get_unique();
2321 // Load settings from HTML5 local storage if available.
2322 if (supports_html5_storage() && localStorage['enable_sound']) {
2323 set_sound(parseInt(localStorage['enable_sound']));
2329 board = new window.ChessBoard('board', {
2330 onMoveEnd: function() { board_is_animating = false; },
2333 pieceTheme: svg_piece_theme,
2334 onDragStart: onDragStart,
2336 onSnapEnd: onSnapEnd
2338 $("#board").on('mousedown', '.square-55d63', mousedownSquare);
2339 $("#board").on('mouseup', '.square-55d63', mouseupSquare);
2342 $(window).resize(function() {
2344 update_sparkline(displayed_analysis_data || current_analysis_data);
2345 update_board_highlight();
2348 $(window).keyup(function(event) {
2349 if (event.which == 39) { // Left arrow.
2351 } else if (event.which == 37) { // Right arrow.
2353 } else if (event.which >= 49 && event.which <= 57) { // 1-9.
2354 var num = event.which - 49;
2355 if (current_games && current_games.length >= num) {
2356 switch_backend(current_games[num]);
2358 } else if (event.which == 78) { // N.
2362 window.addEventListener('hashchange', possibly_switch_game_from_hash, false);
2363 possibly_switch_game_from_hash();
2365 $(document).ready(init);