X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=53393dfcea8cde3b7f0a9253ef4a9a7c6d20caf7;hb=b99ce1fb4539b6ac0afd686acc39e2776e7961b4;hp=6efce0206a96a0bd12e0ae37c09ec2baa8e29f3f;hpb=6f74b81a893da23181f30e2ef1e68bde8a5476cd;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 6efce02..53393df 100644 --- a/base_rules.js +++ b/base_rules.js @@ -1102,7 +1102,8 @@ export default class ChessRules { // Is (x,y) on the chessboard? onBoard(x, y) { - return x >= 0 && x < this.size.x && y >= 0 && y < this.size.y; + return (x >= 0 && x < this.size.x && + y >= 0 && y < this.size.y); } // Used in interface: 'side' arg == player color @@ -1363,23 +1364,24 @@ export default class ChessRules { return moves; } + // NOTE: using special symbols to not interfere with variants' pieces codes static get CannibalKings() { return { - "s": "p", - "u": "r", - "o": "n", - "c": "b", - "t": "q" + "!": "p", + "#": "r", + "$": "n", + "%": "b", + "*": "q" }; } static get CannibalKingCode() { return { - "p": "s", - "r": "u", - "n": "o", - "b": "c", - "q": "t", + "p": "!", + "r": "#", + "n": "$", + "b": "%", + "q": "*", "k": "k" }; } @@ -2189,7 +2191,9 @@ export default class ChessRules { playVisual(move, r) { move.vanish.forEach(v => { if (!this.enlightened || this.enlightened[v.x][v.y]) { - this.g_pieces[v.x][v.y].remove(); + // TODO: next "if" shouldn't be required + if (this.g_pieces[v.x][v.y]) + this.g_pieces[v.x][v.y].remove(); this.g_pieces[v.x][v.y] = null; } }); @@ -2242,6 +2246,11 @@ export default class ChessRules { const dropMove = (typeof i1 == "string"); const startArray = (dropMove ? this.r_pieces : this.g_pieces); let startPiece = startArray[i1][j1]; + // TODO: next "if" shouldn't be required + if (!startPiece) { + callback(); + return; + } let chessboard = document.getElementById(this.containerId).querySelector(".chessboard"); const clonePiece = (