X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=a0defd19f7d718c74ea7cdf361a9a3cb27e4904f;hb=5006aaca31fa5fa36cb82784d13f6d28d754c90c;hp=f9913c44bea0be04c6ba049fed65c97a18053492;hpb=b0803a78c26520265240764ba909c164f31d6fda;p=xogo.git diff --git a/base_rules.js b/base_rules.js index f9913c4..a0defd1 100644 --- a/base_rules.js +++ b/base_rules.js @@ -1171,8 +1171,12 @@ export default class ChessRules { //////////////////////// // PIECES SPECIFICATIONS + getPawnShift(color) { + return (color == "w" ? -1 : 1); + } + pieces(color, x, y) { - const pawnShift = (color == "w" ? -1 : 1); + const pawnShift = this.getPawnShift(color); // NOTE: jump 2 squares from first rank (pawns can be here sometimes) const initRank = ((color == 'w' && x >= 6) || (color == 'b' && x <= 1)); return { @@ -2102,8 +2106,10 @@ export default class ChessRules { //////////////////// // MOVES VALIDATION - // Is piece (or square) at given position attacked by "oppCol" ? + // Is piece (or square) at given position attacked by "oppCol(s)" ? underAttack([x, y], oppCol) { + if (!Array.isArray(oppCol)) + oppCol = [oppCol]; // An empty square is considered as king, // since it's used only in getCastleMoves (TODO?) const king = this.board[x][y] == "" || this.isKing(x, y); @@ -2113,7 +2119,7 @@ export default class ChessRules { this.findCapturesOn( [x, y], { - byCol: [oppCol], + byCol: oppCol, segments: this.options["cylinder"], one: true } @@ -2129,7 +2135,7 @@ export default class ChessRules { segments: this.options["cylinder"], one: true }, - ([i1, j1], [i2, j2]) => this.getColor(i2, j2) == oppCol + ([i1, j1], [i2, j2]) => oppCol.includes(this.getColor(i2, j2)) ) ) );