207682408186ec6d92fdb730082f9c42c4b71fb2
1 import { ChessRules
} from "@/base_rules";
2 import { randInt
} from "@/utils/alea";
3 import { ArrayFun
} from "@/utils/array";
5 export class UpsidedownRules
extends ChessRules
{
6 static get HasFlags() {
10 static get HasCastle() {
14 static get HasEnpassant() {
18 static GenRandInitFen(randomness
) {
20 return "RNBQKBNR/PPPPPPPP/8/8/8/8/pppppppp/rnbqkbnr w 0";
22 let pieces
= { w: new Array(8), b: new Array(8) };
23 for (let c
of ["w", "b"]) {
24 if (c
== 'b' && randomness
== 1) {
25 pieces
['b'] = pieces
['w'];
29 let positions
= ArrayFun
.range(8);
31 let randIndex
= randInt(8);
32 const kingPos
= positions
[randIndex
];
33 positions
.splice(randIndex
, 1);
35 // At least a knight must be next to the king:
36 let knight1Pos
= undefined;
37 if (kingPos
== 0) knight1Pos
= 1;
38 else if (kingPos
== V
.size
.y
- 1) knight1Pos
= V
.size
.y
- 2;
39 else knight1Pos
= kingPos
+ (Math
.random() < 0.5 ? 1 : -1);
40 // Search for knight1Pos index in positions and remove it
41 const knight1Index
= positions
.indexOf(knight1Pos
);
42 positions
.splice(knight1Index
, 1);
44 // King+knight1 are on two consecutive squares: one light, one dark
45 randIndex
= 2 * randInt(3);
46 const bishop1Pos
= positions
[randIndex
];
47 let randIndex_tmp
= 2 * randInt(3) + 1;
48 const bishop2Pos
= positions
[randIndex_tmp
];
49 positions
.splice(Math
.max(randIndex
, randIndex_tmp
), 1);
50 positions
.splice(Math
.min(randIndex
, randIndex_tmp
), 1);
52 randIndex
= randInt(4);
53 const knight2Pos
= positions
[randIndex
];
54 positions
.splice(randIndex
, 1);
56 randIndex
= randInt(3);
57 const queenPos
= positions
[randIndex
];
58 positions
.splice(randIndex
, 1);
60 const rook1Pos
= positions
[0];
61 const rook2Pos
= positions
[1];
63 pieces
[c
][rook1Pos
] = "r";
64 pieces
[c
][knight1Pos
] = "n";
65 pieces
[c
][bishop1Pos
] = "b";
66 pieces
[c
][queenPos
] = "q";
67 pieces
[c
][kingPos
] = "k";
68 pieces
[c
][bishop2Pos
] = "b";
69 pieces
[c
][knight2Pos
] = "n";
70 pieces
[c
][rook2Pos
] = "r";
73 pieces
["w"].join("").toUpperCase() +
74 "/PPPPPPPP/8/8/8/8/pppppppp/" +
75 pieces
["b"].join("") +
77 ); //no castle, no en-passant
80 static get SEARCH_DEPTH() {