import { ArrayFun } from "@/utils/array";
import { randInt, shuffle } from "@/utils/alea";
-export const VariantRules = class RoyalraceRules extends ChessRules {
+export class RoyalraceRules extends ChessRules {
static get HasFlags() {
return false;
}
+ static get HasCastle() {
+ return false;
+ }
+
static get HasEnpassant() {
return false;
}
return this.getSlideNJumpMoves(sq, V.steps[V.KNIGHT]);
}
- // What are the king moves from square x,y ?
- getPotentialKingMoves(sq) {
- return this.getSlideNJumpMoves(
- sq,
- V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
- "oneStep"
- );
- }
-
filterValid(moves) {
if (moves.length == 0) return [];
const color = this.turn;
});
}
- isAttackedByPawn([x, y], colors) {
- const pawnShift = 1;
- if (x + pawnShift < V.size.x) {
- for (let c of colors) {
+ isAttackedByPawn([x, y], color) {
+ // Pawns can capture forward and backward:
+ for (let pawnShift of [-1, 1]) {
+ if (0 < x + pawnShift && x + pawnShift < V.size.x) {
for (let i of [-1, 1]) {
if (
y + i >= 0 &&
y + i < V.size.y &&
this.getPiece(x + pawnShift, y + i) == V.PAWN &&
- this.getColor(x + pawnShift, y + i) == c
+ this.getColor(x + pawnShift, y + i) == color
) {
return true;
}
return false;
}
- isAttackedByKnight(sq, colors) {
+ isAttackedByKnight(sq, color) {
return this.isAttackedBySlideNJump(
sq,
- colors,
+ color,
V.KNIGHT,
V.steps[V.KNIGHT]
);