- static GenRandInitFen() {
- let pieces = { w: new Array(8), b: new Array(8) };
- // Shuffle pieces + pawns on two first ranks
- for (let c of ["w", "b"]) {
- let positions = ArrayFun.range(16);
-
- // Get random squares for bishops
- let randIndex = 2 * randInt(8);
- const bishop1Pos = positions[randIndex];
- // The second bishop must be on a square of different color
- let randIndex_tmp = 2 * randInt(8) + 1;
- const bishop2Pos = positions[randIndex_tmp];
- // Remove chosen squares
- positions.splice(Math.max(randIndex, randIndex_tmp), 1);
- positions.splice(Math.min(randIndex, randIndex_tmp), 1);
-
- // Get random squares for knights
- randIndex = randInt(14);
- const knight1Pos = positions[randIndex];
- positions.splice(randIndex, 1);
- randIndex = randInt(13);
- const knight2Pos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- // Get random squares for rooks
- randIndex = randInt(12);
- const rook1Pos = positions[randIndex];
- positions.splice(randIndex, 1);
- randIndex = randInt(11);
- const rook2Pos = positions[randIndex];
- positions.splice(randIndex, 1);
+ isAttackedByJump([x, y], color, piece, steps) {
+ for (let step of steps) {
+ const sq = this.getSquareAfter([x,y], step);
+ if (
+ sq &&
+ this.getPiece(sq[0], sq[1]) == piece &&
+ this.getColor(sq[0], sq[1]) == color
+ ) {
+ return true;
+ }
+ }
+ return false;
+ }