c0fffcc00f203c88d59626c4ab9dae8112b225a3
1 import ChessRules
from "/base_rules.js";
2 import PiPo
from "/utils/PiPo.js";
4 export default class BenedictRules
extends ChessRules
{
8 select: ChessRules
.Options
.select
,
11 ChessRules
.Options
.styles
.filter(s
=> {
13 ["balance", "cylinder", "dark", "doublemove", "progressive", "zen"]
37 // Find potential captures from a square
38 // follow steps from x,y until something is met.
40 const [color
, piece
] = [this.getColor(x
, y
), this.getPiece(x
, y
)];
41 const oppCol
= ChessRules
.GetOppCol(color
);
43 const specs
= this.pieces(color
)[piece
];
44 const steps
= specs
.attack
|| specs
.steps
;
45 outerLoop: for (let step
of steps
) {
46 let [i
, j
] = [x
+ step
[0], this.computeY(y
+ step
[1])];
48 while (this.onBoard(i
, j
) && this.board
[i
][j
] == "") {
49 if (specs
.range
<= nbSteps
++) continue outerLoop
;
51 j
= this.computeY(j
+ step
[1]);
53 if (this.onBoard(i
, j
) && this.getColor(i
, j
) == oppCol
)
54 squares
[ChessRules
.CoordsToSquare({x: i
, y: j
})] = true;
56 return Object
.keys(squares
);
59 postProcessPotentialMoves(moves
) {
60 if (moves
.length
== 0) return moves
;
61 const [x
, y
] = [moves
[0].end
.x
, moves
[0].end
.y
];
62 const color
= this.getColor(moves
[0].start
.x
, moves
[0].start
.y
);
63 const oppCol
= ChessRules
.GetOppCol(color
);
64 moves
= super.postProcessPotentialMoves(moves
);
68 if (this.options
["zen"]) {
70 super.getZenCaptures(x
, y
).forEach(c
=> {
71 endSquares
[ChessRules
.CoordsToSquare(c
.end
)] = true;
73 attacks
= Object
.keys(endSquares
);
75 else attacks
= this.findAttacks([m
.end
.x
, m
.end
.y
])
77 attacks
.map(ChessRules
.SquareToCoords
).forEach(a
=> {
78 const p
= this.getPiece(a
.x
, a
.y
);
79 m
.appear
.push(new PiPo({x: a
.x
, y: a
.y
, c: color
, p: p
}));
80 m
.vanish
.push(new PiPo({x: a
.x
, y: a
.y
, c: oppCol
, p: p
}));
86 // Moves cannot flip our king's color, so (almost) all are valid
88 if (this.options
["balance"] && [1, 3].includes(this.movesCount
))
89 return moves
.filter(m
=> m
.vanish
.every(v
=> v
.p
!= ChessRules
.KING
));
93 // Since it's used just for the king, and there are no captures:
94 underCheck(square
, color
) {