Commit | Line | Data |
---|---|---|
f6dbe8e3 | 1 | class UpsidedownRules extends ChessRules |
388e4c40 | 2 | { |
69f3d801 | 3 | static get HasFlags() { return false; } |
388e4c40 | 4 | |
69f3d801 | 5 | static get HasEnpassant() { return false; } |
f6dbe8e3 | 6 | |
388e4c40 BA |
7 | getPotentialKingMoves(sq) |
8 | { | |
9 | // No castle | |
10 | return this.getSlideNJumpMoves(sq, | |
11 | V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep"); | |
12 | } | |
13 | ||
14 | static GenRandInitFen() | |
15 | { | |
16 | let pieces = { "w": new Array(8), "b": new Array(8) }; | |
17 | for (let c of ["w","b"]) | |
18 | { | |
19 | let positions = _.range(8); | |
20 | ||
26c1e3bd BA |
21 | let randIndex = _.random(7); |
22 | const kingPos = positions[randIndex]; | |
23 | positions.splice(randIndex, 1); | |
24 | ||
25 | // At least a knight must be next to the king: | |
26 | let knight1Pos = undefined; | |
27 | if (kingPos == 0) | |
28 | knight1Pos = 1; | |
29 | else if (kingPos == V.size.y-1) | |
30 | knight1Pos = V.size.y-2; | |
31 | else | |
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); | |
36 | ||
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]; | |
388e4c40 BA |
42 | positions.splice(Math.max(randIndex,randIndex_tmp), 1); |
43 | positions.splice(Math.min(randIndex,randIndex_tmp), 1); | |
44 | ||
26c1e3bd BA |
45 | randIndex = _.random(3); |
46 | const knight2Pos = positions[randIndex]; | |
388e4c40 BA |
47 | positions.splice(randIndex, 1); |
48 | ||
26c1e3bd BA |
49 | randIndex = _.random(2); |
50 | const queenPos = positions[randIndex]; | |
388e4c40 BA |
51 | positions.splice(randIndex, 1); |
52 | ||
26c1e3bd BA |
53 | const rook1Pos = positions[0]; |
54 | const rook2Pos = positions[1]; | |
388e4c40 BA |
55 | |
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'; | |
64 | } | |
f6dbe8e3 | 65 | return pieces["w"].join("").toUpperCase() + |
388e4c40 | 66 | "/PPPPPPPP/8/8/8/8/pppppppp/" + |
f6dbe8e3 | 67 | pieces["b"].join("") + |
69f3d801 | 68 | " w"; //no castle, no en-passant |
388e4c40 BA |
69 | } |
70 | } |