From 7de3f2a065a0928d9e3b6f278464ca6258e2e6c9 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 9 Feb 2018 19:12:43 +0100 Subject: [PATCH] Fix visualization of Chess960 moves where the king does not move. --- www/js/remoteglot.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index ff566ab..f6c06bb 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -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); } -- 2.39.2