From: Benjamin Auder Date: Tue, 26 Jul 2022 16:34:11 +0000 (+0200) Subject: After refactoring. Seems more or less ok X-Git-Url: https://git.auder.net/variants/Chakart/doc/scripts/img/pieces/index.css?a=commitdiff_plain;h=9aebe2aac02158a4f1c92ad0ac529f8ed245602e;p=xogo.git After refactoring. Seems more or less ok --- diff --git a/base_rules.js b/base_rules.js index 5b1a013..b315fd5 100644 --- a/base_rules.js +++ b/base_rules.js @@ -2080,7 +2080,7 @@ export default class ChessRules { // will be executed in filterValid() later. ( i != finalSquares[castleSide][0] && - this.underCheck([x, i], oppCol) + this.underCheck([[x, i]], oppCol) ) || ( @@ -2187,8 +2187,6 @@ export default class ChessRules { underCheck(square_s, oppCol) { if (this.options["taking"] || this.options["dark"]) return false; - if (!Array.isArray(square_s[0])) - square_s = [square_s]; return square_s.some(sq => this.underAttack(sq, oppCol)); } diff --git a/variants/Alice/class.js b/variants/Alice/class.js index e6d37b2..d1e389d 100644 --- a/variants/Alice/class.js +++ b/variants/Alice/class.js @@ -119,7 +119,7 @@ export default class AliceRules extends ChessRules { this.playOnBoard(m); m.appear.forEach(a => this.toggleWorld(a.x, a.y)); const kingAppear = m.appear.find(a => this.isKing(0, 0, a.p)); - const target = kingAppear ? [kingAppear.x, kingAppear.y] : kingPos; + const target = [kingAppear ? [kingAppear.x, kingAppear.y] : kingPos]; const res = this.underCheck(target, oppCol); m.appear.forEach(a => this.toggleWorld(a.x, a.y)); this.undoOnBoard(m); diff --git a/variants/Ambiguous/class.js b/variants/Ambiguous/class.js index 6d9ac7e..5e7029c 100644 --- a/variants/Ambiguous/class.js +++ b/variants/Ambiguous/class.js @@ -124,12 +124,12 @@ export default class AmbiguousRules extends ChessRules { pieces(color, x, y) { const targets = { - 's': {"class": "target-pawn", moves: []}, - 'u': {"class": "target-rook", moves: []}, - 'o': {"class": "target-knight", moves: []}, - 'c': {"class": "target-bishop", moves: []}, - 't': {"class": "target-queen", moves: []}, - 'l': {"class": "target-king", moves: []} + 's': {"class": "target-pawn"}, + 'u': {"class": "target-rook"}, + 'o': {"class": "target-knight"}, + 'c': {"class": "target-bishop"}, + 't': {"class": "target-queen"}, + 'l': {"class": "target-king"} }; return Object.assign({ 'g': {"class": "target"} }, targets, super.pieces(color, x, y)); diff --git a/variants/Antiking1/style.css b/variants/Antiking1/style.css index faf34b7..456922f 100644 --- a/variants/Antiking1/style.css +++ b/variants/Antiking1/style.css @@ -1,8 +1,2 @@ @import url("/variants/_Antiking/style.css"); - -piece.black.pawn { - background-image: url('/variants/Berolina/pieces/black_pawn.svg'); -} -piece.white.pawn { - background-image: url('/variants/Berolina/pieces/white_pawn.svg'); -} +@import url("/variants/_Berolina/style.css"); diff --git a/variants/Apocalypse/class.js b/variants/Apocalypse/class.js index 1f7cc7a..ace9c4d 100644 --- a/variants/Apocalypse/class.js +++ b/variants/Apocalypse/class.js @@ -68,7 +68,7 @@ export default class ApocalypseRules extends ChessRules { return { 'p': { "class": "pawn", - moves: [ + both: [ { steps: [[pawnShift, 0], [pawnShift, -1], [pawnShift, 1]], range: 1 diff --git a/variants/Balaklava/class.js b/variants/Balaklava/class.js index dd3cf62..e16322f 100644 --- a/variants/Balaklava/class.js +++ b/variants/Balaklava/class.js @@ -34,7 +34,7 @@ export default class BalaklavaRules extends ChessRules { genRandInitBaseFen() { const baseFen = super.genRandInitBaseFen(); return { - fen: baseFen.replace(/n/g, 'm').replace(/N/g, 'M'), + fen: baseFen.fen.replace(/n/g, 'm').replace(/N/g, 'M'), o: baseFen.o }; } diff --git a/variants/Balaklava/pieces/CREDITS b/variants/Balaklava/pieces/CREDITS new file mode 100644 index 0000000..b4b12de --- /dev/null +++ b/variants/Balaklava/pieces/CREDITS @@ -0,0 +1 @@ +https://www.flaticon.com/free-icon/mammoth_925138 diff --git a/variants/Balaklava/pieces/black_mammoth.svg b/variants/Balaklava/pieces/black_mammoth.svg new file mode 100644 index 0000000..8ed01bc --- /dev/null +++ b/variants/Balaklava/pieces/black_mammoth.svg @@ -0,0 +1,188 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/variants/Balaklava/pieces/white_mammoth.svg b/variants/Balaklava/pieces/white_mammoth.svg new file mode 100644 index 0000000..5535a15 --- /dev/null +++ b/variants/Balaklava/pieces/white_mammoth.svg @@ -0,0 +1,172 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/variants/Balaklava/style.css b/variants/Balaklava/style.css index a3550bc..c876806 100644 --- a/variants/Balaklava/style.css +++ b/variants/Balaklava/style.css @@ -1 +1,8 @@ @import url("/base_pieces.css"); + +piece.white.mammoth { + background-image: url('/variants/Balaklava/pieces/white_mammoth.svg'); +} +piece.black.mammoth { + background-image: url('/variants/Balaklava/pieces/black_mammoth.svg'); +} diff --git a/variants/Baroque/class.js b/variants/Baroque/class.js index edf1dd5..240f130 100644 --- a/variants/Baroque/class.js +++ b/variants/Baroque/class.js @@ -1,9 +1,6 @@ -import ChessRules from "/base_rules.js"; import GiveawayRules from "/variants/Giveaway/class.js"; import AbstractSpecialCaptureRules from "/variants/_SpecialCaptures.js"; import {Random} from "/utils/alea.js"; -import PiPo from "/utils/PiPo.js"; -import Move from "/utils/Move.js"; export default class BaroqueRules extends AbstractSpecialCaptureRules { diff --git a/variants/Benedict/class.js b/variants/Benedict/class.js index e6542c4..5503f2f 100644 --- a/variants/Benedict/class.js +++ b/variants/Benedict/class.js @@ -1,5 +1,4 @@ import AbstractFlipRules from "/variants/_Flip/class.js"; -import PiPo from "/utils/PiPo.js"; export default class BenedictRules extends AbstractFlipRules { diff --git a/variants/Berolina/style.css b/variants/Berolina/style.css index a3550bc..9250552 100644 --- a/variants/Berolina/style.css +++ b/variants/Berolina/style.css @@ -1 +1,2 @@ @import url("/base_pieces.css"); +@import url("/variants/_Berolina/style.css"); diff --git a/variants/Bicolour/class.js b/variants/Bicolour/class.js index fd2cdb0..3812d4c 100644 --- a/variants/Bicolour/class.js +++ b/variants/Bicolour/class.js @@ -2,9 +2,7 @@ import ChessRules from "/base_rules.js"; import {Random} from "/utils/alea.js"; import {ArrayFun} from "/utils/array.js"; -export class BicolourRules extends ChessRules { - - // TODO: Options +export default class BicolourRules extends ChessRules { get hasFlags() { return false; @@ -103,9 +101,11 @@ export class BicolourRules extends ChessRules { }; } - underCheck(color) { - const kingPos = this.searchKingPos(color)[0], - return (this.underAttack(kingPos, 'w') || this.underAttack(kingPos, 'b')); + underCheck(square_s) { + return ( + this.underAttack(square_s[0], 'w') || + this.underAttack(square_s[0], 'b') + ); } }; diff --git a/variants/Giveaway/class.js b/variants/Giveaway/class.js index 39f586c..3f27e5f 100644 --- a/variants/Giveaway/class.js +++ b/variants/Giveaway/class.js @@ -80,10 +80,10 @@ export default class GiveawayRules extends ChessRules { super(o); } - underCheck(square, oppCol) { + underCheck(square_s, oppCol) { if (this.options["mode"] == "suicide") return false; - return super.underCheck(square, oppCol); + return super.underCheck(square_s, oppCol); } getCurrentScore() { diff --git a/variants/Hex/class.js b/variants/Hex/class.js index 774de17..f58800f 100644 --- a/variants/Hex/class.js +++ b/variants/Hex/class.js @@ -187,7 +187,7 @@ export default class HexRules extends AbstractClickFillRules { max = z; explored[index] = true; component[index] = true; - for (let [dx, dy] of super.pieces()['k'].moves[0].steps) { + for (let [dx, dy] of super.pieces()['k'].both[0].steps) { const [nx, ny] = [x + dx, y + dy]; const nidx = getIndex(nx, ny); if ( diff --git a/variants/_Antiking/class.js b/variants/_Antiking/class.js index 941bd82..ac9aedc 100644 --- a/variants/_Antiking/class.js +++ b/variants/_Antiking/class.js @@ -57,8 +57,6 @@ export default class AbstractAntikingRules extends ChessRules { underCheck(square_s, color) { let res = false; - if (!Array.isArray(square_s[0])) - square_s = [square_s]; square_s.forEach(sq => { switch (this.getPiece(sq[0], sq[1])) { case 'k': diff --git a/variants/_Berolina/pawnSpec.js b/variants/_Berolina/pawnSpec.js index 088e7df..7cfc7be 100644 --- a/variants/_Berolina/pawnSpec.js +++ b/variants/_Berolina/pawnSpec.js @@ -1,7 +1,8 @@ -export default BerolinaPawnSpec = (color) => { +export default function (color) { const pawnShift = (color == "w" ? -1 : 1); return { + "class": "pawn", moves: [ { steps: [[pawnShift, 1], [pawnShift, -1]], @@ -16,4 +17,4 @@ export default BerolinaPawnSpec = (color) => { ] }; -}; +} diff --git a/variants/_Berolina/style.css b/variants/_Berolina/style.css new file mode 100644 index 0000000..4daa2c8 --- /dev/null +++ b/variants/_Berolina/style.css @@ -0,0 +1,6 @@ +piece.black.pawn { + background-image: url('/variants/_Berolina/pieces/black_pawn.svg'); +} +piece.white.pawn { + background-image: url('/variants/_Berolina/pieces/white_pawn.svg'); +}