X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Fjs%2Fchess.js;h=f274628273e33c6d964f3274bf524046ed5e0e61;hb=045fcbf700505f71416672ab1aaa2fbe6f7e58e4;hp=6d6623e4d90005e7b5616346ca920391a4963d17;hpb=01b20c4f22ef463dec8262498848d3f7236b34ef;p=remoteglot diff --git a/www/js/chess.js b/www/js/chess.js index 6d6623e..f274628 100644 --- a/www/js/chess.js +++ b/www/js/chess.js @@ -242,7 +242,7 @@ var Chess = function(fen) { var i, flag; if (white_frc_columns !== null) { for (i = 0; i < white_frc_columns.length; ++i) { - var sq = SQUARES.a1 + (white_frc_columns[0].charCodeAt(0) - "A".charCodeAt(0)); + var sq = SQUARES.a1 + (white_frc_columns[i].charCodeAt(0) - "A".charCodeAt(0)); flag = sq < kings[WHITE] ? BITS.QSIDE_CASTLE : BITS.KSIDE_CASTLE; castling.w |= flag; rooks[WHITE].push({square: sq, flag: flag}); @@ -270,7 +270,7 @@ var Chess = function(fen) { var black_frc_columns = tokens[2].match(/[a-h]/g); if (black_frc_columns !== null) { for (i = 0; i < black_frc_columns.length; ++i) { - var sq = SQUARES.a1 + (black_frc_columns[0].charCodeAt(0) - "A".charCodeAt(0)); + var sq = SQUARES.a8 + (black_frc_columns[i].charCodeAt(0) - "a".charCodeAt(0)); flag = sq < kings[BLACK] ? BITS.QSIDE_CASTLE : BITS.KSIDE_CASTLE; castling.b |= flag; rooks[BLACK].push({square: sq, flag: flag}); @@ -997,14 +997,14 @@ var Chess = function(fen) { if (move.flags & BITS.KSIDE_CASTLE) { var castling_to = move.to - 1; var castling_from = move.rook_sq; - board[castling_to] = board[castling_from]; - if(castling_from !== move.to) + board[castling_to] = {type: ROOK, color: us}; + if(castling_from !== move.to && castling_from !== castling_to) board[castling_from] = null; } else if (move.flags & BITS.QSIDE_CASTLE) { var castling_to = move.to + 1; var castling_from = move.rook_sq; - board[castling_to] = board[castling_from]; - if(castling_from !== move.to) + board[castling_to] = {type: ROOK, color: us}; + if(castling_from !== move.to && castling_from !== castling_to) board[castling_from] = null; } @@ -1104,8 +1104,8 @@ var Chess = function(fen) { castling_from = move.to + 1; } - board[castling_to] = board[castling_from]; - if(castling_from !== move.from) + board[castling_to] = {type: ROOK, color: us}; + if(castling_from !== move.from && castling_from !== castling_to) board[castling_from] = null; }