3 /** @type {window.ChessBoard} @private */
7 * The most recent analysis data we have from the server
8 * (about the most recent position).
12 var current_analysis_data = null;
15 * If we are displaying previous analysis, this is non-null,
16 * and will override most of current_analysis_data.
21 var displayed_analysis_data = null;
36 /** @type {Array.<Array.<boolean>>} */
37 var occupied_by_arrows = [];
39 var refutation_lines = [];
41 /** @type {!number} @private */
44 /** @type {!string} @private */
47 /** @type {number} @private */
50 /** @type {boolean} @private */
51 var sort_refutation_lines_by_score = true;
53 /** @type {boolean} @private */
54 var truncate_display_history = true;
56 /** @type {!string|undefined} @private */
57 var highlight_from = undefined;
59 /** @type {!string|undefined} @private */
60 var highlight_to = undefined;
62 /** @type {?jQuery} @private */
63 var highlighted_move = null;
65 /** @type {?number} @private */
68 /** The current position on the board, represented as a FEN string.
76 * uci_pv: Array.<string>,
77 * pretty_pv: Array.<string>,
82 /** @type {Array.<DisplayLine>}
85 var display_lines = [];
87 /** @type {?DisplayLine} @private */
88 var current_display_line = null;
90 /** @type {boolean} @private */
91 var current_display_line_is_history = false;
93 /** @type {?number} @private */
94 var current_display_move = null;
96 var supports_html5_storage = function() {
98 return 'localStorage' in window && window['localStorage'] !== null;
104 // Make the unique token persistent so people refreshing the page won't count twice.
105 // Of course, you can never fully protect against people deliberately wanting to spam.
106 var get_unique = function() {
107 var use_local_storage = supports_html5_storage();
108 if (use_local_storage && localStorage['unique']) {
109 return localStorage['unique'];
111 var unique = Math.random();
112 if (use_local_storage) {
113 localStorage['unique'] = unique;
118 var request_update = function() {
120 url: "/analysis.pl?ims=" + ims + "&unique=" + unique
121 }).done(function(data, textstatus, xhr) {
122 ims = xhr.getResponseHeader('X-Remoteglot-Last-Modified');
123 var num_viewers = xhr.getResponseHeader('X-Remoteglot-Num-Viewers');
124 current_analysis_data = data;
125 update_board(current_analysis_data, displayed_analysis_data);
126 update_num_viewers(num_viewers);
129 setTimeout(function() { request_update(); }, 100);
131 // Wait ten seconds, then try again.
132 setTimeout(function() { request_update(); }, 10000);
136 var clear_arrows = function() {
137 for (var i = 0; i < arrows.length; ++i) {
139 arrows[i].svg.parentElement.removeChild(arrows[i].svg);
140 delete arrows[i].svg;
145 occupied_by_arrows = [];
146 for (var y = 0; y < 8; ++y) {
147 occupied_by_arrows.push([false, false, false, false, false, false, false, false]);
151 var redraw_arrows = function() {
152 for (var i = 0; i < arrows.length; ++i) {
153 position_arrow(arrows[i]);
157 /** @param {!number} x
160 var sign = function(x) {
170 /** See if drawing this arrow on the board would cause unduly amount of confusion.
171 * @param {!string} from The square the arrow is from (e.g. e4).
172 * @param {!string} to The square the arrow is to (e.g. e4).
175 var interfering_arrow = function(from, to) {
176 var from_col = from.charCodeAt(0) - "a1".charCodeAt(0);
177 var from_row = from.charCodeAt(1) - "a1".charCodeAt(1);
178 var to_col = to.charCodeAt(0) - "a1".charCodeAt(0);
179 var to_row = to.charCodeAt(1) - "a1".charCodeAt(1);
181 occupied_by_arrows[from_row][from_col] = true;
183 // Knight move: Just check that we haven't been at the destination before.
184 if ((Math.abs(to_col - from_col) == 2 && Math.abs(to_row - from_row) == 1) ||
185 (Math.abs(to_col - from_col) == 1 && Math.abs(to_row - from_row) == 2)) {
186 return occupied_by_arrows[to_row][to_col];
189 // Sliding piece: Check if anything except the from-square is seen before.
190 var dx = sign(to_col - from_col);
191 var dy = sign(to_row - from_row);
197 if (occupied_by_arrows[y][x]) {
200 occupied_by_arrows[y][x] = true;
201 } while (x != to_col || y != to_row);
206 /** Find a point along the coordinate system given by the given line,
207 * <t> units forward from the start of the line, <u> units to the right of it.
208 * @param {!number} x1
209 * @param {!number} x2
210 * @param {!number} y1
211 * @param {!number} y2
214 * @return {!string} The point in "x y" form, suitable for SVG paths.
216 var point_from_start = function(x1, y1, x2, y2, t, u) {
220 var norm = 1.0 / Math.sqrt(dx * dx + dy * dy);
224 var x = x1 + dx * t + dy * u;
225 var y = y1 + dy * t - dx * u;
229 /** Find a point along the coordinate system given by the given line,
230 * <t> units forward from the end of the line, <u> units to the right of it.
231 * @param {!number} x1
232 * @param {!number} x2
233 * @param {!number} y1
234 * @param {!number} y2
237 * @return {!string} The point in "x y" form, suitable for SVG paths.
239 var point_from_end = function(x1, y1, x2, y2, t, u) {
243 var norm = 1.0 / Math.sqrt(dx * dx + dy * dy);
247 var x = x2 + dx * t + dy * u;
248 var y = y2 + dy * t - dx * u;
252 var position_arrow = function(arrow) {
254 arrow.svg.parentElement.removeChild(arrow.svg);
257 if (current_display_line !== null && !current_display_line_is_history) {
261 var pos = $(".square-a8").position();
263 var zoom_factor = $("#board").width() / 400.0;
264 var line_width = arrow.line_width * zoom_factor;
265 var arrow_size = arrow.arrow_size * zoom_factor;
267 var square_width = $(".square-a8").width();
268 var from_y = (7 - arrow.from_row + 0.5)*square_width;
269 var to_y = (7 - arrow.to_row + 0.5)*square_width;
270 var from_x = (arrow.from_col + 0.5)*square_width;
271 var to_x = (arrow.to_col + 0.5)*square_width;
273 var SVG_NS = "http://www.w3.org/2000/svg";
274 var XHTML_NS = "http://www.w3.org/1999/xhtml";
275 var svg = document.createElementNS(SVG_NS, "svg");
276 svg.setAttribute("width", /** @type{number} */ ($("#board").width()));
277 svg.setAttribute("height", /** @type{number} */ ($("#board").height()));
278 svg.setAttribute("style", "position: absolute");
279 svg.setAttribute("position", "absolute");
280 svg.setAttribute("version", "1.1");
281 svg.setAttribute("class", "c1");
282 svg.setAttribute("xmlns", XHTML_NS);
290 var outline = document.createElementNS(SVG_NS, "path");
291 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));
292 outline.setAttribute("xmlns", XHTML_NS);
293 outline.setAttribute("stroke", "#666");
294 outline.setAttribute("stroke-width", line_width + 2);
295 outline.setAttribute("fill", "none");
296 svg.appendChild(outline);
298 var path = document.createElementNS(SVG_NS, "path");
299 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));
300 path.setAttribute("xmlns", XHTML_NS);
301 path.setAttribute("stroke", arrow.fg_color);
302 path.setAttribute("stroke-width", line_width);
303 path.setAttribute("fill", "none");
304 svg.appendChild(path);
306 // Then the arrow head.
307 var head = document.createElementNS(SVG_NS, "path");
308 head.setAttribute("d",
309 "M " + point_from_end(x1, y1, x2, y2, 0, 0) +
310 " L " + point_from_end(x1, y1, x2, y2, -arrow_size, -arrow_size / 2) +
311 " L " + point_from_end(x1, y1, x2, y2, -arrow_size * .623, 0.0) +
312 " L " + point_from_end(x1, y1, x2, y2, -arrow_size, arrow_size / 2) +
313 " L " + point_from_end(x1, y1, x2, y2, 0, 0));
314 head.setAttribute("xmlns", XHTML_NS);
315 head.setAttribute("stroke", "#000");
316 head.setAttribute("stroke-width", "1");
317 head.setAttribute("fill", arrow.fg_color);
318 svg.appendChild(head);
320 $(svg).css({ top: pos.top, left: pos.left });
321 document.body.appendChild(svg);
326 * @param {!string} from_square
327 * @param {!string} to_square
328 * @param {!string} fg_color
329 * @param {number} line_width
330 * @param {number} arrow_size
332 var create_arrow = function(from_square, to_square, fg_color, line_width, arrow_size) {
333 var from_col = from_square.charCodeAt(0) - "a1".charCodeAt(0);
334 var from_row = from_square.charCodeAt(1) - "a1".charCodeAt(1);
335 var to_col = to_square.charCodeAt(0) - "a1".charCodeAt(0);
336 var to_row = to_square.charCodeAt(1) - "a1".charCodeAt(1);
344 line_width: line_width,
345 arrow_size: arrow_size,
349 position_arrow(arrow);
353 var compare_by_sort_key = function(refutation_lines, a, b) {
354 var ska = refutation_lines[a]['sort_key'];
355 var skb = refutation_lines[b]['sort_key'];
356 if (ska < skb) return -1;
357 if (ska > skb) return 1;
361 var compare_by_score = function(refutation_lines, a, b) {
362 var sa = parseInt(refutation_lines[b]['score_sort_key'], 10);
363 var sb = parseInt(refutation_lines[a]['score_sort_key'], 10);
368 * Fake multi-PV using the refutation lines. Find all “relevant” moves,
369 * sorted by quality, descending.
371 * @param {!Object} data
372 * @param {number} margin The maximum number of centipawns worse than the
373 * best move can be and still be included.
374 * @return {Array.<string>} The UCI representation (e.g. e1g1) of all
375 * moves, in score order.
377 var find_nonstupid_moves = function(data, margin) {
378 // First of all, if there are any moves that are more than 0.5 ahead of
379 // the primary move, the refutation lines are probably bunk, so just
381 var best_score = undefined;
382 var pv_score = undefined;
383 for (var move in data['refutation_lines']) {
384 var score = parseInt(data['refutation_lines'][move]['score_sort_key'], 10);
385 if (move == data['pv_uci'][0]) {
388 if (best_score === undefined || score > best_score) {
391 if (!(data['refutation_lines'][move]['depth'] >= 8)) {
396 if (best_score - pv_score > 50) {
400 // Now find all moves that are within “margin” of the best score.
401 // The PV move will always be first.
403 for (var move in data['refutation_lines']) {
404 var score = parseInt(data['refutation_lines'][move]['score_sort_key'], 10);
405 if (move != data['pv_uci'][0] && best_score - score <= margin) {
409 moves = moves.sort(function(a, b) { return compare_by_score(data['refutation_lines'], a, b) });
410 moves.unshift(data['pv_uci'][0]);
419 var thousands = function(x) {
420 return String(x).split('').reverse().join('').replace(/(\d{3}\B)/g, '$1,').split('').reverse().join('');
424 * @param {!string} fen
425 * @param {Array.<string>} pretty_pv
426 * @param {number} move_num
427 * @param {!string} toplay
428 * @param {number=} opt_limit
429 * @param {boolean=} opt_showlast
431 var add_pv = function(fen, pretty_pv, move_num, toplay, opt_limit, opt_showlast) {
434 pretty_pv: pretty_pv,
435 line_number: display_lines.length
437 return print_pv(display_lines.length - 1, pretty_pv, move_num, toplay, opt_limit, opt_showlast);
441 * @param {number} line_num
442 * @param {Array.<string>} pretty_pv
443 * @param {number} move_num
444 * @param {!string} toplay
445 * @param {number=} opt_limit
446 * @param {boolean=} opt_showlast
448 var print_pv = function(line_num, pretty_pv, move_num, toplay, opt_limit, opt_showlast) {
451 if (opt_limit && opt_showlast && pretty_pv.length > opt_limit) {
452 // Truncate the PV at the beginning (instead of at the end).
453 // We assume here that toplay is 'W'. We also assume that if
454 // opt_showlast is set, then it is the history, and thus,
455 // the UI should be to expand the history.
456 pv = '(<a class="move" href="javascript:collapse_history(false)">…</a>) ';
457 i = pretty_pv.length - opt_limit;
462 } else if (toplay == 'B' && pretty_pv.length > 0) {
463 var move = "<a class=\"move\" id=\"automove" + line_num + "-0\" href=\"javascript:show_line(" + line_num + ", " + 0 + ");\">" + pretty_pv[0] + "</a>";
464 pv = move_num + '. … ' + move;
469 for ( ; i < pretty_pv.length; ++i) {
470 var move = "<a class=\"move\" id=\"automove" + line_num + "-" + i + "\" href=\"javascript:show_line(" + line_num + ", " + i + ");\">" + pretty_pv[i] + "</a>";
473 if (i > opt_limit && !opt_showlast) {
479 pv += move_num + '. ' + move;
490 var update_highlight = function() {
491 $("#board").find('.square-55d63').removeClass('nonuglyhighlight');
492 if ((current_display_line === null || current_display_line_is_history) &&
493 highlight_from !== undefined && highlight_to !== undefined) {
494 $("#board").find('.square-' + highlight_from).addClass('nonuglyhighlight');
495 $("#board").find('.square-' + highlight_to).addClass('nonuglyhighlight');
499 var update_history = function() {
500 if (display_lines[0] === null || display_lines[0].pretty_pv.length == 0) {
501 $("#history").html("No history");
502 } else if (truncate_display_history) {
503 $("#history").html(print_pv(0, display_lines[0].pretty_pv, 1, 'W', 8, true));
506 '(<a class="move" href="javascript:collapse_history(true)">collapse</a>) ' +
507 print_pv(0, display_lines[0].pretty_pv, 1, 'W'));
512 * @param {!boolean} truncate_history
514 var collapse_history = function(truncate_history) {
515 truncate_display_history = truncate_history;
518 window['collapse_history'] = collapse_history;
520 var update_refutation_lines = function() {
524 if (display_lines.length > 2) {
525 display_lines = [ display_lines[0], display_lines[1] ];
528 var tbl = $("#refutationlines");
532 for (var move in refutation_lines) {
535 var compare = sort_refutation_lines_by_score ? compare_by_score : compare_by_sort_key;
536 moves = moves.sort(function(a, b) { return compare(refutation_lines, a, b) });
537 for (var i = 0; i < moves.length; ++i) {
538 var line = refutation_lines[moves[i]];
540 var tr = document.createElement("tr");
542 var move_td = document.createElement("td");
543 tr.appendChild(move_td);
544 $(move_td).addClass("move");
545 if (line['pv_pretty'].length == 0) {
546 $(move_td).text(line['pretty_move']);
548 var move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['pretty_move'] + "</a>";
549 $(move_td).html(move);
552 var score_td = document.createElement("td");
553 tr.appendChild(score_td);
554 $(score_td).addClass("score");
555 $(score_td).text(line['pretty_score']);
557 var depth_td = document.createElement("td");
558 tr.appendChild(depth_td);
559 $(depth_td).addClass("depth");
560 $(depth_td).text("d" + line['depth']);
562 var pv_td = document.createElement("td");
563 tr.appendChild(pv_td);
564 $(pv_td).addClass("pv");
565 $(pv_td).html(add_pv(fen, line['pv_pretty'], move_num, toplay, 10));
570 // Make one of the links clickable and the other nonclickable.
571 if (sort_refutation_lines_by_score) {
572 $("#sortbyscore0").html("<a href=\"javascript:resort_refutation_lines(false)\">Move</a>");
573 $("#sortbyscore1").html("<strong>Score</strong>");
575 $("#sortbyscore0").html("<strong>Move</strong>");
576 $("#sortbyscore1").html("<a href=\"javascript:resort_refutation_lines(true)\">Score</a>");
581 * @param {Object} data
582 * @param {?Object} display_data
584 var update_board = function(current_data, display_data) {
585 var data = display_data || current_data;
589 // Print the history. This is pretty much the only thing that's
590 // unconditionally taken from current_data (we're not interested in
591 // historic history).
592 if (current_data['position']['pretty_history']) {
593 add_pv('start', current_data['position']['pretty_history'], 1, 'W', 8, true);
595 display_lines.push(null);
599 // The headline. Names are always fetched from current_data;
600 // the rest can depend a bit.
603 current_data['position']['player_w'] && current_data['position']['player_b']) {
604 headline = current_data['position']['player_w'] + '–' +
605 current_data['position']['player_b'] + ', analysis';
607 headline = 'Analysis';
612 // Displaying some non-current position, pick out the last move
613 // from the history. This will work even if the fetch failed.
614 last_move = format_move_with_number(
615 current_display_line.pretty_pv[current_display_move],
616 Math.floor((current_display_move + 1) / 2) + 1,
617 (current_display_move % 2 == 1));
618 headline += ' after ' + last_move;
619 } else if (data['position']['last_move'] !== 'none') {
620 last_move = format_move_with_number(
621 data['position']['last_move'],
622 data['position']['move_num'],
623 data['position']['toplay'] == 'W');
624 headline += ' after ' + last_move;
628 $("#headline").text(headline);
630 // The <title> contains a very brief headline.
631 var title_elems = [];
632 if (data['short_score'] !== undefined && data['short_score'] !== null) {
633 title_elems.push(data['short_score']);
635 if (last_move !== null) {
636 title_elems.push(last_move);
639 if (title_elems.length != 0) {
640 document.title = '(' + title_elems.join(', ') + ') analysis.sesse.net';
642 document.title = 'analysis.sesse.net';
645 if (data['failed']) {
646 $("#score").text("No analysis for this move");
648 $("#searchstats").html(" ");
649 $("#refutationlines").empty();
650 refutation_lines = [];
651 update_refutation_lines();
657 if (data['id'] && data['id']['name'] !== null) {
658 $("#engineid").text(data['id']['name']);
662 if (data['score'] !== null) {
663 $("#score").text(data['score']);
667 if (data['tablebase'] == 1) {
668 $("#searchstats").text("Tablebase result");
669 } else if (data['nodes'] && data['nps'] && data['depth']) {
670 var stats = thousands(data['nodes']) + ' nodes, ' + thousands(data['nps']) + ' nodes/sec, depth ' + data['depth'] + ' ply';
671 if (data['seldepth']) {
672 stats += ' (' + data['seldepth'] + ' selective)';
674 if (data['tbhits'] && data['tbhits'] > 0) {
675 if (data['tbhits'] == 1) {
676 stats += ', one Syzygy hit';
678 stats += ', ' + thousands(data['tbhits']) + ' Syzygy hits';
682 $("#searchstats").text(stats);
684 $("#searchstats").text("");
687 // Update the board itself.
688 fen = data['position']['fen'];
689 update_displayed_line();
691 if (data['position']['last_move_uci']) {
692 highlight_from = data['position']['last_move_uci'].substr(0, 2);
693 highlight_to = data['position']['last_move_uci'].substr(2, 2);
695 highlight_from = highlight_to = undefined;
700 $("#pv").html(add_pv(data['position']['fen'], data['pv_pretty'], data['position']['move_num'], data['position']['toplay']));
702 // Update the PV arrow.
704 if (data['pv_uci'].length >= 1) {
705 // draw a continuation arrow as long as it's the same piece
706 for (var i = 0; i < data['pv_uci'].length; i += 2) {
707 var from = data['pv_uci'][i].substr(0, 2);
708 var to = data['pv_uci'][i].substr(2,4);
709 if ((i >= 2 && from != data['pv_uci'][i - 2].substr(2, 2)) ||
710 interfering_arrow(from, to)) {
713 create_arrow(from, to, '#f66', 6, 20);
716 var alt_moves = find_nonstupid_moves(data, 30);
717 for (var i = 1; i < alt_moves.length && i < 3; ++i) {
718 create_arrow(alt_moves[i].substr(0, 2),
719 alt_moves[i].substr(2, 2), '#f66', 1, 10);
723 // See if all semi-reasonable moves have only one possible response.
724 if (data['pv_uci'].length >= 2) {
725 var nonstupid_moves = find_nonstupid_moves(data, 300);
726 var response = data['pv_uci'][1];
727 for (var i = 0; i < nonstupid_moves.length; ++i) {
728 if (nonstupid_moves[i] == data['pv_uci'][0]) {
729 // ignore the PV move for refutation lines.
732 if (!data['refutation_lines'] ||
733 !data['refutation_lines'][nonstupid_moves[i]] ||
734 !data['refutation_lines'][nonstupid_moves[i]]['pv_uci'] ||
735 data['refutation_lines'][nonstupid_moves[i]]['pv_uci'].length < 1) {
736 // Incomplete PV, abort.
737 response = undefined;
740 var this_response = data['refutation_lines'][nonstupid_moves[i]]['pv_uci'][1];
741 if (response !== this_response) {
742 // Different response depending on lines, abort.
743 response = undefined;
748 if (nonstupid_moves.length > 0 && response !== undefined) {
749 create_arrow(response.substr(0, 2),
750 response.substr(2, 2), '#66f', 6, 20);
754 // Update the refutation lines.
755 fen = data['position']['fen'];
756 move_num = data['position']['move_num'];
757 toplay = data['position']['toplay'];
758 refutation_lines = data['refutation_lines'];
759 update_refutation_lines();
763 * @param {number} num_viewers
765 var update_num_viewers = function(num_viewers) {
766 if (num_viewers === null) {
767 $("#numviewers").text("");
768 } else if (num_viewers == 1) {
769 $("#numviewers").text("You are the only current viewer");
771 $("#numviewers").text(num_viewers + " current viewers");
776 * @param {string} move
777 * @param {Number} move_num
778 * @param {boolean} white_to_play
780 var format_move_with_number = function(move, move_num, white_to_play) {
783 ret = (move_num - 1) + '… ';
785 ret = move_num + '. ';
792 * @param {boolean} sort_by_score
794 var resort_refutation_lines = function(sort_by_score) {
795 sort_refutation_lines_by_score = sort_by_score;
796 update_refutation_lines();
798 window['resort_refutation_lines'] = resort_refutation_lines;
801 * @param {boolean} truncate_history
803 var set_truncate_history = function(truncate_history) {
804 truncate_display_history = truncate_history;
805 update_refutation_lines();
807 window['set_truncate_history'] = set_truncate_history;
810 * @param {number} line_num
811 * @param {number} move_num
813 var show_line = function(line_num, move_num) {
814 if (line_num == -1) {
815 current_display_line = null;
816 current_display_move = null;
817 if (displayed_analysis_data) {
818 // TODO: Support exiting to history position if we are in an
819 // analysis line of a history position.
820 displayed_analysis_data = null;
821 update_board(current_analysis_data, displayed_analysis_data);
824 current_display_line = display_lines[line_num];
825 current_display_move = move_num;
827 current_display_line_is_history = (line_num == 0);
829 update_historic_analysis();
830 update_displayed_line();
834 window['show_line'] = show_line;
836 var prev_move = function() {
837 if (current_display_move > -1) {
838 --current_display_move;
840 update_historic_analysis();
841 update_displayed_line();
843 window['prev_move'] = prev_move;
845 var next_move = function() {
846 if (current_display_line && current_display_move < current_display_line.pretty_pv.length - 1) {
847 ++current_display_move;
849 update_historic_analysis();
850 update_displayed_line();
852 window['next_move'] = next_move;
854 var update_historic_analysis = function() {
855 if (!current_display_line_is_history) {
858 if (current_display_move == current_display_line.pretty_pv.length - 1) {
859 displayed_analysis_data = null;
860 update_board(current_analysis_data, displayed_analysis_data);
863 // Fetch old analysis for this line if it exists.
864 var hiddenboard = new Chess();
865 for (var i = 0; i <= current_display_move; ++i) {
866 hiddenboard.move(current_display_line.pretty_pv[i]);
868 var filename = "/history/move" + (current_display_move + 1) + "-" +
869 hiddenboard.fen().replace(/ /g, '_').replace(/\//g, '-') + ".json";
873 }).done(function(data, textstatus, xhr) {
874 displayed_analysis_data = data;
875 update_board(current_analysis_data, displayed_analysis_data);
877 displayed_analysis_data = {'failed': true};
878 update_board(current_analysis_data, displayed_analysis_data);
882 var update_displayed_line = function() {
883 if (highlighted_move !== null) {
884 highlighted_move.removeClass('highlight');
886 if (current_display_line === null) {
887 $("#linenav").hide();
888 $("#linemsg").show();
893 $("#linenav").show();
894 $("#linemsg").hide();
896 if (current_display_move <= 0) {
897 $("#prevmove").html("Previous");
899 $("#prevmove").html("<a href=\"javascript:prev_move();\">Previous</a></span>");
901 if (current_display_move == current_display_line.pretty_pv.length - 1) {
902 $("#nextmove").html("Next");
904 $("#nextmove").html("<a href=\"javascript:next_move();\">Next</a></span>");
907 var hiddenboard = new Chess();
908 hiddenboard.load(current_display_line.start_fen);
909 for (var i = 0; i <= current_display_move; ++i) {
910 hiddenboard.move(current_display_line.pretty_pv[i]);
913 highlighted_move = $("#automove" + current_display_line.line_number + "-" + current_display_move);
914 highlighted_move.addClass('highlight');
916 board.position(hiddenboard.fen());
919 var init = function() {
920 unique = get_unique();
923 board = new window.ChessBoard('board', 'start');
926 $(window).resize(function() {
931 $(window).keyup(function(event) {
932 if (event.which == 39) {
934 } else if (event.which == 37) {
939 $(document).ready(init);