Fix Antiking 1 notation
[vchess.git] / client / src / variants / Upsidedown.js
1 import { ChessRules } from "@/base_rules";
2 import { randInt } from "@/utils/alea";
3 import { ArrayFun } from "@/utils/array";
4
5 export const VariantRules = class UpsidedownRules extends ChessRules {
6 static get HasFlags() {
7 return false;
8 }
9
10 static get HasCastle() {
11 return false;
12 }
13
14 static get HasEnpassant() {
15 return false;
16 }
17
18 static GenRandInitFen(randomness) {
19 if (randomness == 0)
20 return "RNBQKBNR/PPPPPPPP/8/8/8/8/pppppppp/rnbqkbnr w 0";
21
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'];
26 break;
27 }
28
29 let positions = ArrayFun.range(8);
30
31 let randIndex = randInt(8);
32 const kingPos = positions[randIndex];
33 positions.splice(randIndex, 1);
34
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);
43
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);
51
52 randIndex = randInt(4);
53 const knight2Pos = positions[randIndex];
54 positions.splice(randIndex, 1);
55
56 randIndex = randInt(3);
57 const queenPos = positions[randIndex];
58 positions.splice(randIndex, 1);
59
60 const rook1Pos = positions[0];
61 const rook2Pos = positions[1];
62
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";
71 }
72 return (
73 pieces["w"].join("").toUpperCase() +
74 "/PPPPPPPP/8/8/8/8/pppppppp/" +
75 pieces["b"].join("") +
76 " w 0"
77 ); //no castle, no en-passant
78 }
79
80 static get SEARCH_DEPTH() {
81 return 2;
82 }
83 };