- 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 = C.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[C.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 (
+ 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]}));