url: "/analysis.pl?ims=" + ims + "&unique=" + unique
}).done(function(data, textstatus, xhr) {
sync_server_clock(xhr.getResponseHeader('Date'));
- ims = xhr.getResponseHeader('X-Remoteglot-Last-Modified');
- var num_viewers = xhr.getResponseHeader('X-Remoteglot-Num-Viewers');
+ ims = xhr.getResponseHeader('X-RGLM');
+ var num_viewers = xhr.getResponseHeader('X-RGNV');
possibly_play_sound(current_analysis_data, data);
- current_analysis_data = data;
+ if (Array.isArray(data)) {
+ current_analysis_data = JSON_delta.patch(current_analysis_data, data);
+ } else {
+ current_analysis_data = data;
+ }
update_board(current_analysis_data, displayed_analysis_data);
update_num_viewers(num_viewers);
}
}
+/**
+ * @param {?string} fen
+ * @param {Array.<string>} moves
+ * @param {number} last_move
+ */
+var chess_from = function(fen, moves, last_move) {
+ var hiddenboard = new Chess();
+ if (fen !== null) {
+ hiddenboard.load(fen);
+ }
+ for (var i = 0; i <= last_move; ++i) {
+ if (moves[i] === '0-0') {
+ hiddenboard.move('O-O');
+ } else if (moves[i] === '0-0-0') {
+ hiddenboard.move('O-O-O');
+ } else {
+ hiddenboard.move(moves[i]);
+ }
+ }
+ return hiddenboard;
+}
+
/**
* @param {Object} data
* @param {?Object} display_data
// We don't have historic analysis for this position, but we
// can reconstruct what the last move was by just replaying
// from the start.
- var hiddenboard = new Chess();
- for (var i = 0; i <= current_display_move; ++i) {
- hiddenboard.move(current_display_line.pretty_pv[i]);
- }
+ var hiddenboard = chess_from(null, current_display_line.pretty_pv, current_display_move);
var moves = hiddenboard.history({ verbose: true });
var last_move = moves.pop();
highlight_from = last_move.from;
}
// Fetch old analysis for this line if it exists.
- var hiddenboard = new Chess();
- for (var i = 0; i <= current_display_move; ++i) {
- hiddenboard.move(current_display_line.pretty_pv[i]);
- }
+ var hiddenboard = chess_from(null, current_display_line.pretty_pv, current_display_move);
var filename = "/history/move" + (current_display_move + 1) + "-" +
hiddenboard.fen().replace(/ /g, '_').replace(/\//g, '-') + ".json";
$("#nextmove").html("<a href=\"javascript:next_move();\">Next</a></span>");
}
- var hiddenboard = new Chess();
- hiddenboard.load(current_display_line.start_fen);
- for (var i = 0; i <= current_display_move; ++i) {
- hiddenboard.move(current_display_line.pretty_pv[i]);
- }
-
highlighted_move = $("#automove" + current_display_line.line_number + "-" + current_display_move);
highlighted_move.addClass('highlight');
+ var hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pretty_pv, current_display_move);
board.position(hiddenboard.fen());
}