1 import { ChessRules
} from "@/base_rules";
2 import { ArrayFun
} from "@/utils/array";
3 import { randInt
} from "@/utils/alea";
5 export class KnightmateRules
extends ChessRules
{
7 static get COMMONER() {
12 return ChessRules
.PIECES
.concat([V
.COMMONER
]);
16 return ([V
.KING
, V
.COMMONER
].includes(b
[1]) ? "Knightmate/" : "") + b
;
19 static GenRandInitFen(randomness
) {
20 return ChessRules
.GenRandInitFen(randomness
)
21 .replace(/n
/g
, 'c').replace(/N
/g
, 'C');
24 getPotentialMovesFrom([x
, y
]) {
25 switch (this.getPiece(x
, y
)) {
27 return this.getPotentialCommonerMoves([x
, y
]);
29 return super.getPotentialMovesFrom([x
, y
]);
33 getPotentialCommonerMoves(sq
) {
34 return this.getSlideNJumpMoves(
36 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]),
41 getPotentialKingMoves(sq
) {
42 return super.getPotentialKnightMoves(sq
).concat(super.getCastleMoves(sq
));
45 isAttacked(sq
, color
) {
47 this.isAttackedByCommoner(sq
, color
) ||
48 this.isAttackedByPawn(sq
, color
) ||
49 this.isAttackedByRook(sq
, color
) ||
50 this.isAttackedByBishop(sq
, color
) ||
51 this.isAttackedByQueen(sq
, color
) ||
52 this.isAttackedByKing(sq
, color
)
56 isAttackedByKing(sq
, color
) {
57 return this.isAttackedBySlideNJump(
66 isAttackedByCommoner(sq
, color
) {
67 return this.isAttackedBySlideNJump(
71 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]),
80 c: 5, //the commoner is valuable