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
,
29 // Find potential captures from a square
30 // follow steps from x,y until something is met.
32 const [color
, piece
] = [this.getColor(x
, y
), this.getPiece(x
, y
)];
33 const oppCol
= C
.GetOppCol(color
);
35 const specs
= this.pieces(color
, x
, y
)[piece
];
36 const attacks
= specs
.attack
|| specs
.moves
;
37 for (let a
of attacks
) {
38 outerLoop: for (let step
of a
.steps
) {
39 let [i
, j
] = [x
+ step
[0], this.computeY(y
+ step
[1])];
41 while (this.onBoard(i
, j
) && this.board
[i
][j
] == "") {
42 if (a
.range
<= nbSteps
++) continue outerLoop
;
44 j
= this.computeY(j
+ step
[1]);
46 if (this.onBoard(i
, j
) && this.getColor(i
, j
) == oppCol
)
47 squares
[C
.CoordsToSquare({x: i
, y: j
})] = true;
50 return Object
.keys(squares
);
53 postProcessPotentialMoves(moves
) {
54 if (moves
.length
== 0) return moves
;
55 const [x
, y
] = [moves
[0].end
.x
, moves
[0].end
.y
];
56 const color
= this.getColor(moves
[0].start
.x
, moves
[0].start
.y
);
57 const oppCol
= C
.GetOppCol(color
);
58 moves
= super.postProcessPotentialMoves(moves
);
62 if (this.options
["zen"]) {
64 super.getZenCaptures(x
, y
).forEach(c
=> {
65 endSquares
[C
.CoordsToSquare(c
.end
)] = true;
67 attacks
= Object
.keys(endSquares
);
69 else attacks
= this.findAttacks([m
.end
.x
, m
.end
.y
])
71 attacks
.map(C
.SquareToCoords
).forEach(a
=> {
72 const p
= this.getPiece(a
.x
, a
.y
);
73 m
.appear
.push(new PiPo({x: a
.x
, y: a
.y
, c: color
, p: p
}));
74 m
.vanish
.push(new PiPo({x: a
.x
, y: a
.y
, c: oppCol
, p: p
}));
80 // Moves cannot flip our king's color, so (almost) all are valid
82 if (this.options
["balance"] && [1, 3].includes(this.movesCount
))
83 return moves
.filter(m
=> m
.vanish
.every(v
=> v
.p
!= C
.KING
));
87 // Since it's used just for the king, and there are no captures:
88 underCheck(square
, color
) {