1 class UpsidedownRules
extends ChessRules
3 static get HasFlags() { return false; }
5 static get HasEnpassant() { return false; }
7 getPotentialKingMoves(sq
)
10 return this.getSlideNJumpMoves(sq
,
11 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), "oneStep");
14 static GenRandInitFen()
16 let pieces
= { "w": new Array(8), "b": new Array(8) };
17 for (let c
of ["w","b"])
19 let positions
= _
.range(8);
21 let randIndex
= _
.random(7);
22 const kingPos
= positions
[randIndex
];
23 positions
.splice(randIndex
, 1);
25 // At least a knight must be next to the king:
26 let knight1Pos
= undefined;
29 else if (kingPos
== V
.size
.y
-1)
30 knight1Pos
= V
.size
.y
-2;
32 knight1Pos
= kingPos
+ (Math
.random() < 0.5 ? 1 : -1);
33 // Search for knight1Pos index in positions and remove it
34 const knight1Index
= positions
.indexOf(knight1Pos
);
35 positions
.splice(knight1Index
, 1);
37 // King+knight1 are on two consecutive squares: one light, one dark
38 randIndex
= 2 * _
.random(2);
39 const bishop1Pos
= positions
[randIndex
];
40 let randIndex_tmp
= 2 * _
.random(2) + 1;
41 const bishop2Pos
= positions
[randIndex_tmp
];
42 positions
.splice(Math
.max(randIndex
,randIndex_tmp
), 1);
43 positions
.splice(Math
.min(randIndex
,randIndex_tmp
), 1);
45 randIndex
= _
.random(3);
46 const knight2Pos
= positions
[randIndex
];
47 positions
.splice(randIndex
, 1);
49 randIndex
= _
.random(2);
50 const queenPos
= positions
[randIndex
];
51 positions
.splice(randIndex
, 1);
53 const rook1Pos
= positions
[0];
54 const rook2Pos
= positions
[1];
56 pieces
[c
][rook1Pos
] = 'r';
57 pieces
[c
][knight1Pos
] = 'n';
58 pieces
[c
][bishop1Pos
] = 'b';
59 pieces
[c
][queenPos
] = 'q';
60 pieces
[c
][kingPos
] = 'k';
61 pieces
[c
][bishop2Pos
] = 'b';
62 pieces
[c
][knight2Pos
] = 'n';
63 pieces
[c
][rook2Pos
] = 'r';
65 return pieces
["w"].join("").toUpperCase() +
66 "/PPPPPPPP/8/8/8/8/pppppppp/" +
67 pieces
["b"].join("") +
68 " w"; //no castle, no en-passant
72 const VariantRules
= UpsidedownRules
;