]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Support starting from a nonstandard position.
[remoteglot] / www / js / remoteglot.js
index d614c7ea1016a44f8b92afa841eb42c09b5a81b0..ff566ab85c81c4ba4b33ff8a9853bec23d8f89ca 100644 (file)
@@ -864,7 +864,7 @@ var update_refutation_lines = function() {
  */
 var chess_from = function(fen, moves, last_move) {
        var hiddenboard = new Chess();
-       if (fen !== null) {
+       if (fen !== null && fen !== undefined) {
                hiddenboard.load(fen);
        }
        for (var i = 0; i <= last_move; ++i) {
@@ -957,7 +957,8 @@ var update_board = function() {
        // unconditionally taken from current_data (we're not interested in
        // historic history).
        if (current_data['position']['history']) {
-               add_pv('start', current_data['position']['history'], 1, 'W', null, 0, 8, true);
+               var start = (current_data['position'] && current_data['position']['start_fen']) ? current_data['position']['start_fen'] : 'start';
+               add_pv(start, current_data['position']['history'], 1, 'W', null, 0, 8, true);
        } else {
                display_lines.push(null);
        }
@@ -1083,7 +1084,8 @@ var update_board = function() {
                // 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 = chess_from(null, current_display_line.pv, current_display_move);
+               var position = (data['position'] && data['position']['start_fen']) ? data['position']['start_fen'] : null;
+               var hiddenboard = chess_from(position, current_display_line.pv, current_display_move);
                var moves = hiddenboard.history({ verbose: true });
                last_move = moves.pop();
                highlight_from = last_move.from;
@@ -1607,7 +1609,7 @@ var update_historic_analysis = function() {
        }
 
        // Fetch old analysis for this line if it exists.
-       var hiddenboard = chess_from(null, current_display_line.pv, current_display_move);
+       var hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pv, current_display_move);
        var filename = "/history/move" + (current_display_move + 1) + "-" +
                hiddenboard.fen().replace(/ /g, '_').replace(/\//g, '-') + ".json";