Add an entry to the FAQ
[vchess.git] / client / src / variants / Doublearmy.js
1 import { ChessRules } from "@/base_rules";
2
3 // Ideas with 2 kings:
4 // Stage 1 {w, b} : 2 kings on board, value 5.
5 // Stage 2: only one, get mated and all that, value 1000
6 // ...But the middle king will get captured quickly...
7
8 export class DoublearmyRules extends ChessRules {
9
10 static get COMMONER() {
11 return "c";
12 }
13
14 static get PIECES() {
15 return ChessRules.PIECES.concat([V.COMMONER]);
16 }
17
18 getPpath(b) {
19 return (b[1] == V.COMMONER ? "Doublearmy/" : "") + b;
20 }
21
22 static GenRandInitFen(randomness) {
23 const fen = ChessRules.GenRandInitFen(randomness);
24 const rows = fen.split(" ")[0].split("/");
25 return (
26 rows[0] + "/" +
27 rows[1] + "/" +
28 rows[0].replace('k', 'c') + "/" +
29 rows[1] + "/" +
30 rows[6] + "/" +
31 rows[7].replace('K', 'C') + "/" +
32 rows[6] + "/" +
33 rows[7] + fen.slice(-11)
34 );
35 }
36
37 getPotentialMovesFrom([x, y]) {
38 switch (this.getPiece(x, y)) {
39 case V.COMMONER:
40 return this.getPotentialCommonerMoves([x, y]);
41 default:
42 return super.getPotentialMovesFrom([x, y]);
43 }
44 }
45
46 getPotentialCommonerMoves(sq) {
47 return this.getSlideNJumpMoves(
48 sq,
49 V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
50 "oneStep"
51 );
52 }
53
54 isAttacked(sq, color) {
55 return (
56 super.isAttacked(sq, color) ||
57 this.isAttackedByCommoner(sq, color)
58 );
59 }
60
61 isAttackedByCommoner(sq, color) {
62 return this.isAttackedBySlideNJump(
63 sq,
64 color,
65 V.COMMONER,
66 V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
67 "oneStep"
68 );
69 }
70
71 static get VALUES() {
72 return Object.assign(
73 {},
74 ChessRules.VALUES,
75 { c: 5 }
76 );
77 }
78
79 static get SEARCH_DEPTH() {
80 return 2;
81 }
82
83 };