X-Git-Url: https://git.auder.net/assets/current/gitweb.css?a=blobdiff_plain;f=variants%2FBenedict%2Fclass.js;h=0fda796503e5b9cdfdd22f8b7c08a24a5ea695f3;hb=bc97fdd1302473b774cfb19e65dc3ed3ed388901;hp=bf15ee66d0e8e263be572a892a296c7e5d50f654;hpb=af9c9be34f416500f9e025e28f39fe89a8c7c345;p=xogo.git diff --git a/variants/Benedict/class.js b/variants/Benedict/class.js index bf15ee6..0fda796 100644 --- a/variants/Benedict/class.js +++ b/variants/Benedict/class.js @@ -1,7 +1,6 @@ -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 { @@ -25,14 +24,6 @@ export default class BenedictRules extends ChessRules { }; } - get hasEnpassant() { - return false; - } - - canTake() { - return false; - } - pieces(color, x, y) { if (!this.options["cleopatra"]) return super.pieces(color, x, y); @@ -44,20 +35,34 @@ export default class BenedictRules extends ChessRules { } postProcessPotentialMoves(moves) { - moves.forEach(m => { + 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: false}, - ([x, y] => this.canTake([m.end.x, m.end.y], [x, 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], - {segments: false}, - ([x, y] => this.canTake([m.end.x, m.end.y], [x, 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); } @@ -65,41 +70,7 @@ export default class BenedictRules extends ChessRules { attacks.forEach(a => m.flips.push({x: a.sq[0], y: a.sq[1]})); } }); - return moves; - } - - playOnBoard(move) { - super.playOnBoard(move); - this.flipColorOf(move.flips); - } - undoOnBoard(move) { - super.undoOnBoard(move); - this.flipColorOf(move.flips); - } - - flipColorOf(flips) { - for (let xy of flips) { - const newColor = C.GetOppCol(this.getColor(xy.x, xy.y)); - this.board[xy.x][xy.y] = newColor + this.board[xy.x][xy.y][1]; - } - } - - // Moves cannot flip our king's color, so all are valid - filterValid(moves) { - return moves; - } - - // A king under (regular) check flips color, and the game is over. - underCheck() { - return false; - } - - playVisual(move, r) { - super.playVisual(move, r); - move.flips.forEach(f => { - this.g_pieces[f.x][f.y].classList.toggle("white"); - this.g_pieces[f.x][f.y].classList.toggle("black"); - }); + return bMoves; } };