-
- let positions = ArrayFun.range(8);
-
- // Get random squares for bishop: if black, pick a different color
- // than where the white one stands.
- let randIndex =
- c == 'w'
- ? randInt(8)
- : 2 * randInt(4) + (1 - whiteBishopPos % 2);
- if (c == 'w') whiteBishopPos = randIndex;
- const bishopPos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- randIndex = randInt(7);
- const knightPos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- randIndex = randInt(6);
- const queenPos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- randIndex = randInt(5);
- const amazonPos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- randIndex = randInt(4);
- const princessPos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- // Rook, empress and king positions are now almost fixed,
- // only the ordering rook->empress or empress->rook must be decided.
- let rookPos = positions[0];
- let empressPos = positions[2];
- const kingPos = positions[1];
- flags += V.CoordToColumn(rookPos) + V.CoordToColumn(empressPos);
- if (Math.random() < 0.5) [rookPos, empressPos] = [empressPos, rookPos];
-
- pieces[c][rookPos] = "r";
- pieces[c][knightPos] = "n";
- pieces[c][bishopPos] = "b";
- pieces[c][queenPos] = "q";
- pieces[c][kingPos] = "k";
- pieces[c][amazonPos] = "a";
- pieces[c][princessPos] = "s";
- pieces[c][empressPos] = "e";