1 import { ChessRules
} from "@/base_rules";
2 import { ArrayFun
} from "@/utils/array";
3 import { randInt
} from "@/utils/alea";
5 export class KnightmateRules
extends ChessRules
{
6 static get COMMONER() {
11 return ChessRules
.PIECES
.concat([V
.COMMONER
]);
15 return ([V
.KING
, V
.COMMONER
].includes(b
[1]) ? "Knightmate/" : "") + b
;
18 static GenRandInitFen(randomness
) {
19 return ChessRules
.GenRandInitFen(randomness
)
20 .replace(/n
/g
, 'c').replace(/N
/g
, 'C');
23 getPotentialMovesFrom([x
, y
]) {
24 switch (this.getPiece(x
, y
)) {
26 return this.getPotentialCommonerMoves([x
, y
]);
28 return super.getPotentialMovesFrom([x
, y
]);
32 getPotentialCommonerMoves(sq
) {
33 return this.getSlideNJumpMoves(
35 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]),
40 getPotentialKingMoves(sq
) {
41 return super.getPotentialKnightMoves(sq
).concat(super.getCastleMoves(sq
));
44 isAttacked(sq
, color
) {
46 this.isAttackedByCommoner(sq
, color
) ||
47 this.isAttackedByPawn(sq
, color
) ||
48 this.isAttackedByRook(sq
, color
) ||
49 this.isAttackedByBishop(sq
, color
) ||
50 this.isAttackedByQueen(sq
, color
) ||
51 this.isAttackedByKing(sq
, color
)
55 isAttackedByKing(sq
, color
) {
56 return this.isAttackedBySlideNJump(
65 isAttackedByCommoner(sq
, color
) {
66 return this.isAttackedBySlideNJump(
70 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]),
79 c: 5, //the commoner is valuable