| 1 | import AbstractFlipRules from "/variants/_Flip/class.js"; |
| 2 | import PiPo from "/utils/PiPo.js"; |
| 3 | |
| 4 | export default class BenedictRules extends AbstractFlipRules { |
| 5 | |
| 6 | static get Options() { |
| 7 | return { |
| 8 | select: C.Options.select, |
| 9 | input: [ |
| 10 | { |
| 11 | label: "Cleopatra", |
| 12 | variable: "cleopatra", |
| 13 | type: "checkbox", |
| 14 | defaut: false |
| 15 | } |
| 16 | ], |
| 17 | styles: [ |
| 18 | "balance", |
| 19 | "cylinder", |
| 20 | "dark", |
| 21 | "doublemove", |
| 22 | "progressive", |
| 23 | "zen" |
| 24 | ] |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | pieces(color, x, y) { |
| 29 | if (!this.options["cleopatra"]) |
| 30 | return super.pieces(color, x, y); |
| 31 | const allSpecs = super.pieces(color, x, y); |
| 32 | return Object.assign({}, |
| 33 | allSpecs, |
| 34 | {'q': Object.assign({}, allSpecs['q'], {"class": "cleopatra"})} |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | postProcessPotentialMoves(moves) { |
| 39 | const oppCol = C.GetOppCol(this.turn); |
| 40 | let bMoves = super.postProcessPotentialMoves(moves); |
| 41 | bMoves.forEach(m => { |
| 42 | m.flips = []; |
| 43 | if (!this.options["cleopatra"] || m.vanish[0].p == 'q') { |
| 44 | super.playOnBoard(m); |
| 45 | let attacks = super.findDestSquares( |
| 46 | [m.end.x, m.end.y], |
| 47 | { |
| 48 | attackOnly: true, |
| 49 | segments: this.options["cylinder"] |
| 50 | }, |
| 51 | ([i1, j1], [i2, j2]) => { |
| 52 | return ( |
| 53 | super.canTake([i1, j1], [i2, j2]) && |
| 54 | (!this.options["zen"] || this.getPiece(i2, j2) == 'k') |
| 55 | ); |
| 56 | } |
| 57 | ); |
| 58 | if (this.options["zen"]) { |
| 59 | const zenAttacks = super.findCapturesOn( |
| 60 | [m.end.x, m.end.y], |
| 61 | { |
| 62 | byCol: [oppCol], |
| 63 | segments: this.options["cylinder"] |
| 64 | }, |
| 65 | ([i1, j1], [i2, j2]) => |
| 66 | this.getPiece(i1, j1) != 'k' && super.canTake([i2, j2], [i1, j1]) |
| 67 | ); |
| 68 | Array.prototype.push.apply(attacks, zenAttacks); |
| 69 | } |
| 70 | super.undoOnBoard(m); |
| 71 | attacks.forEach(a => m.flips.push({x: a.sq[0], y: a.sq[1]})); |
| 72 | } |
| 73 | }); |
| 74 | return bMoves; |
| 75 | } |
| 76 | |
| 77 | }; |