X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FBenedict%2Fclass.js;h=dfabddb72cc9a41efa3ef78026d78f43e8340a35;hb=HEAD;hp=c0fffcc00f203c88d59626c4ab9dae8112b225a3;hpb=41534b92f0bcfc8ef5f58d8040706a5e7ce088c6;p=xogo.git diff --git a/variants/Benedict/class.js b/variants/Benedict/class.js index c0fffcc..25e1ef8 100644 --- a/variants/Benedict/class.js +++ b/variants/Benedict/class.js @@ -1,98 +1,75 @@ -import ChessRules from "/base_rules.js"; -import PiPo from "/utils/PiPo.js"; +import AbstractFlipRules from "/variants/_Flip/class.js"; -export default class BenedictRules extends ChessRules { +export default class BenedictRules extends AbstractFlipRules { static get Options() { return { - select: ChessRules.Options.select, - check: [], - styles: ( - ChessRules.Options.styles.filter(s => { - return ( - ["balance", "cylinder", "dark", "doublemove", "progressive", "zen"] - .includes(s) - ); - }) - ) + select: C.Options.select, + input: [ + { + label: "Cleopatra", + variable: "cleopatra", + type: "checkbox", + defaut: false + } + ], + styles: [ + "balance", + "cylinder", + "dark", + "doublemove", + "progressive", + "zen" + ] }; } - get hasEnpassant() { - return false; - } - - get pawnSpecs() { - return Object.assign( - {}, - super.pawnSpecs, - { canCapture: false } + pieces(color, x, y) { + if (!this.options["cleopatra"]) + return super.pieces(color, x, y); + const allSpecs = super.pieces(color, x, y); + return Object.assign({}, + allSpecs, + {'q': Object.assign({}, allSpecs['q'], {"class": "cleopatra"})} ); } - canTake() { - return false; - } - - // Find potential captures from a square - // follow steps from x,y until something is met. - findAttacks([x, y]) { - const [color, piece] = [this.getColor(x, y), this.getPiece(x, y)]; - const oppCol = ChessRules.GetOppCol(color); - let squares = {}; - const specs = this.pieces(color)[piece]; - const steps = specs.attack || specs.steps; - outerLoop: for (let step of steps) { - let [i, j] = [x + step[0], this.computeY(y + step[1])]; - let nbSteps = 1; - while (this.onBoard(i, j) && this.board[i][j] == "") { - if (specs.range <= nbSteps++) continue outerLoop; - i += step[0]; - j = this.computeY(j + step[1]); - } - if (this.onBoard(i, j) && this.getColor(i, j) == oppCol) - squares[ChessRules.CoordsToSquare({x: i, y: j})] = true; - } - return Object.keys(squares); - } - postProcessPotentialMoves(moves) { - if (moves.length == 0) return moves; - const [x, y] = [moves[0].end.x, moves[0].end.y]; - const color = this.getColor(moves[0].start.x, moves[0].start.y); - const oppCol = ChessRules.GetOppCol(color); - moves = super.postProcessPotentialMoves(moves); - moves.forEach(m => { - this.playOnBoard(m); - let attacks; - if (this.options["zen"]) { - let endSquares = {}; - super.getZenCaptures(x, y).forEach(c => { - endSquares[ChessRules.CoordsToSquare(c.end)] = true; - }); - attacks = Object.keys(endSquares); + const oppCol = C.GetOppTurn(this.turn); + let bMoves = super.postProcessPotentialMoves(moves); + bMoves.forEach(m => { + m.flips = []; + if (!this.options["cleopatra"] || m.vanish[0].p == 'q') { + super.playOnBoard(m); + let attacks = super.findDestSquares( + [m.end.x, m.end.y], + { + attackOnly: true, + segments: this.options["cylinder"] + }, + ([i1, j1], [i2, j2]) => { + return ( + this.getColor(i2, j2) == oppCol && + (!this.options["zen"] || this.getPiece(i2, j2) == 'k') + ); + } + ); + if (this.options["zen"]) { + const zenAttacks = super.findCapturesOn( + [m.end.x, m.end.y], + { + byCol: [oppCol], + segments: this.options["cylinder"] + }, + ([i1, j1], [i2, j2]) => this.getPiece(i1, j1) != 'k' + ); + Array.prototype.push.apply(attacks, zenAttacks); + } + super.undoOnBoard(m); + attacks.forEach(a => m.flips.push({x: a.sq[0], y: a.sq[1]})); } - else attacks = this.findAttacks([m.end.x, m.end.y]) - this.undoOnBoard(m); - attacks.map(ChessRules.SquareToCoords).forEach(a => { - const p = this.getPiece(a.x, a.y); - m.appear.push(new PiPo({x: a.x, y: a.y, c: color, p: p})); - m.vanish.push(new PiPo({x: a.x, y: a.y, c: oppCol, p: p})); - }); }); - return moves; - } - - // Moves cannot flip our king's color, so (almost) all are valid - filterValid(moves) { - if (this.options["balance"] && [1, 3].includes(this.movesCount)) - return moves.filter(m => m.vanish.every(v => v.p != ChessRules.KING)); - return moves; - } - - // Since it's used just for the king, and there are no captures: - underCheck(square, color) { - return false; + return bMoves; } };