X-Git-Url: https://git.auder.net/?p=xogo.git;a=blobdiff_plain;f=variants%2FBenedict%2Fclass.js;h=bf15ee66d0e8e263be572a892a296c7e5d50f654;hp=e055e8630beff7c9688acadfcd04bdf7ccf7a9ae;hb=af9c9be34f416500f9e025e28f39fe89a8c7c345;hpb=e7d409fc03a8cd8459a2b41f9fef51c0a3fb0d6d diff --git a/variants/Benedict/class.js b/variants/Benedict/class.js index e055e86..bf15ee6 100644 --- a/variants/Benedict/class.js +++ b/variants/Benedict/class.js @@ -43,52 +43,26 @@ export default class BenedictRules extends ChessRules { ); } - // 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.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.getY(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); - } - postProcessPotentialMoves(moves) { moves.forEach(m => { m.flips = []; if (!this.options["cleopatra"] || m.vanish[0].p == 'q') { super.playOnBoard(m); - let attacks = this.findAttacks([m.end.x, m.end.y]) + 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])) + ); 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)); + const zenAttacks = super.findCapturesOn( + [m.end.x, m.end.y], + {segments: false}, + ([x, y] => this.canTake([m.end.x, m.end.y], [x, y])) + ); + Array.prototype.push.apply(attacks, zenAttacks); } super.undoOnBoard(m); - attacks.map(C.SquareToCoords).forEach(a => { - m.flips.push({x: a.x, y: a.y}); - }); + attacks.forEach(a => m.flips.push({x: a.sq[0], y: a.sq[1]})); } }); return moves; @@ -110,20 +84,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;