Fix Arena diag
[vchess.git] / client / src / variants / Knightmate1.js
CommitLineData
a97bdbda 1import { ChessRules } from "@/base_rules";
a97bdbda 2
3de62e0a 3export class Knightmate1Rules extends ChessRules {
7e8a7ea1 4
a97bdbda
BA
5 static get COMMONER() {
6 return "c";
7 }
8
9 static get PIECES() {
10 return ChessRules.PIECES.concat([V.COMMONER]);
11 }
12
13 getPpath(b) {
14 return ([V.KING, V.COMMONER].includes(b[1]) ? "Knightmate/" : "") + b;
15 }
16
4313762d
BA
17 static GenRandInitFen(options) {
18 return ChessRules.GenRandInitFen(options)
7ba4a5bc 19 .replace(/n/g, 'c').replace(/N/g, 'C');
a97bdbda
BA
20 }
21
22 getPotentialMovesFrom([x, y]) {
23 switch (this.getPiece(x, y)) {
24 case V.COMMONER:
25 return this.getPotentialCommonerMoves([x, y]);
26 default:
27 return super.getPotentialMovesFrom([x, y]);
28 }
29 }
30
31 getPotentialCommonerMoves(sq) {
32 return this.getSlideNJumpMoves(
4313762d 33 sq, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1);
a97bdbda
BA
34 }
35
36 getPotentialKingMoves(sq) {
37 return super.getPotentialKnightMoves(sq).concat(super.getCastleMoves(sq));
38 }
39
68e19a44 40 isAttacked(sq, color) {
a97bdbda 41 return (
68e19a44
BA
42 this.isAttackedByCommoner(sq, color) ||
43 this.isAttackedByPawn(sq, color) ||
44 this.isAttackedByRook(sq, color) ||
45 this.isAttackedByBishop(sq, color) ||
46 this.isAttackedByQueen(sq, color) ||
47 this.isAttackedByKing(sq, color)
a97bdbda
BA
48 );
49 }
50
68e19a44 51 isAttackedByKing(sq, color) {
a97bdbda 52 return this.isAttackedBySlideNJump(
4313762d 53 sq, color, V.KING, V.steps[V.KNIGHT], 1);
a97bdbda
BA
54 }
55
68e19a44 56 isAttackedByCommoner(sq, color) {
a97bdbda 57 return this.isAttackedBySlideNJump(
4313762d 58 sq, color, V.COMMONER, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1);
a97bdbda
BA
59 }
60
61 static get VALUES() {
62 return {
63 p: 1,
64 r: 5,
65 c: 5, //the commoner is valuable
66 b: 3,
67 q: 9,
68 k: 1000
69 };
70 }
7e8a7ea1 71
a97bdbda 72};