X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FBenedict%2Fclass.js;h=dfabddb72cc9a41efa3ef78026d78f43e8340a35;hb=6b9320bb6e42ece7694df32f85aab4d2989f6a13;hp=bbaf8e9522c2b553b14e06a54264d719a37c1041;hpb=535c464b0543306a0ea36c66f07dcfad7a951efc;p=xogo.git diff --git a/variants/Benedict/class.js b/variants/Benedict/class.js index bbaf8e9..dfabddb 100644 --- a/variants/Benedict/class.js +++ b/variants/Benedict/class.js @@ -6,6 +6,14 @@ export default class BenedictRules extends ChessRules { static get Options() { return { select: C.Options.select, + input: [ + { + label: "Cleopatra", + variable: "cleopatra", + type: "checkbox", + defaut: false + } + ], styles: [ "balance", "cylinder", @@ -25,53 +33,53 @@ export default class BenedictRules extends ChessRules { 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 = C.GetOppCol(color); - let squares = {}; - const specs = this.pieces(color, x, y)[piece]; - const attacks = specs.attack || specs.moves; - for (let a of attacks) { - outerLoop: for (let step of a.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 (a.range <= nbSteps++) - continue outerLoop; - i += step[0]; - j = this.computeY(j + step[1]); - } - if ( - this.onBoard(i, j) && this.getColor(i, j) == oppCol && - (!this.options["zen"] || this.getPieceType(i, j) == "k") - ) { - squares[C.CoordsToSquare({x: i, y: j})] = true; - } - } - } - return Object.keys(squares); + 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"})} + ); } postProcessPotentialMoves(moves) { - moves.forEach(m => { - super.playOnBoard(m); - let attacks = this.findAttacks([m.end.x, m.end.y]) - if (this.options["zen"]) { - let endSquares = {}; - super.findCapturesOn([m.end.x, m.end.y], {zen: true}).forEach(c => { - endSquares[C.CoordsToSquare(c.end)] = true; - }); - Array.prototype.push.apply(attacks, Object.keys(endSquares)); - } - super.undoOnBoard(m); + const oppCol = C.GetOppCol(this.turn); + let bMoves = super.postProcessPotentialMoves(moves); + bMoves.forEach(m => { m.flips = []; - attacks.map(C.SquareToCoords).forEach(a => { - m.flips.push({x: a.x, y: a.y}); - }); + 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 ( + super.canTake([i1, j1], [i2, j2]) && + (!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' && super.canTake([i2, j2], [i1, j1]) + ); + Array.prototype.push.apply(attacks, zenAttacks); + } + super.undoOnBoard(m); + attacks.forEach(a => m.flips.push({x: a.sq[0], y: a.sq[1]})); + } }); - return moves; + return bMoves; } playOnBoard(move) { @@ -90,20 +98,6 @@ export default class BenedictRules extends ChessRules { } } - postPlay(move) { - if (this.options["balance"] && [1, 3].includes(this.movesCount)) { - // If enemy king is flipped: game over - const oppCol = C.GetOppCol(move.vanish[0].c); - const oppKingPos = this.searchKingPos(oppCol); - if (oppKingPos[0] < 0) { - this.turn = oppCol; - this.movesCount++; - return; - } - } - super.postPlay(move); - } - // Moves cannot flip our king's color, so all are valid filterValid(moves) { return moves;