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