1 // Standard rules on a 4x8 board with no pawns
2 class HalfRules
extends ChessRules
6 this.kingPos
= {'w':[-1,-1], 'b':[-1,-1]};
7 const fenParts
= fen
.split(" ");
8 const position
= fenParts
[0].split("/");
9 for (let i
=0; i
<position
.length
; i
++)
12 for (let j
=0; j
<position
[i
].length
; j
++)
14 switch (position
[i
].charAt(j
))
17 this.kingPos
['b'] = [i
,k
];
20 this.kingPos
['w'] = [i
,k
];
23 let num
= parseInt(position
[i
].charAt(j
));
30 // No pawns so no ep., but otherwise we must redefine play()
36 // No castling, hence no flags; but flags defined for compatibility
37 this.castleFlags
= { "w":[false,false], "b":[false,false] };
40 static get size() { return [4,8]; }
42 getPotentialKingMoves(sq
)
44 const V
= VariantRules
;
46 return this.getSlideNJumpMoves(sq
,
47 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), "oneStep");
50 isAttacked(sq
, colors
)
52 return (this.isAttackedByRook(sq
, colors
)
53 || this.isAttackedByKnight(sq
, colors
)
54 || this.isAttackedByBishop(sq
, colors
)
55 || this.isAttackedByQueen(sq
, colors
)
56 || this.isAttackedByKing(sq
, colors
));
61 // Just update king position
62 const piece
= this.getPiece(move.start
.x
,move.start
.y
);
63 const c
= this.getColor(move.start
.x
,move.start
.y
);
64 if (piece
== VariantRules
.KING
)
66 this.kingPos
[c
][0] = move.appear
[0].x
;
67 this.kingPos
[c
][1] = move.appear
[0].y
;
71 static GenRandInitFen()
73 let minorPieces
= { "w": new Array(4), "b": new Array(4) };
74 let majorPieces
= { "w": new Array(4), "b": new Array(4) };
75 for (let c
of ["w","b"])
77 // Minor pieces first (on 2nd rank)
78 let positions
= _
.range(4);
80 // Get random squares for bishops
81 let randIndex
= 2 * _
.random(1);
82 let bishop1Pos
= positions
[randIndex
];
83 let randIndex_tmp
= 2 * _
.random(1) + 1;
84 let bishop2Pos
= positions
[randIndex_tmp
];
85 positions
.splice(Math
.max(randIndex
,randIndex_tmp
), 1);
86 positions
.splice(Math
.min(randIndex
,randIndex_tmp
), 1);
88 // Get random squares for knights
89 randIndex
= _
.random(1);
90 let knight1Pos
= positions
[randIndex
];
91 positions
.splice(randIndex
, 1);
92 let knight2Pos
= positions
[0];
94 minorPieces
[c
][bishop1Pos
] = 'b';
95 minorPieces
[c
][bishop2Pos
] = 'b';
96 minorPieces
[c
][knight1Pos
] = 'n';
97 minorPieces
[c
][knight2Pos
] = 'n';
99 // Major pieces then (on 1st rank)
100 positions
= _
.range(4);
102 // Get random square for queen
103 randIndex
= _
.random(3);
104 let queenPos
= positions
[randIndex
];
105 positions
.splice(randIndex
, 1);
107 // Random square for king (no castle)
108 randIndex
= _
.random(2);
109 let kingPos
= positions
[randIndex
];
110 positions
.splice(randIndex
, 1);
112 // Rooks and king positions:
113 let rook1Pos
= positions
[0];
114 let rook2Pos
= positions
[1];
116 majorPieces
[c
][rook1Pos
] = 'r';
117 majorPieces
[c
][rook2Pos
] = 'r';
118 majorPieces
[c
][kingPos
] = 'k';
119 majorPieces
[c
][queenPos
] = 'q';
122 for (let i
=0; i
<4; i
++)
124 fen
+= majorPieces
["b"][i
] + minorPieces
["b"][i
] + "4" +
125 minorPieces
["w"][i
].toUpperCase() + majorPieces
["w"][i
].toUpperCase();
129 fen
+= " 0000"; //TODO: flags?!