Fix Progressive2. Fixing attempt on Doublemove1
[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
6// ...But the middle king will get captured quickly...
7
8export class DoublearmyRules extends ChessRules {
9 static get COMMONER() {
10 return "c";
11 }
12
13 static get PIECES() {
14 return ChessRules.PIECES.concat([V.COMMONER]);
15 }
16
17 getPpath(b) {
18 return (b[1] == V.COMMONER ? "Doublearmy/" : "") + b;
19 }
20
21 static GenRandInitFen(randomness) {
22 const fen = ChessRules.GenRandInitFen(randomness);
23 const rows = fen.split(" ")[0].split("/");
24 return (
25 rows[0] + "/" +
26 rows[1] + "/" +
27 rows[0].replace('k', 'c') + "/" +
28 rows[1] + "/" +
29 rows[6] + "/" +
30 rows[7].replace('K', 'C') + "/" +
31 rows[6] + "/" +
32 rows[7] + fen.slice(-11)
33 );
34 }
35
36 getPotentialMovesFrom([x, y]) {
37 switch (this.getPiece(x, y)) {
38 case V.COMMONER:
39 return this.getPotentialCommonerMoves([x, y]);
40 default:
41 return super.getPotentialMovesFrom([x, y]);
42 }
43 }
44
45 getPotentialCommonerMoves(sq) {
46 return this.getSlideNJumpMoves(
47 sq,
48 V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
49 "oneStep"
50 );
51 }
52
53 isAttacked(sq, color) {
54 return (
55 super.isAttacked(sq, color) ||
56 this.isAttackedByCommoner(sq, color)
57 );
58 }
59
60 isAttackedByCommoner(sq, color) {
61 return this.isAttackedBySlideNJump(
62 sq,
63 color,
64 V.COMMONER,
65 V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
66 "oneStep"
67 );
68 }
69
70 static get VALUES() {
71 return Object.assign(
72 {},
73 ChessRules.VALUES,
74 { c: 5 }
75 );
76 }
77
78 static get SEARCH_DEPTH() {
79 return 2;
80 }
81};