8176b957b0502eafa9fdd9a2e408fe4dbc514174
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
{
8 static get PawnSpecs() {
12 { promotions: [V
.LANCER
, V
.ARCHER
, V
.KHESHIG
, V
.FALCON
] }
16 static get HasFlags() {
20 static get HasEnpassant() {
28 static GenRandInitFen(randomness
) {
30 return "lhafkahl/8/pppppppp/8/8/PPPPPPPP/8/LHAFKAHL w 0 ah -";
32 let pieces
= { w: new Array(8), b: new Array(8) };
33 // Shuffle pieces on first (and last rank if randomness == 2)
34 for (let c
of ["w", "b"]) {
35 if (c
== 'b' && randomness
== 1) {
36 pieces
['b'] = pieces
['w'];
40 let positions
= ArrayFun
.range(8);
42 let randIndex
= 2 * randInt(4);
43 const bishop1Pos
= positions
[randIndex
];
44 let randIndex_tmp
= 2 * randInt(4) + 1;
45 const bishop2Pos
= positions
[randIndex_tmp
];
46 positions
.splice(Math
.max(randIndex
, randIndex_tmp
), 1);
47 positions
.splice(Math
.min(randIndex
, randIndex_tmp
), 1);
49 randIndex
= randInt(6);
50 const knight1Pos
= positions
[randIndex
];
51 positions
.splice(randIndex
, 1);
52 randIndex
= randInt(5);
53 const knight2Pos
= positions
[randIndex
];
54 positions
.splice(randIndex
, 1);
56 randIndex
= randInt(4);
57 const queenPos
= positions
[randIndex
];
58 positions
.splice(randIndex
, 1);
60 const rook1Pos
= positions
[0];
61 const kingPos
= positions
[1];
62 const rook2Pos
= positions
[2];
64 pieces
[c
][rook1Pos
] = "l";
65 pieces
[c
][knight1Pos
] = "h";
66 pieces
[c
][bishop1Pos
] = "a";
67 pieces
[c
][queenPos
] = "f";
68 pieces
[c
][kingPos
] = "k";
69 pieces
[c
][bishop2Pos
] = "a";
70 pieces
[c
][knight2Pos
] = "h";
71 pieces
[c
][rook2Pos
] = "l";
74 pieces
["b"].join("") +
75 "/8/pppppppp/8/8/PPPPPPPP/8/" +
76 pieces
["w"].join("").toUpperCase() +
86 return [V
.LANCER
, V
.ARCHER
, V
.KHESHIG
, V
.FALCON
, V
.KING
];
89 getPotentialMovesFrom(sq
) {
90 switch (this.getPiece(sq
[0], sq
[1])) {
92 return super.getPotentialPawnMoves(sq
);
94 return super.getPotentialLancerMoves(sq
);
96 return super.getPotentialArcherMoves(sq
);
98 return super.getPotentialKheshigMoves(sq
);
100 return this.getPotentialFalconMoves(sq
);
102 return super.getPotentialKingMoves(sq
)
104 return []; //never reached
107 getPotentialFalconMoves(sq
) {
108 const onlyMoves
= this.getSlideNJumpMoves(
110 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]),
114 const onlyTakes
= this.getSlideNJumpMoves(
120 return onlyMoves
.concat(onlyTakes
);
123 isAttacked(sq
, color
) {
125 super.isAttackedByPawn(sq
, color
) ||
126 super.isAttackedByLancer(sq
, color
) ||
127 super.isAttackedByKheshig(sq
, color
) ||
128 super.isAttackedByArcher(sq
, color
) ||
129 this.isAttackedByFalcon(sq
, color
) ||
130 super.isAttackedByKing(sq
, color
)
134 isAttackedByFalcon(sq
, color
) {
135 return this.isAttackedBySlideNJump(
136 sq
, color
, V
.FALCON
, V
.steps
[V
.KNIGHT
], "oneStep");
139 static get VALUES() {