From: Benjamin Auder Date: Fri, 12 Jun 2026 13:44:11 +0000 (+0200) Subject: Small refactor X-Git-Url: https://git.auder.net/js/css/doc/html/figure/current/gitweb.js?a=commitdiff_plain;p=xogo.git Small refactor --- diff --git a/js/base_rules.js b/js/base_rules.js index a91c2a3..749b65c 100644 --- a/js/base_rules.js +++ b/js/base_rules.js @@ -3,21 +3,7 @@ import {ArrayFun} from "/utils/array.js"; import {FenUtil} from "/utils/setupPieces.js"; import PiPo from "/utils/PiPo.js"; import Move from "/utils/Move.js"; - -// Helper class for move animation -class TargetObj { - - constructor(callOnComplete) { - this.value = 0; - this.target = 0; - this.callOnComplete = callOnComplete; - } - increment() { - if (++this.value == this.target) - this.callOnComplete(); - } - -}; +import TargetObj from "/utils/TargetObj.js"; // NOTE: x coords: top to bottom (white perspective); y: left to right // NOTE: ChessRules is aliased as window.C, and variants as window.V diff --git a/utils/TargetObj.js b/utils/TargetObj.js new file mode 100644 index 0000000..7238970 --- /dev/null +++ b/utils/TargetObj.js @@ -0,0 +1,15 @@ +// Helper class for move animation +export default class TargetObj { + + constructor(callOnComplete) { + this.value = 0; + this.target = 0; + this.callOnComplete = callOnComplete; + } + increment() { + if (++this.value == this.target) + this.callOnComplete(); + } + +}; + diff --git a/utils/array.js b/utils/array.js index af8462e..dc74949 100644 --- a/utils/array.js +++ b/utils/array.js @@ -13,14 +13,4 @@ export const ArrayFun = { return [...Array(max - min).keys()].map(k => k + min); }, - toObject: function(keys, values) { - if (!Array.isArray(values)) - // Second argument is a scalar - values = Array(keys.length).fill(values); - return ( - ArrayFun.range(keys.length) - .reduce((acc, curr) => (acc[keys[curr]] = values[curr], acc), {}) - ); - } - }; diff --git a/variants/Absorption/class.js b/variants/Absorption/class.js index b29d864..097ee43 100644 --- a/variants/Absorption/class.js +++ b/variants/Absorption/class.js @@ -14,7 +14,6 @@ export default class AbsorptionRules extends ChessRules { "doublemove", "progressive", "recycle", - //"rifle", //TODO "teleport", "zen" ] @@ -120,7 +119,6 @@ export default class AbsorptionRules extends ChessRules { return V.MergeComposed[[p1, p2].sort().join("")]; } - // TODO: interaction with rifle ? postProcessPotentialMoves(moves) { // Filter out capturing promotions (except one), // because they are all the same. diff --git a/variants/Alice/class.js b/variants/Alice/class.js index a9a9ad1..3151cad 100644 --- a/variants/Alice/class.js +++ b/variants/Alice/class.js @@ -11,7 +11,6 @@ export default class AliceRules extends ChessRules { "balance", "capture", "cylinder", - "dark", "doublemove", "progressive", "zen" diff --git a/variants/Apocalypse/class.js b/variants/Apocalypse/class.js index e9c14c3..844e17e 100644 --- a/variants/Apocalypse/class.js +++ b/variants/Apocalypse/class.js @@ -35,10 +35,10 @@ export default class ApocalypseRules extends ChessRules { ? JSON.parse(fenParsed.whiteMove) : []; this.firstMove = null; //used if black turn pawn relocation - this.penalties = ArrayFun.toObject( - ['w', 'b'], - [0, 1].map(i => parseInt(fenParsed.penalties.charAt(i), 10)) - ); + this.penalties = { + 'w': parseInt(fenParsed.penalties.charAt(0), 10), + 'b': parseInt(fenParsed.penalties.charAt(1), 10) + }; } genRandInitBaseFen() { diff --git a/variants/Arena/class.js b/variants/Arena/class.js index 035aee7..93493ab 100644 --- a/variants/Arena/class.js +++ b/variants/Arena/class.js @@ -3,7 +3,11 @@ import ChessRules from "/js/base_rules.js"; export default class ArenaRules extends ChessRules { static get Options() { - return {}; //TODO + return { + select: C.Options.select, + input: [], + styles: ["atomic", "cannibal", "capture", "cylinder", "zen"] + }; } get hasFlags() { diff --git a/variants/Checkless/class.js b/variants/Checkless/class.js index bb6324c..09eb0b4 100644 --- a/variants/Checkless/class.js +++ b/variants/Checkless/class.js @@ -2,6 +2,15 @@ import ChessRules from "/js/base_rules.js"; export default class ChecklessRules extends ChessRules { + static get Options() { + return { + select: C.Options.select, + input: C.Options.input.filter(o => o.variable == "pawnfall"), + styles: ["cannibal", "capture", "crazyhouse", "cylinder", "madrasi", + "progressive", "recycle", "rifle", "teleport", "zen"] + }; + } + // Cannot use super.atLeastOneMove: lead to infinite recursion atLeastOneMove_aux(kingPos, oppKingPos, color, oppCol) { for (let i = 0; i < this.size.x; i++) { diff --git a/variants/Recycle/class.js b/variants/Recycle/class.js index a8c27db..e5d6cb2 100644 --- a/variants/Recycle/class.js +++ b/variants/Recycle/class.js @@ -5,20 +5,7 @@ export default class RecycleRules extends ChessRules { static get Options() { return { select: C.Options.select, - input: [ - { - label: "Capture king", - variable: "taking", - type: "checkbox", - defaut: false - }, - { - label: "Falling pawn", - variable: "pawnfall", - type: "checkbox", - defaut: true - } - ], + input: C.Options.input, styles: C.Options.styles.filter(s => s != "recycle") }; }