1 import { ChessRules
} from "@/base_rules";
2 import { ArrayFun
} from "@/utils/array";
3 import { randInt
} from "@/utils/alea";
5 export const VariantRules
= 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
, colors
) {
46 this.isAttackedByCommoner(sq
, colors
) ||
47 this.isAttackedByPawn(sq
, colors
) ||
48 this.isAttackedByRook(sq
, colors
) ||
49 this.isAttackedByBishop(sq
, colors
) ||
50 this.isAttackedByQueen(sq
, colors
) ||
51 this.isAttackedByKing(sq
, colors
)
55 isAttackedByKing(sq
, colors
) {
56 return this.isAttackedBySlideNJump(
65 isAttackedByCommoner(sq
, colors
) {
66 return this.isAttackedBySlideNJump(
70 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]),
79 c: 5, //the commoner is valuable