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