Commit | Line | Data |
---|---|---|
a97bdbda | 1 | import { ChessRules } from "@/base_rules"; |
a97bdbda | 2 | |
3de62e0a | 3 | export 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 | ||
7ba4a5bc BA |
17 | static GenRandInitFen(randomness) { |
18 | return ChessRules.GenRandInitFen(randomness) | |
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( | |
33 | sq, | |
34 | V.steps[V.ROOK].concat(V.steps[V.BISHOP]), | |
35 | "oneStep" | |
36 | ); | |
37 | } | |
38 | ||
39 | getPotentialKingMoves(sq) { | |
40 | return super.getPotentialKnightMoves(sq).concat(super.getCastleMoves(sq)); | |
41 | } | |
42 | ||
68e19a44 | 43 | isAttacked(sq, color) { |
a97bdbda | 44 | return ( |
68e19a44 BA |
45 | this.isAttackedByCommoner(sq, color) || |
46 | this.isAttackedByPawn(sq, color) || | |
47 | this.isAttackedByRook(sq, color) || | |
48 | this.isAttackedByBishop(sq, color) || | |
49 | this.isAttackedByQueen(sq, color) || | |
50 | this.isAttackedByKing(sq, color) | |
a97bdbda BA |
51 | ); |
52 | } | |
53 | ||
68e19a44 | 54 | isAttackedByKing(sq, color) { |
a97bdbda BA |
55 | return this.isAttackedBySlideNJump( |
56 | sq, | |
68e19a44 | 57 | color, |
a97bdbda BA |
58 | V.KING, |
59 | V.steps[V.KNIGHT], | |
60 | "oneStep" | |
61 | ); | |
62 | } | |
63 | ||
68e19a44 | 64 | isAttackedByCommoner(sq, color) { |
a97bdbda BA |
65 | return this.isAttackedBySlideNJump( |
66 | sq, | |
68e19a44 | 67 | color, |
a97bdbda BA |
68 | V.COMMONER, |
69 | V.steps[V.ROOK].concat(V.steps[V.BISHOP]), | |
70 | "oneStep" | |
71 | ); | |
72 | } | |
73 | ||
74 | static get VALUES() { | |
75 | return { | |
76 | p: 1, | |
77 | r: 5, | |
78 | c: 5, //the commoner is valuable | |
79 | b: 3, | |
80 | q: 9, | |
81 | k: 1000 | |
82 | }; | |
83 | } | |
7e8a7ea1 | 84 | |
a97bdbda | 85 | }; |