From: Benjamin Auder Date: Thu, 11 Jun 2026 21:58:20 +0000 (+0200) Subject: Adjust all variants using pieces() ==> now pieceDef() X-Git-Url: https://git.auder.net/doc/html/scripts/css/assets/DESCRIPTION?a=commitdiff_plain;h=HEAD;p=xogo.git Adjust all variants using pieces() ==> now pieceDef() --- diff --git a/variants/Absorption/class.js b/variants/Absorption/class.js index b58d664..b29d864 100644 --- a/variants/Absorption/class.js +++ b/variants/Absorption/class.js @@ -21,62 +21,63 @@ export default class AbsorptionRules extends ChessRules { }; } - pieces(color, x, y) { - let fusions = { - 'a': { - "class": "amazon", - both: [ - { - steps: [ - [0, 1], [0, -1], [1, 0], [-1, 0], - [1, 1], [1, -1], [-1, 1], [-1, -1] - ] - }, - { - steps: [ - [1, 2], [1, -2], [-1, 2], [-1, -2], - [2, 1], [-2, 1], [2, -1], [-2, -1] - ], - range: 1 - } - ] - }, - 'e': { - "class": "empress", - both: [ - { - steps: [ - [1, 0], [-1, 0], [0, 1], [0, -1] - ] - }, - { - steps: [ - [1, 2], [1, -2], [-1, 2], [-1, -2], - [2, 1], [-2, 1], [2, -1], [-2, -1] - ], - range: 1 - } - ] - }, - 's': { - "class": "princess", - both: [ - { - steps: [ - [1, 1], [1, -1], [-1, 1], [-1, -1] - ] - }, - { - steps: [ - [1, 2], [1, -2], [-1, 2], [-1, -2], - [2, 1], [-2, 1], [2, -1], [-2, -1] - ], - range: 1 - } - ] - } + pieceDef(piece, color, x, y) { + switch (piece) { + // Fusions + case 'a': return { + "class": "amazon", + both: [ + { + steps: [ + [0, 1], [0, -1], [1, 0], [-1, 0], + [1, 1], [1, -1], [-1, 1], [-1, -1] + ] + }, + { + steps: [ + [1, 2], [1, -2], [-1, 2], [-1, -2], + [2, 1], [-2, 1], [2, -1], [-2, -1] + ], + range: 1 + } + ] + }; + case 'e': return { + "class": "empress", + both: [ + { + steps: [ + [1, 0], [-1, 0], [0, 1], [0, -1] + ] + }, + { + steps: [ + [1, 2], [1, -2], [-1, 2], [-1, -2], + [2, 1], [-2, 1], [2, -1], [-2, -1] + ], + range: 1 + } + ] }; - return Object.assign(fusions, super.pieces(color, x, y)); + case 's': return { + "class": "princess", + both: [ + { + steps: [ + [1, 1], [1, -1], [-1, 1], [-1, -1] + ] + }, + { + steps: [ + [1, 2], [1, -2], [-1, 2], [-1, -2], + [2, 1], [-2, 1], [2, -1], [-2, -1] + ], + range: 1 + } + ] + }; + } + return super.pieceDef(piece, color, x, y); } static get MergeComposed() { diff --git a/variants/Alapo/class.js b/variants/Alapo/class.js index fa047eb..57618e3 100644 --- a/variants/Alapo/class.js +++ b/variants/Alapo/class.js @@ -56,46 +56,43 @@ export default class AlapoRules extends ChessRules { } // Triangles are rotated from opponent viewpoint (=> suffix "_inv") - pieces(color, x, y) { - const allSpecs = super.pieces(color, x, y); - return { - 'r': allSpecs['r'], - 'q': allSpecs['q'], - 'b': { - "class": "bishop" + (this.playerColor != color ? "_inv" : ""), - ...allSpecs['b'] - }, - 's': { //"square" - "class": "babyrook", - both: [ - { - steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], - range: 1 - } - ] - }, - 'c': { //"circle" - "class": "babyqueen", - both: [ - { - steps: [ - [0, 1], [0, -1], [1, 0], [-1, 0], - [1, 1], [1, -1], [-1, 1], [-1, -1] - ], - range: 1 - } - ] - }, - 't': { //"triangle" - "class": "babybishop" + (this.playerColor != color ? "_inv" : ""), - both: [ - { - steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]], - range: 1 - } - ] - } + pieceDef(piece, color, x, y) { + switch (piece) { + case 's': return { //"square" + "class": "babyrook", + both: [ + { + steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], + range: 1 + } + ] + }; + case 'c': return { //"circle" + "class": "babyqueen", + both: [ + { + steps: [ + [0, 1], [0, -1], [1, 0], [-1, 0], + [1, 1], [1, -1], [-1, 1], [-1, -1] + ], + range: 1 + } + ] }; + case 't': return { //"triangle" + "class": "babybishop" + (this.playerColor != color ? "_inv" : ""), + both: [ + { + steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]], + range: 1 + } + ] + }; + } + let pd = super.pieceDef(piece, color, x, y); + if (piece == 'b') + pd["class"] = "bishop" + (this.playerColor != color ? "_inv" : ""); + return pd; } get size() { diff --git a/variants/Alice/class.js b/variants/Alice/class.js index 188579d..a9a9ad1 100644 --- a/variants/Alice/class.js +++ b/variants/Alice/class.js @@ -47,16 +47,16 @@ export default class AliceRules extends ChessRules { return ['k', 'l'].includes(p); } - pieces(color, x, y) { - let alices = { - 's': {"class": "alice-pawn", moveas: 'p'}, - 'u': {"class": "alice-rook", moveas: 'r'}, - 'o': {"class": "alice-knight", moveas: 'n'}, - 'c': {"class": "alice-bishop", moveas: 'b'}, - 't': {"class": "alice-queen", moveas: 'q'}, - 'l': {"class": "alice-king", moveas: 'k'} - }; - return Object.assign(alices, super.pieces(color, x, y)); + pieceDef(piece, color, x, y) { + switch (piece) { + case 's': return {"class": "alice-pawn", moveas: 'p'}; + case 'u': return {"class": "alice-rook", moveas: 'r'}; + case 'o': return {"class": "alice-knight", moveas: 'n'}; + case 'c': return {"class": "alice-bishop", moveas: 'b'}; + case 't': return {"class": "alice-queen", moveas: 'q'}; + case 'l': return {"class": "alice-king", moveas: 'k'}; + } + return super.pieceDef(piece, color, x, y); } fromSameWorld(p1, p2) { diff --git a/variants/Ambiguous/class.js b/variants/Ambiguous/class.js index 5420856..95279bd 100644 --- a/variants/Ambiguous/class.js +++ b/variants/Ambiguous/class.js @@ -131,17 +131,17 @@ export default class AmbiguousRules extends ChessRules { }; } - pieces(color, x, y) { - const targets = { - '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)); + pieceDef(piece, color, x, y) { + switch (piece) { + case 's': return {"class": "target-pawn"}; + case 'u': return {"class": "target-rook"}; + case 'o': return {"class": "target-knight"}; + case 'c': return {"class": "target-bishop"}; + case 't': return {"class": "target-queen"}; + case 'l': return {"class": "target-king"}; + case 'g': return {"class": "target"} }; + } + return super.pieceDef(piece, color, x, y); } atLeastOneMove() { diff --git a/variants/Antiking1/class.js b/variants/Antiking1/class.js index eeba995..7d7e52f 100644 --- a/variants/Antiking1/class.js +++ b/variants/Antiking1/class.js @@ -11,10 +11,10 @@ export default class Antiking1Rules extends AbstractAntikingRules { return false; } - pieces(color, x, y) { - let res = super.pieces(color, x, y); - res['p'] = BerolinaPawnSpec(color); //no 2-squares moves - return res; + pieceDef(piece, color, x, y) { + if (piece == 'p') + return BerolinaPawnSpec(color); //no 2-squares moves + return super.pieceDef(piece, color, x, y); } genRandInitBaseFen() { diff --git a/variants/Apocalypse/class.js b/variants/Apocalypse/class.js index c380eaa..e9c14c3 100644 --- a/variants/Apocalypse/class.js +++ b/variants/Apocalypse/class.js @@ -66,10 +66,10 @@ export default class ApocalypseRules extends ChessRules { // Allow pawns to move diagonally and capture vertically, // because some of these moves might be valid a posteriori. // They will be flagged as 'illegal' in a first time, however. - pieces(color, x, y) { - const pawnShift = (color == "w" ? -1 : 1); - return { - 'p': { + pieceDef(piece, color, x, y) { + if (piece == 'p') { + const pawnShift = (color == "w" ? -1 : 1); + return { "class": "pawn", both: [ { @@ -77,9 +77,9 @@ export default class ApocalypseRules extends ChessRules { range: 1 } ], - }, - 'n': super.pieces(color, x, y)['n'] - }; + }; + } + return super.pieceDef('n', color, x, y); } // Allow self-captures, because they might be valid diff --git a/variants/Arena/class.js b/variants/Arena/class.js index 9b53fa1..035aee7 100644 --- a/variants/Arena/class.js +++ b/variants/Arena/class.js @@ -20,24 +20,26 @@ export default class ArenaRules extends ChessRules { return board; } - pieces(color, x, y) { - let allSpecs = super.pieces(color, x, y); - let pawnSpec = allSpecs['p'], - queenSpec = allSpecs['q'], - kingSpec = allSpecs['k']; - const pawnShift = (color == "w" ? -1 : 1); - Array.prototype.push.apply(pawnSpec.attack[0].steps, - [[-pawnShift, 1], [-pawnShift, -1]]); - queenSpec.both[0].range = 3; - kingSpec.both[0].range = 3; - return Object.assign({}, - allSpecs, - { - 'p': pawnSpec, - 'q': queenSpec, - 'k': kingSpec - } - ); + pieceDef(piece, color, x, y) { + switch (piece) { + case 'p': { + const pawnShift = (color == "w" ? -1 : 1); + let pawnSpec = super.pieceDef('p', color, x, y); + pawnSpec.attack[0].steps.push(...[[-pawnShift, 1], [-pawnShift, -1]]); + return pawnSpec; + } + case 'q': { + let queenSpec = super.pieceDef('q', color, x, y); + queenSpec.both[0].range = 3; + return queenSpec; + } + case 'k': { + let kingSpec = super.pieceDef('k', color, x, y); + kingSpec.both[0].range = 3; + return kingSpec; + } + } + return super.pieceDef(piece, color, x, y); } static InArena(x) { diff --git a/variants/Balaklava/class.js b/variants/Balaklava/class.js index c9910d4..3e5753b 100644 --- a/variants/Balaklava/class.js +++ b/variants/Balaklava/class.js @@ -11,28 +11,27 @@ export default class BalaklavaRules extends ChessRules { return false; } - pieces(color, x, y) { - let res = super.pieces(color, x, y); - const knightSpecMoves = res['n'].both; - delete res['n']; - res['m'] = { - "class": "mammoth", - both: [ - { - steps: [ - [-2, -2], [-2, 0], [-2, 2], - [0, -2], [0, 2], [2, -2], - [2, 0], [2, 2] - ], - range: 1 - } - ] - }; - ['p', 'r', 'b', 'm', 'q'].forEach(p => { - if (!res[p].moves) - res[p].moves = []; - Array.prototype.push.apply(res[p].moves, knightSpecMoves); - }); + pieceDef(piece, color, x, y) { + if (piece == 'm') { + return { + "class": "mammoth", + both: [ + { + steps: [ + [-2, -2], [-2, 0], [-2, 2], + [0, -2], [0, 2], [2, -2], + [2, 0], [2, 2] + ], + range: 1 + } + ] + }; + } + let res = super.pieceDef(piece, color, x, y); + const knightSpecMoves = super.pieceDef('n').both; + if (!res.moves) + res.moves = []; + res.moves.push(...knightSpecMoves); return res; } diff --git a/variants/Bario/class.js b/variants/Bario/class.js index 4734cfc..878760a 100644 --- a/variants/Bario/class.js +++ b/variants/Bario/class.js @@ -24,11 +24,10 @@ export default class BarioRules extends ChessRules { return true; } - pieces(color, x, y) { - return Object.assign( - { 'u': {"class": "undefined"} }, - super.pieces(color, x, y) - ); + pieceDef(piece, color, x, y) { + if (piece == 'u') + return {"class": "undefined"}; + return super.pieceDef(piece, color, x, y); } get clickOnly() { @@ -167,7 +166,7 @@ export default class BarioRules extends ChessRules { const inReserve = Object.keys(this.reserve[oppCol]) .filter(k => this.reserve[oppCol][k] >= 1); const allAttacks = Array.prototype.concat.apply( - inReserve.map(p => this.pieces()[p].both[0])); + inReserve.map(p => this.pieceDef(p).both[0])); const [x, y] = square_s[0]; for (let i=0; i { + this.pieceDef('n').both[0].steps.forEach(s => { const [i, j] = [x + s[0], y + s[1]]; if ( this.onBoard(i, j) && @@ -135,7 +135,7 @@ export default class ConvertRules extends ChessRules { } }); // Sliders: - this.pieces()['q'].both[0].steps.forEach(s => { + this.pieceDef('q').both[0].steps.forEach(s => { let [i, j] = [x + s[0], y + s[1]]; while (this.onBoard(i, j) && this.board[i][j] == "") { i += s[0]; diff --git a/variants/Copycat/class.js b/variants/Copycat/class.js index 98690e5..edbbfd1 100644 --- a/variants/Copycat/class.js +++ b/variants/Copycat/class.js @@ -19,7 +19,7 @@ export default class CopycatRules extends ChessRules { return res; // Now check if the piece at x, y attack some friendly one (enhancement) let movements = {}; - const steps = this.pieces()[piece].both[0].steps; + const steps = this.pieceDef(piece).both[0].steps; steps.forEach(s => { let [i, j] = [x + s[0], y + s[1]]; while ( @@ -46,7 +46,7 @@ export default class CopycatRules extends ChessRules { }); Object.keys(movements).forEach(type => { if ((piece != 'q' && type != piece) || (piece == 'q' && type == 'n')) - res.both.push(this.pieces()[type].both[0]); + res.both.push(this.pieceDef(type).both[0]); }); return res; } diff --git a/variants/Coregal/class.js b/variants/Coregal/class.js index 578b090..8d36da1 100644 --- a/variants/Coregal/class.js +++ b/variants/Coregal/class.js @@ -75,13 +75,16 @@ export default class CoregalRules extends ChessRules { }; } - pieces(color, x, y) { - let res = super.pieces(color, x, y); - res['l'] = JSON.parse(JSON.stringify(res['q'])); - // TODO: CSS royal queen symbol (with cross?) - res['l']["class"] = "royal_queen"; - res['='] = {"class": "castle"}; //for castle display - return res; + pieceDef(piece, color, x, y) { + if (piece == 'l') { + let pd = super.pieceDef('q', color, x, y); + // TODO: CSS royal queen symbol (with cross?) + pd["class"] = "royal_queen"; + return pd; + } + else if (piece == '=') + return {"class": "castle"}; //for castle display + return super.pieceDef(piece, color, x, y); } setFlags(fenflags) { diff --git a/variants/Cwda/class.js b/variants/Cwda/class.js index 0f1c02a..b568bc7 100644 --- a/variants/Cwda/class.js +++ b/variants/Cwda/class.js @@ -164,115 +164,112 @@ export default class CwdaRules extends ChessRules { }; } - pieces(color, x, y) { - const res = super.pieces(color, x, y); + pieceDef(piece, color, x, y) { const backward = (color == 'w' ? 1 : -1); const forward = -backward; - return Object.assign( - { - 'd': { - "class": "c_rook", - both: [ - {steps: res['b'].both[0].steps}, - {steps: V.steps.d, range: 1} - ] - }, - 'w': { - "class": "c_knight", - both: [ - {steps: V.steps.a, range: 1}, - {steps: res['r'].both[0].steps, range: 1} - ] - }, - 'f': { - "class": "c_bishop", - both: [ - {steps: V.steps.d, range: 1}, - {steps: V.steps.a, range: 1}, - {steps: res['b'].both[0].steps, range: 1} - ] - }, - 'c': { - "class": "c_queen", - both: [ - {steps: res['b'].both[0].steps}, - {steps: res['n'].both[0].steps, range: 1} - ] - }, - 'm': { "class": "c_king", moveas: 'k' }, - 'z': { "class": "c_pawn", moveas: 'p' }, - 'g': { - "class": "n_rook", - both: [ - {steps: [[0, -1], [0, 1], [color == 'w' ? -1 : 1, 0]]}, - {steps: [[backward, -1], [backward, 0], [backward, 1]], range: 1} - ] - }, - 'i': { - "class": "n_knight", - both: [ - {steps: V.steps.$n, range: 1}, - {steps: V.steps.f, range: 1} - ] - }, - 't': { - "class": "n_bishop", - both: [ - { - steps: [[0, -1], [0, 1], [backward, -1], - [backward, 0], [backward, 1]], - range: 1 - }, - { - steps: [[2*forward, -1], [2*forward, 1], - [forward, -2], [forward, 2]], - range: 1 - } - ] - }, - 'l': { - "class": "n_queen", - both: [ - {steps: [[0, -1], [0, 1], [forward, 0]]}, - {steps: [[forward, -1], [forward, 1], - [backward, -1], [backward, 0], [backward, 1]], range: 1}, - {steps: [[2*forward, -1], [2*forward, 1], - [forward, -2], [forward, 2]], range: 1} - ] - }, - 'e': { "class": "n_king", moveas: 'k' }, - 'v': { "class": "n_pawn", moveas: 'p' }, - 's': { - "class": "r_rook", - both: [{steps: res['r'].both[0].steps, range: 4}] - }, - 'y': { - "class": "r_knight", - both: [ - {steps: V.steps.d, range: 1}, - {steps: V.steps.w, range: 1} - ] - }, - 'h': { - "class": "r_bishop", - both: [ - {steps: V.steps.d, range: 1}, - {steps: V.steps.f, range: 1}, - {steps: V.steps.$3, range: 1} - ] - }, - 'o': { - "class": "r_queen", - both: [ - {steps: res['r'].both[0].steps}, - {steps: res['n'].both[0].steps, range: 1} - ] + switch (piece) { + case 'd': return { + "class": "c_rook", + both: [ + {steps: res['b'].both[0].steps}, + {steps: V.steps.d, range: 1} + ] + }; + case 'w': return { + "class": "c_knight", + both: [ + {steps: V.steps.a, range: 1}, + {steps: res['r'].both[0].steps, range: 1} + ] + }; + case 'f': return { + "class": "c_bishop", + both: [ + {steps: V.steps.d, range: 1}, + {steps: V.steps.a, range: 1}, + {steps: res['b'].both[0].steps, range: 1} + ] + }; + case 'c': return { + "class": "c_queen", + both: [ + {steps: res['b'].both[0].steps}, + {steps: res['n'].both[0].steps, range: 1} + ] + }; + case 'm': return { "class": "c_king", moveas: 'k' }; + case 'z': return { "class": "c_pawn", moveas: 'p' }; + case 'g': return { + "class": "n_rook", + both: [ + {steps: [[0, -1], [0, 1], [color == 'w' ? -1 : 1, 0]]}, + {steps: [[backward, -1], [backward, 0], [backward, 1]], range: 1} + ] + }; + case 'i': return { + "class": "n_knight", + both: [ + {steps: V.steps.$n, range: 1}, + {steps: V.steps.f, range: 1} + ] + }; + case 't': return { + "class": "n_bishop", + both: [ + { + steps: [[0, -1], [0, 1], [backward, -1], + [backward, 0], [backward, 1]], + range: 1 }, - 'a': { "class": "r_king", moveas: 'k' }, - 'u': { "class": "r_pawn", moveas: 'p' } - }, - res - ); + { + steps: [[2*forward, -1], [2*forward, 1], + [forward, -2], [forward, 2]], + range: 1 + } + ] + }; + case 'l': return { + "class": "n_queen", + both: [ + {steps: [[0, -1], [0, 1], [forward, 0]]}, + {steps: [[forward, -1], [forward, 1], + [backward, -1], [backward, 0], [backward, 1]], range: 1}, + {steps: [[2*forward, -1], [2*forward, 1], + [forward, -2], [forward, 2]], range: 1} + ] + }; + case 'e': return { "class": "n_king", moveas: 'k' }; + case 'v': return { "class": "n_pawn", moveas: 'p' }; + case 's': return { + "class": "r_rook", + both: [{steps: res['r'].both[0].steps, range: 4}] + }; + case 'y': return { + "class": "r_knight", + both: [ + {steps: V.steps.d, range: 1}, + {steps: V.steps.w, range: 1} + ] + }; + case 'h': return { + "class": "r_bishop", + both: [ + {steps: V.steps.d, range: 1}, + {steps: V.steps.f, range: 1}, + {steps: V.steps.$3, range: 1} + ] + }; + case 'o': return { + "class": "r_queen", + both: [ + {steps: res['r'].both[0].steps}, + {steps: res['n'].both[0].steps, range: 1} + ] + }; + case 'a': return { "class": "r_king", moveas: 'k' }; + case 'u': return { "class": "r_pawn", moveas: 'p' }; + } + return super.pieceDef(piece, color, x, y); } pawnPromotions() { diff --git a/variants/Diamond/class.js b/variants/Diamond/class.js index 14cb712..8e57086 100644 --- a/variants/Diamond/class.js +++ b/variants/Diamond/class.js @@ -85,12 +85,16 @@ export default class DiamondRules extends ChessRules { return { fen: fen, o: {} }; } - pieces(color, x, y) { - let res = super.pieces(color, x, y); - const pawnShift = this.getPawnShift(color || 'w'); - res['p'].moves = [{steps: [[pawnShift, pawnShift]], range: 1}]; - res['p'].attack = [{steps: [[0, pawnShift], [pawnShift, 0]], range: 1}]; - return res; + pieceDef(piece, color, x, y) { + if (piece == 'p') { + const pawnShift = this.getPawnShift(color || 'w'); + return { + "class": "pawn", + moves: [{steps: [[pawnShift, pawnShift]], range: 1}], + attack: [{steps: [[0, pawnShift], [pawnShift, 0]], range: 1}] + }; + } + return super.pieceDef(piece, color, x, y); } }; diff --git a/variants/Dobutsu/class.js b/variants/Dobutsu/class.js index 8f68e13..bfb08fd 100644 --- a/variants/Dobutsu/class.js +++ b/variants/Dobutsu/class.js @@ -14,44 +14,47 @@ export default class DobutsuRules extends ChessRules { return false; } - pieces(color, x, y) { - const pawnShift = this.getPawnShift(color || 'w'); + pieceDef(piece, color, x, y) { // NOTE: classs change according to playerColor (orientation) const mySide = (this.playerColor == color); - return { - 'p': { + switch (piece) { + case 'p': { + const pawnShift = this.getPawnShift(color || 'w'); + return { "class": (mySide ? "" : "rev-") + "chick", both: [{steps: [[pawnShift, 0]], range: 1}] - }, - 'h': { - "class": (mySide ? "" : "rev-") + "hen", - both: [ - { - steps: [ - [pawnShift, 1], [pawnShift, -1], - [0, 1], [0, -1], [1, 0], [-1, 0] - ], - range: 1 - } - ] - }, - 'e': { - "class": (mySide ? "" : "rev-") + "elephant", - both: [{steps: [[-1, 1], [-1, -1], [1, 1], [1, -1]], range: 1}] - }, - 'g': { - "class": (mySide ? "" : "rev-") + "giraffe", - both: [{steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], range: 1}] - }, - 'k': { - "class": (mySide ? "" : "rev-") + "lion", - both: [{ - steps: [[-1, 1], [-1, -1], [1, 1], [1, -1], - [0, 1], [0, -1], [1, 0], [-1, 0]], + }; + } + case 'h': return { + "class": (mySide ? "" : "rev-") + "hen", + both: [ + { + steps: [ + [pawnShift, 1], [pawnShift, -1], + [0, 1], [0, -1], [1, 0], [-1, 0] + ], range: 1 - }] - } + } + ] }; + case 'e': return { + "class": (mySide ? "" : "rev-") + "elephant", + both: [{steps: [[-1, 1], [-1, -1], [1, 1], [1, -1]], range: 1}] + }; + case 'g': return { + "class": (mySide ? "" : "rev-") + "giraffe", + both: [{steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], range: 1}] + }; + case 'k': return { + "class": (mySide ? "" : "rev-") + "lion", + both: [{ + steps: [[-1, 1], [-1, -1], [1, 1], [1, -1], + [0, 1], [0, -1], [1, 0], [-1, 0]], + range: 1 + }] + }; + } + return {}; //never reached } static get ReserveArray() { diff --git a/variants/Doublearmy/class.js b/variants/Doublearmy/class.js index f2e2227..ea6b0c1 100644 --- a/variants/Doublearmy/class.js +++ b/variants/Doublearmy/class.js @@ -10,17 +10,14 @@ export default class DoublearmyRules extends ChessRules { }; } - pieces(color, x, y) { - let res = super.pieces(color, x, y); - return Object.assign( - { - 'c': { - "class": "commoner", - moveas: 'k' - } - }, - res - ); + pieceDef(piece, color, x, y) { + if (piece == 'c') { + return { + "class": "commoner", + moveas: 'k' + }; + } + return super.pieceDef(piece, color, x, y); } genRandInitBaseFen() { diff --git a/variants/Dynamo/class.js b/variants/Dynamo/class.js index 3ec2c3f..4e59a1a 100644 --- a/variants/Dynamo/class.js +++ b/variants/Dynamo/class.js @@ -167,9 +167,9 @@ export default class DynamoRules extends ChessRules { // Slider let steps = []; if (['r', 'q'].includes(p)) - steps = steps.concat(this.pieces()['r'].both[0].steps); + steps = steps.concat(this.pieceDef('r').both[0].steps); if (['b', 'q'].includes(p)) - steps = steps.concat(this.pieces()['b'].both[0].steps); + steps = steps.concat(this.pieceDef('b').both[0].steps); for (let s of steps) { let [i, j] = [x + s[0], y + s[1]]; while (this.onBoard(i, j) && this.board[i][j] == "") { @@ -213,7 +213,7 @@ export default class DynamoRules extends ChessRules { let movesHash = {}; moves.forEach(m => { movesHash[getMoveHash(m)] = true; }); // [x, y] is pushed by 'color' - for (let step of this.pieces()['n'].both[0].steps) { + for (let step of this.pieceDef('n').both[0].steps) { const [i, j] = [x + step[0], y + step[1]]; if ( this.onBoard(i, j) && @@ -224,8 +224,8 @@ export default class DynamoRules extends ChessRules { addMoves(step, 1); } } - for (let step of this.pieces()['r'].both[0].steps.concat( - this.pieces()['b'].both[0].steps)) + for (let step of this.pieceDef('r').both[0].steps.concat( + this.pieceDef('b').both[0].steps)) { let [i, j] = [x + step[0], y + step[1]]; while (this.onBoard(i, j) && this.board[i][j] == "") { @@ -491,9 +491,9 @@ export default class DynamoRules extends ChessRules { const sq = square_s[0], oppCol = oppCols[0]; // Look for every directions from kp - const P = this.pieces(oppCol, 0, 0); for (const piece of ['r', 'n', 'b', 'q', 'k', 'p']) { - const stepArray = (P[piece].attack || P[piece].both); + const pd = this.pieceDef(piece, oppCol); + const stepArray = (pd.attack || pd.both); for (const stepObj of stepArray) { const range = stepObj.range || Math.max(this.size.x, this.size.y); for (const s of stepObj.steps) { @@ -538,7 +538,7 @@ export default class DynamoRules extends ChessRules { } } return false; - } //TODO: checks by pull!! + } // Does m2 un-do m1 ? (to disallow undoing actions) oppositeMoves(m1, m2) { diff --git a/variants/Eightpieces/class.js b/variants/Eightpieces/class.js index 46d66d2..6bc8ddf 100644 --- a/variants/Eightpieces/class.js +++ b/variants/Eightpieces/class.js @@ -92,72 +92,72 @@ export default class EightpiecesRules extends ChessRules { this.pushedTo = V.convertPush(fenParsed.pushedTo); } - pieces(color, x, y) { + pieceDef(piece, color, x, y) { const mirror = (this.playerColor == 'b'); - return { - 'j': { - "class": "jailer", - moves: [ - {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]} - ] - }, - 's': { - "class": "sentry", - indirectAttack: true, - both: [ - {steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]]} - ] - }, - 'c': { - "class": mirror ? "lancer_S" : "lancer_N", - both: [ - {steps: [[-1, 0]]} - ] - }, - 'd': { - "class": mirror ? "lancer_SO" : "lancer_NE", - both: [ - {steps: [[-1, 1]]} - ] - }, - 'e': { - "class": mirror ? "lancer_O" : "lancer_E", - both: [ - {steps: [[0, 1]]} - ] - }, - 'f': { - "class": mirror ? "lancer_NO" : "lancer_SE", - both: [ - {steps: [[1, 1]]} - ] - }, - 'g': { - "class": mirror ? "lancer_N" : "lancer_S", - both: [ - {steps: [[1, 0]]} - ] - }, - 'h': { - "class": mirror ? "lancer_NE" : "lancer_SO", - both: [ - {steps: [[1, -1]]} - ] - }, - 'm': { - "class": mirror ? "lancer_E" : "lancer_O", - both: [ - {steps: [[0, -1]]} - ] - }, - 'o': { - "class": mirror ? "lancer_SE" : "lancer_NO", - both: [ - {steps: [[-1, -1]]} - ] - }, - ...super.pieces(color, x, y) + switch (piece) { + case 'j': return { + "class": "jailer", + moves: [ + {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]} + ] }; + case 's': return { + "class": "sentry", + indirectAttack: true, + both: [ + {steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]]} + ] + }; + case 'c': return { + "class": mirror ? "lancer_S" : "lancer_N", + both: [ + {steps: [[-1, 0]]} + ] + }; + case 'd': return { + "class": mirror ? "lancer_SO" : "lancer_NE", + both: [ + {steps: [[-1, 1]]} + ] + }; + case 'e': return { + "class": mirror ? "lancer_O" : "lancer_E", + both: [ + {steps: [[0, 1]]} + ] + }; + case 'f': return { + "class": mirror ? "lancer_NO" : "lancer_SE", + both: [ + {steps: [[1, 1]]} + ] + }; + case 'g': return { + "class": mirror ? "lancer_N" : "lancer_S", + both: [ + {steps: [[1, 0]]} + ] + }; + case 'h': return { + "class": mirror ? "lancer_NE" : "lancer_SO", + both: [ + {steps: [[1, -1]]} + ] + }; + case 'm': return { + "class": mirror ? "lancer_E" : "lancer_O", + both: [ + {steps: [[0, -1]]} + ] + }; + case 'o': return { + "class": mirror ? "lancer_SE" : "lancer_NO", + both: [ + {steps: [[-1, -1]]} + ] + }; + } + return super.pieceDef(piece, color, x, y); } canIplay(x, y) { @@ -232,7 +232,7 @@ export default class EightpiecesRules extends ChessRules { ) || ( - this.pieces()['j'].moves[0].steps.some(s => { + this.pieceDef('j').moves[0].steps.some(s => { const [i, j] = [coords.x + s[0], coords.y + s[1]]; return ( this.onBoard(i, j) && @@ -274,9 +274,9 @@ export default class EightpiecesRules extends ChessRules { }); if (V.LANCERS.includes(p)) { // Allow all other directions without reorient - const ls = this.pieces()[p].both[0].steps[0]; + const ls = this.pieceDef(p).both[0].steps[0]; for (const lCode of V.LANCERS) { - const s = this.pieces()[lCode].both[0].steps[0]; + const s = this.pieceDef(lCode).both[0].steps[0]; if (s[0] != ls[0] || s[1] != ls[1]) { this.board[x][y] = color + lCode; super.findDestSquares([x, y], {}).forEach(r => { @@ -329,10 +329,10 @@ export default class EightpiecesRules extends ChessRules { if (V.LANCERS.includes(p)) { pmoves.forEach(m => m.noReorient = true); // Allow all other steps by 1 square (nudge) - const ls = this.pieces()[p].both[0].steps[0]; + const ls = this.pieceDef(p).both[0].steps[0]; let nextP = p; for (const lCode of V.LANCERS) { - const s = this.pieces()[lCode].both[0].steps[0]; + const s = this.pieceDef(lCode).both[0].steps[0]; if ( (s[0] != ls[0] || s[1] != ls[1]) && this.onBoard(x + s[0], y + s[1]) && @@ -447,7 +447,7 @@ export default class EightpiecesRules extends ChessRules { const p = this.getPiece(r.sq[0], r.sq[1]); if (['j', 's'].includes(p)) continue; - const specs = this.pieces(oppCol, r.sq[0], r.sq[1])[p]; + const specs = this.pieceDef(p, oppCol, r.sq[0], r.sq[1]); const steps = (specs.both || specs.attack)[0].steps; let res = false; for (const s of steps) { diff --git a/variants/Hex/class.js b/variants/Hex/class.js index 22dee0d..6abe083 100644 --- a/variants/Hex/class.js +++ b/variants/Hex/class.js @@ -190,7 +190,7 @@ export default class HexRules extends AbstractClickFillRules { max = z; explored[index] = true; component[index] = true; - for (let [dx, dy] of super.pieces()['k'].both[0].steps) { + for (let [dx, dy] of super.pieceDef('k').both[0].steps) { const [nx, ny] = [x + dx, y + dy]; const nidx = getIndex(nx, ny); if ( diff --git a/variants/Progressive/class.js b/variants/Progressive/class.js index 265b356..154e0c0 100644 --- a/variants/Progressive/class.js +++ b/variants/Progressive/class.js @@ -26,16 +26,17 @@ export default class ProgressiveRules extends ChessRules { return !this.options["logical"]; } - pieces(color, x, y) { - let res = super.pieces(color, x, y); - if (this.options["logical"]) { + pieceDef(piece, color, x, y) { + if (this.options["logical"] && piece == 'p') { const pawnShift = (color == "w" ? -1 : 1); - res["p"].moves[0] = { + let res = super.pieceDef('p', color, x, y); + res.moves[0] = { steps: [[pawnShift, 0]], range: 1 //always }; + return res; } - return res; + return super.pieceDef(piece, color, x, y); } }; diff --git a/variants/Sleepy/class.js b/variants/Sleepy/class.js index 07c9a9b..8c2c6d9 100644 --- a/variants/Sleepy/class.js +++ b/variants/Sleepy/class.js @@ -30,15 +30,15 @@ export default class SleepyRules extends ChessRules { }; } - pieces(color, x, y) { - return { - 's': {"class": "sleepy-pawn"}, - 'u': {"class": "sleepy-rook"}, - 'o': {"class": "sleepy-knight"}, - 'c': {"class": "sleepy-bishop"}, - 't': {"class": "sleepy-queen"}, - ...super.pieces(color, x, y) - }; + pieceDef(piece, color, x, y) { + switch (piece) { + case 's': return {"class": "sleepy-pawn"}; + case 'u': return {"class": "sleepy-rook"}; + case 'o': return {"class": "sleepy-knight"}; + case 'c': return {"class": "sleepy-bishop"}; + case 't': return {"class": "sleepy-queen"}; + } + return super.pieceDef(piece, color, x, y); } static get M_PIECES() { diff --git a/variants/Weiqi/class.js b/variants/Weiqi/class.js index f9ca469..1a3bc4d 100644 --- a/variants/Weiqi/class.js +++ b/variants/Weiqi/class.js @@ -124,16 +124,11 @@ export default class WeiqiRules extends ChessRules { passBtn_arr[0].removeEventListener("click", this.passListener); } - pieces(color, x, y) { + pieceDef(piece, color, x, y) { let classe_s = ["stone"]; - if (this.options["onecolor"] && color == 'w') + if (this.options["onecolor"] && color == 'w') //'w' is black! (First move) classe_s.push("one-color"); - return { - 's': { - "class": classe_s, - moves: [] - } - }; + return {"class": classe_s}; } doClick(coords) { diff --git a/variants/_Antiking/class.js b/variants/_Antiking/class.js index 17213a4..9bfb77b 100644 --- a/variants/_Antiking/class.js +++ b/variants/_Antiking/class.js @@ -25,10 +25,13 @@ export default class AbstractAntikingRules extends ChessRules { }; } - pieces(color, x, y) { - let antikingSpec = super.pieces(color, x, y)['k']; - antikingSpec["class"] = "antiking"; - return Object.assign({'a': antikingSpec}, super.pieces(color, x, y)); + pieceDef(piece, color, x, y) { + if (piece == 'a') { + let antikingSpec = super.pieceDef('k', color, x, y); + antikingSpec["class"] = "antiking"; + return antikingSpec; + } + return super.pieceDef(piece, color, x, y); } isKing(x, y, p) { diff --git a/variants/_SpecialCaptures/class.js b/variants/_SpecialCaptures/class.js index 54a245b..76d583c 100644 --- a/variants/_SpecialCaptures/class.js +++ b/variants/_SpecialCaptures/class.js @@ -9,19 +9,16 @@ export default class AbstractSpecialCaptureRules extends ChessRules { return false; } - pieces() { - return Object.assign({}, - super.pieces(), - { - '+': {"class": "push-action"}, - '-': {"class": "pull-action"} - } - ); + pieceDef(piece, color, x, y) { + if (['+', '-'].includes(piece)) + // When a move is ambiguous ("pushme-pullyou") + return {"class": (piece == '+' ? "push" : "pull" + "-action")}; + super.pieceDef(piece, color, x, y); } // Modify capturing moves among listed pincer moves addPincerCaptures(moves, byChameleon) { - const steps = this.pieces()['p'].moves[0].steps; + const steps = this.pieceDef('p').moves[0].steps; const color = moves[0].vanish[0].c; const oppCol = C.GetOppTurn(color); moves.forEach(m => { @@ -89,7 +86,7 @@ export default class AbstractSpecialCaptureRules extends ChessRules { getLeaperCaptures([x, y], byChameleon, onlyOne) { // Look in every direction for captures - const steps = this.pieces()['r'].moves[0].steps; + const steps = this.pieceDef('r').moves[0].steps; const color = this.getColor(x, y); const oppCol = C.GetOppTurn(color); let moves = []; @@ -155,7 +152,7 @@ export default class AbstractSpecialCaptureRules extends ChessRules { // type: nothing (freely, capture all), or pull or push, or "exclusive" addPushmePullyouCaptures(moves, byChameleon, type) { const [sx, sy] = [moves[0].start.x, moves[0].start.y]; - const adjacentSteps = this.pieces()['r'].moves[0].steps; + const adjacentSteps = this.pieceDef('r').moves[0].steps; let capturingPullDir = {}; const color = moves[0].vanish[0].c; const oppCol = C.GetOppTurn(color);