X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FCannibal1.js;fp=client%2Fsrc%2Fvariants%2FCannibal.js;h=0c327b457213b082dce7fcb0ac20bdb8328f6ed3;hp=a0da0fd6c341cfe41af4cd1721a3609fa7245b44;hb=3955246aca52e36cd02a528c98712e473c93417c;hpb=5199c0d85710470f06e23572b360a87517dabf3c diff --git a/client/src/variants/Cannibal.js b/client/src/variants/Cannibal1.js similarity index 73% rename from client/src/variants/Cannibal.js rename to client/src/variants/Cannibal1.js index a0da0fd6..0c327b45 100644 --- a/client/src/variants/Cannibal.js +++ b/client/src/variants/Cannibal1.js @@ -1,6 +1,6 @@ import { ChessRules, Move, PiPo } from "@/base_rules"; -export class CannibalRules extends ChessRules { +export class Cannibal1Rules extends ChessRules { static get KING_CODE() { return { @@ -84,31 +84,6 @@ export class CannibalRules extends ChessRules { } } - // Trim all non-capturing moves - static KeepCaptures(moves) { - return moves.filter(m => m.vanish.length == 2 && m.appear.length == 1); - } - - // Stop at the first capture found (if any) - atLeastOneCapture() { - const color = this.turn; - const oppCol = V.GetOppCol(color); - for (let i = 0; i < V.size.x; i++) { - for (let j = 0; j < V.size.y; j++) { - if ( - this.board[i][j] != V.EMPTY && - this.getColor(i, j) != oppCol && - this.filterValid(this.getPotentialMovesFrom([i, j])).some(m => - // Warning: discard castle moves - m.vanish.length == 2 && m.appear.length == 1) - ) { - return true; - } - } - } - return false; - } - // Because of the disguised kings, getPiece() could be wrong: // use board[x][y][1] instead (always valid). getBasicMove([sx, sy], [ex, ey], tr) { @@ -140,38 +115,6 @@ export class CannibalRules extends ChessRules { return super.getPotentialMovesFrom([x, y], piece); } - addPawnMoves([x1, y1], [x2, y2], moves) { - let finalPieces = [V.PAWN]; - const color = this.turn; - const lastRank = (color == "w" ? 0 : V.size.x - 1); - if (x2 == lastRank) { - if (this.board[x2][y2] != V.EMPTY) - // Cannibal rules: no choice if capture - finalPieces = [this.getPiece(x2, y2)]; - else finalPieces = V.PawnSpecs.promotions; - } - let tr = null; - for (let piece of finalPieces) { - tr = (piece != V.PAWN ? { c: color, p: piece } : null); - moves.push(this.getBasicMove([x1, y1], [x2, y2], tr)); - } - } - - getPossibleMovesFrom(sq) { - let moves = this.filterValid(this.getPotentialMovesFrom(sq)); - const captureMoves = V.KeepCaptures(moves); - if (captureMoves.length > 0) return captureMoves; - if (this.atLeastOneCapture()) return []; - return moves; - } - - getAllValidMoves() { - const moves = super.getAllValidMoves(); - if (moves.some(m => m.vanish.length == 2 && m.appear.length == 1)) - return V.KeepCaptures(moves); - return moves; - } - postPlay(move) { const c = V.GetOppCol(this.turn); const piece = move.appear[0].p;