Attempt to clarify installation instructions a little
[vchess.git] / client / src / variants / Doublearmy.js
... / ...
CommitLineData
1import { 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 be captured quickly...
7
8export 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(options) {
23 const fen = ChessRules.GenRandInitFen(options);
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, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1);
49 }
50
51 isAttacked(sq, color) {
52 return (
53 super.isAttacked(sq, color) ||
54 this.isAttackedByCommoner(sq, color)
55 );
56 }
57
58 isAttackedByCommoner(sq, color) {
59 return this.isAttackedBySlideNJump(
60 sq, color, V.COMMONER, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1);
61 }
62
63 static get VALUES() {
64 return Object.assign(
65 { c: 5 },
66 ChessRules.VALUES
67 );
68 }
69
70 static get SEARCH_DEPTH() {
71 return 2;
72 }
73
74};