X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=www%2Fjs%2Fremoteglot.js;h=b3b8163f0bd1dca60ca0c495eda7b987c413b0bd;hp=ff566ab85c81c4ba4b33ff8a9853bec23d8f89ca;hb=b4059a786029132eb27769a42ca52eca6d8b44cc;hpb=01a8eaa3db2c015b25c0cf53df96b12493f3db58 diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index ff566ab..b3b8163 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -7,7 +7,7 @@ * @type {Number} * @const * @private */ -var SCRIPT_VERSION = 2016113002; +var SCRIPT_VERSION = 2016113007; /** * The current backend URL. @@ -945,6 +945,32 @@ var possibly_switch_game_from_hash = function() { } } +/** + * If this is a Chess960 castling which doesn't move the king, + * move the rook instead. +*/ +var patch_move = function(move) { + if (move === null) return null; + if (move.from !== move.to) return move; + + var f = move.rook_sq & 15; + var r = move.rook_sq >> 4; + var from = ('abcdefgh'.substring(f,f+1) + '87654321'.substring(r,r+1)); + var to = move.to; + + if (move.to === 'g1') { + to = 'f1'; + } else if (move.to === 'g8') { + to = 'f8'; + } else if (move.to === 'b1') { + to = 'c1'; + } else if (move.to === 'b8') { + to = 'c8'; + } + + return { from: from, to: to }; +} + /** Update all the HTML on the page, based on current global state. */ var update_board = function() { @@ -1174,7 +1200,8 @@ var update_board = function() { // draw a continuation arrow as long as it's the same piece var last_to; for (var i = 0; i < data['pv'].length; i += 2) { - var move = hiddenboard.move(data['pv'][i]); + var move = patch_move(hiddenboard.move(data['pv'][i])); + if ((i >= 2 && move.from != last_to) || interfering_arrow(move.from, move.to)) { break; @@ -1187,7 +1214,7 @@ var update_board = function() { var alt_moves = find_nonstupid_moves(data, 30, data['position']['toplay'] === 'B'); for (var i = 1; i < alt_moves.length && i < 3; ++i) { hiddenboard = new Chess(base_fen); - var move = hiddenboard.move(alt_moves[i]); + var move = patch_move(hiddenboard.move(alt_moves[i])); if (move !== null) { create_arrow(move.from, move.to, '#f66', 1, 10); }