1 class HalfRules
extends ChessRules
3 // Standard rules on a 4x8 board with no pawns
5 initVariables(fen
) { } //nothing to do
9 // No castling, hence no flags; but flags defined for compatibility
10 this.castleFlags
= { "w":[false,false], "b":[false,false] };
13 static get size() { return [8,4]; }
15 getPotentialKingMoves(sq
)
17 const V
= VariantRules
;
19 return this.getSlideNJumpMoves(sq
,
20 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), "oneStep");
23 isAttacked(sq
, colors
)
25 return (this.isAttackedByRook(sq
, colors
)
26 || this.isAttackedByKnight(sq
, colors
)
27 || this.isAttackedByBishop(sq
, colors
)
28 || this.isAttackedByQueen(sq
, colors
)
29 || this.isAttackedByKing(sq
, colors
));
33 updateVariables(move) { }
34 unupdateVariables(move) { }
36 static get SEARCH_DEPTH() { return 4; }
38 static GenRandInitFen()
40 let minorPieces
= { "w": new Array(4), "b": new Array(4) };
41 let majorPieces
= { "w": new Array(4), "b": new Array(4) };
42 for (let c
of ["w","b"])
44 // Minor pieces first (on 2nd rank)
45 let positions
= _
.range(4);
47 // Get random squares for bishops
48 let randIndex
= 2 * _
.random(1);
49 let bishop1Pos
= positions
[randIndex
];
50 let randIndex_tmp
= 2 * _
.random(1) + 1;
51 let bishop2Pos
= positions
[randIndex_tmp
];
52 positions
.splice(Math
.max(randIndex
,randIndex_tmp
), 1);
53 positions
.splice(Math
.min(randIndex
,randIndex_tmp
), 1);
55 // Get random squares for knights
56 randIndex
= _
.random(1);
57 let knight1Pos
= positions
[randIndex
];
58 positions
.splice(randIndex
, 1);
59 let knight2Pos
= positions
[0];
61 minorPieces
[c
][bishop1Pos
] = 'b';
62 minorPieces
[c
][bishop2Pos
] = 'b';
63 minorPieces
[c
][knight1Pos
] = 'n';
64 minorPieces
[c
][knight2Pos
] = 'n';
66 // Major pieces then (on 1st rank)
67 positions
= _
.range(4);
69 // Get random square for queen
70 randIndex
= _
.random(3);
71 let queenPos
= positions
[randIndex
];
72 positions
.splice(randIndex
, 1);
74 // Rooks and king positions:
75 let rook1Pos
= positions
[0];
76 let kingPos
= positions
[1];
77 let rook2Pos
= positions
[2];
79 majorPieces
[c
][rook1Pos
] = 'r';
80 majorPieces
[c
][rook2Pos
] = 'r';
81 majorPieces
[c
][kingPos
] = 'k';
82 majorPieces
[c
][queenPos
] = 'q';
84 return majorPieces
["b"].join("") + "/" + minorPieces
["b"].join("") + "/4/4/4/4/" +
85 minorPieces
["w"].join("").toUpperCase() + "/" +
86 majorPieces
["w"].join("").toUpperCase() + " 0000"; //TODO: flags?!