Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Doublearmy.js
CommitLineData
de3f5625
BA
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
f52671e5 6// ...But the middle king will be captured quickly...
de3f5625
BA
7
8export class DoublearmyRules extends ChessRules {
7e8a7ea1 9
de3f5625
BA
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
4313762d
BA
22 static GenRandInitFen(options) {
23 const fen = ChessRules.GenRandInitFen(options);
de3f5625
BA
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(
4313762d 48 sq, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1);
de3f5625
BA
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(
4313762d 60 sq, color, V.COMMONER, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1);
de3f5625
BA
61 }
62
63 static get VALUES() {
64 return Object.assign(
4313762d
BA
65 { c: 5 },
66 ChessRules.VALUES
de3f5625
BA
67 );
68 }
69
70 static get SEARCH_DEPTH() {
71 return 2;
72 }
7e8a7ea1 73
de3f5625 74};