Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Knightmate1.js
1 import { ChessRules } from "@/base_rules";
2
3 export class Knightmate1Rules extends ChessRules {
4
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
17 static GenRandInitFen(options) {
18 return ChessRules.GenRandInitFen(options)
19 .replace(/n/g, 'c').replace(/N/g, 'C');
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(
33 sq, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1);
34 }
35
36 getPotentialKingMoves(sq) {
37 return super.getPotentialKnightMoves(sq).concat(super.getCastleMoves(sq));
38 }
39
40 isAttacked(sq, color) {
41 return (
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)
48 );
49 }
50
51 isAttackedByKing(sq, color) {
52 return this.isAttackedBySlideNJump(
53 sq, color, V.KING, V.steps[V.KNIGHT], 1);
54 }
55
56 isAttackedByCommoner(sq, color) {
57 return this.isAttackedBySlideNJump(
58 sq, color, V.COMMONER, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1);
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 }
71
72 };