5503f2f4e1f2e5a2c1dfe92be1f97538a68dcdae
[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.GetOppCol(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 super.canTake([i1, j1], [i2, j2]) &&
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]) =>
65 this.getPiece(i1, j1) != 'k' && super.canTake([i2, j2], [i1, j1])
66 );
67 Array.prototype.push.apply(attacks, zenAttacks);
68 }
69 super.undoOnBoard(m);
70 attacks.forEach(a => m.flips.push({x: a.sq[0], y: a.sq[1]}));
71 }
72 });
73 return bMoves;
74 }
75
76 };