1 import ChessRules
from "/base_rules.js";
2 import PiPo
from "/utils/PiPo.js";
4 export default class BenedictRules
extends ChessRules
{
8 select: C
.Options
.select
,
12 variable: "cleopatra",
37 if (!this.options
["cleopatra"])
38 return super.pieces(color
, x
, y
);
39 const allSpecs
= super.pieces(color
, x
, y
);
40 return Object
.assign({},
42 {'q': Object
.assign({}, allSpecs
['q'], {"class": "cleopatra"})}
46 postProcessPotentialMoves(moves
) {
49 if (!this.options
["cleopatra"] || m
.vanish
[0].p
== 'q') {
51 let attacks
= super.findDestSquares(
53 {attackOnly: true, segments: false},
54 ([x
, y
] => this.canTake([m
.end
.x
, m
.end
.y
], [x
, y
]))
56 if (this.options
["zen"]) {
57 const zenAttacks
= super.findCapturesOn(
60 ([x
, y
] => this.canTake([m
.end
.x
, m
.end
.y
], [x
, y
]))
62 Array
.prototype.push
.apply(attacks
, zenAttacks
);
65 attacks
.forEach(a
=> m
.flips
.push({x: a
.sq
[0], y: a
.sq
[1]}));
72 super.playOnBoard(move);
73 this.flipColorOf(move.flips
);
76 super.undoOnBoard(move);
77 this.flipColorOf(move.flips
);
81 for (let xy
of flips
) {
82 const newColor
= C
.GetOppCol(this.getColor(xy
.x
, xy
.y
));
83 this.board
[xy
.x
][xy
.y
] = newColor
+ this.board
[xy
.x
][xy
.y
][1];
87 // Moves cannot flip our king's color, so all are valid
92 // A king under (regular) check flips color, and the game is over.
98 super.playVisual(move, r
);
99 move.flips
.forEach(f
=> {
100 this.g_pieces
[f
.x
][f
.y
].classList
.toggle("white");
101 this.g_pieces
[f
.x
][f
.y
].classList
.toggle("black");