1 import { ChessRules
} from "@/base_rules";
2 import { OrdaRules
} from "@/variants/Orda";
3 import { ArrayFun
} from "@/utils/array";
4 import { randInt
} from "@/utils/alea";
6 export class OrdamirrorRules
extends OrdaRules
{
7 static get PawnSpecs() {
11 { promotions: [V
.LANCER
, V
.ARCHER
, V
.KHESHIG
, V
.FALCON
] }
15 static get HasFlags() {
19 static get HasEnpassant() {
27 static GenRandInitFen(randomness
) {
29 return "lhafkahl/8/pppppppp/8/8/PPPPPPPP/8/LHAFKAHL w 0 ah -";
31 let pieces
= { w: new Array(8), b: new Array(8) };
32 // Shuffle pieces on first (and last rank if randomness == 2)
33 for (let c
of ["w", "b"]) {
34 if (c
== 'b' && randomness
== 1) {
35 pieces
['b'] = pieces
['w'];
39 let positions
= ArrayFun
.range(8);
41 let randIndex
= 2 * randInt(4);
42 const bishop1Pos
= positions
[randIndex
];
43 let randIndex_tmp
= 2 * randInt(4) + 1;
44 const bishop2Pos
= positions
[randIndex_tmp
];
45 positions
.splice(Math
.max(randIndex
, randIndex_tmp
), 1);
46 positions
.splice(Math
.min(randIndex
, randIndex_tmp
), 1);
48 randIndex
= randInt(6);
49 const knight1Pos
= positions
[randIndex
];
50 positions
.splice(randIndex
, 1);
51 randIndex
= randInt(5);
52 const knight2Pos
= positions
[randIndex
];
53 positions
.splice(randIndex
, 1);
55 randIndex
= randInt(4);
56 const queenPos
= positions
[randIndex
];
57 positions
.splice(randIndex
, 1);
59 const rook1Pos
= positions
[0];
60 const kingPos
= positions
[1];
61 const rook2Pos
= positions
[2];
63 pieces
[c
][rook1Pos
] = "l";
64 pieces
[c
][knight1Pos
] = "h";
65 pieces
[c
][bishop1Pos
] = "a";
66 pieces
[c
][queenPos
] = "f";
67 pieces
[c
][kingPos
] = "k";
68 pieces
[c
][bishop2Pos
] = "a";
69 pieces
[c
][knight2Pos
] = "h";
70 pieces
[c
][rook2Pos
] = "l";
73 pieces
["b"].join("") +
74 "/8/pppppppp/8/8/PPPPPPPP/8/" +
75 pieces
["w"].join("").toUpperCase() +
85 return [V
.LANCER
, V
.ARCHER
, V
.KHESHIG
, V
.FALCON
, V
.KING
];
88 getPotentialMovesFrom(sq
) {
89 switch (this.getPiece(sq
[0], sq
[1])) {
91 return super.getPotentialPawnMoves(sq
);
93 return super.getPotentialLancerMoves(sq
);
95 return super.getPotentialArcherMoves(sq
);
97 return super.getPotentialKheshigMoves(sq
);
99 return this.getPotentialFalconMoves(sq
);
101 return super.getPotentialKingMoves(sq
)
103 return []; //never reached
106 getPotentialFalconMoves(sq
) {
107 const onlyMoves
= this.getSlideNJumpMoves(
109 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]),
113 const onlyTakes
= this.getSlideNJumpMoves(
119 return onlyMoves
.concat(onlyTakes
);
122 isAttacked(sq
, color
) {
124 super.isAttackedByPawn(sq
, color
) ||
125 super.isAttackedByLancer(sq
, color
) ||
126 super.isAttackedByKheshig(sq
, color
) ||
127 super.isAttackedByArcher(sq
, color
) ||
128 this.isAttackedByFalcon(sq
, color
) ||
129 super.isAttackedByKing(sq
, color
)
133 isAttackedByFalcon(sq
, color
) {
134 return this.isAttackedBySlideNJump(
135 sq
, color
, V
.FALCON
, V
.steps
[V
.KNIGHT
], "oneStep");
138 static get VALUES() {