X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FBenedict%2Fclass.js;h=e055e8630beff7c9688acadfcd04bdf7ccf7a9ae;hb=65cf1690c6119c949e2ea8feba8835b6e90b79a2;hp=88609d7b719b5a172710b0345c439a7be4405348;hpb=6997e386b546c650870d64176029aff55d13edb7;p=xogo.git diff --git a/variants/Benedict/class.js b/variants/Benedict/class.js index 88609d7..e055e86 100644 --- a/variants/Benedict/class.js +++ b/variants/Benedict/class.js @@ -6,7 +6,14 @@ export default class BenedictRules extends ChessRules { static get Options() { return { select: C.Options.select, - check: [], + input: [ + { + label: "Cleopatra", + variable: "cleopatra", + type: "checkbox", + defaut: false + } + ], styles: [ "balance", "cylinder", @@ -22,6 +29,20 @@ export default class BenedictRules extends ChessRules { return false; } + canTake() { + return 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"})} + ); + } + // Find potential captures from a square // follow steps from x,y until something is met. findAttacks([x, y]) { @@ -32,13 +53,13 @@ export default class BenedictRules extends ChessRules { 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 [i, j] = [x + step[0], this.getY(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]); + j = this.getY(j + step[1]); } if ( this.onBoard(i, j) && this.getColor(i, j) == oppCol && @@ -52,29 +73,23 @@ export default class BenedictRules extends ChessRules { } postProcessPotentialMoves(moves) { - if (moves.length == 0) - return moves; - const color = this.getColor(moves[0].start.x, moves[0].start.y); - const oppCol = C.GetOppCol(color); - // Remove captures (NOTE: altering canTake has side effects, - // Benedict is still based on captures even if they are forbidden): - moves = super.postProcessPotentialMoves(moves) - .filter(m => this.board[m.end.x][m.end.y] == ""); 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], true).forEach(c => { - endSquares[C.CoordsToSquare(c.end)] = true; + m.flips = []; + if (!this.options["cleopatra"] || m.vanish[0].p == 'q') { + 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); + attacks.map(C.SquareToCoords).forEach(a => { + m.flips.push({x: a.x, y: a.y}); }); - Array.prototype.push.apply(attacks, Object.keys(endSquares)); } - super.undoOnBoard(m); - m.flips = []; - attacks.map(C.SquareToCoords).forEach(a => { - m.flips.push({x: a.x, y: a.y}); - }); }); return moves; } @@ -115,7 +130,7 @@ export default class BenedictRules extends ChessRules { } // A king under (regular) check flips color, and the game is over. - underCheck(square, color) { + underCheck() { return false; }