From 5b460b241c334dc0d5e1f5768c12c0b3e65bdc36 Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Thu, 30 Apr 2026 16:48:10 +0200 Subject: [PATCH] Some more code in 8-pieces --- base_rules.js | 8 +++--- variants/Eightpieces/class.js | 47 ++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/base_rules.js b/base_rules.js index b73776b..3866aa3 100644 --- a/base_rules.js +++ b/base_rules.js @@ -1375,7 +1375,8 @@ export default class ChessRules { return !this.isKing(x2, y2); } - canStepOver(i, j, p) { + // Can piece p (of color c) step over square i, j ? + canStepOver(i, j, p, c) { // In some variants, objects on boards don't stop movement (Chakart) return this.board[i][j] == ""; } @@ -1778,6 +1779,7 @@ export default class ChessRules { if (!allowed) allowed = (sq1, sq2) => this.canTake(sq1, sq2); const apparentPiece = this.getPiece(x, y); //how it looks + const c = this.getColor(x, y); let res = []; // Next 3 for Cylinder mode or circular (useless otherwise) let explored = {}; @@ -1798,7 +1800,7 @@ export default class ChessRules { let stepCounter = 0; while ( this.onBoard(i, j) && - ((i == x && j == y) || this.canStepOver(i, j, apparentPiece)) + ((i == x && j == y) || this.canStepOver(i, j, apparentPiece, c)) ) { if (!explored[i + "." + j] && (i != x || j != y)) { explored[i + "." + j] = true; @@ -1878,7 +1880,7 @@ export default class ChessRules { ) { const apparentPiece = this.getPiece(i, j); // Quick check: does this potential attacker target x,y ? - if (this.canStepOver(x, y, apparentPiece)) + if (this.canStepOver(x, y, apparentPiece, colIJ)) continue; const stepSpec = this.getStepSpec(colIJ, i, j); if (stepSpec.indirectAttack) //e.g. 8-pieces (only?) diff --git a/variants/Eightpieces/class.js b/variants/Eightpieces/class.js index 70f3296..f836570 100644 --- a/variants/Eightpieces/class.js +++ b/variants/Eightpieces/class.js @@ -9,8 +9,7 @@ export default class EightpiecesRules extends ChessRules { return { select: C.Options.select, input: C.Options.input, - styles: ["crazyhouse", "cylinder", "doublemove", "progressive", - "recycle", "rifle", "teleport", "zen"] + styles: ["crazyhouse", "cylinder", "recycle", "teleport"] }; } @@ -143,6 +142,11 @@ export default class EightpiecesRules extends ChessRules { }, super.pieces(color, x, y)); } + canStepOver(i, j, p, c) { + const colIJ = this.getColor(i, j); + return this.board[i][j] == "" || (V.LANCERS.includes(p) && c == colIJ); + } + isImmobilized([x, y]) { const color = this.getColor(x, y); const oppCol = C.GetOppTurn(color); @@ -160,9 +164,40 @@ export default class EightpiecesRules extends ChessRules { return false; } + getPassMoves(x, y) { + const col = this.getColor(x, y); + let res = []; + if (this.getPiece(x, y) == 'k') { + for (let i of [-1, 1]) { + for (let j of [-1, 1]) { + if ( + this.onBoard(x + i, y + j) && + this.getPiece(x + i, y + j) == 'j' && + this.getColor(x + i, y + j) != col + ) { + res.push( new Move({ + appear: [], + vanish: [], + start: {x: x, y: y}, + end: {x: x + i, y: y + j} + }) ); + } + } + } + } + return res; + } + + +// TODO: finish lancers + // http://ftp.chessvariants.com/rules/8-piece-chess + + getPotentialMovesFrom([x, y], color) { - if (!this.pushFrom) - return super.getPotentialMovesFrom([x, y], color); + if (!this.pushFrom) { + return this.getPassMoves(x, y).concat( + super.getPotentialMovesFrom([x, y], color) ); + } if (x != this.pushFrom.x || y != this.pushFrom.y) return []; // After sentry "attack": move enemy as if it was ours @@ -180,8 +215,8 @@ export default class EightpiecesRules extends ChessRules { let finalMoves = []; for (const m of moves) { //if (m.vanish.length == 0 && ... TODO: drop - if (V.LANCERS.includes(m.vanish[0].p)) { - // TODO: how to know it's regular? + if (m.vanish.length > 0 && V.LANCERS.includes(m.vanish[0].p)) { + // TODO: how to know it's regular? (not sentry push) this.getLancerOptions(m.end.x, m.end.y).forEach(o => { finalMoves.push( new Move({ appear: [new PiPo({x:m.end.x,y:m.end.y,c:m.appear[0].c,p:o})], -- 2.53.0