- static GenRandInitFen() {
- let pieces = { w: new Array(8), b: new Array(8) };
- // Shuffle pieces on first and last rank
- for (let c of ["w", "b"]) {
- let positions = ArrayFun.range(8);
- // Get random squares for every piece, totally freely
-
- let randIndex = randInt(8);
- const bishop1Pos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- randIndex = randInt(7);
- const bishop2Pos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- randIndex = randInt(6);
- const knight1Pos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- randIndex = randInt(5);
- const knight2Pos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- randIndex = randInt(4);
- const queenPos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- randIndex = randInt(3);
- const kingPos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- randIndex = randInt(2);
- const rookPos = positions[randIndex];
- positions.splice(randIndex, 1);
- const immobilizerPos = positions[0];
-
- pieces[c][bishop1Pos] = "b";
- pieces[c][bishop2Pos] = "b";
- pieces[c][knight1Pos] = "n";
- pieces[c][knight2Pos] = "n";
- pieces[c][queenPos] = "q";
- pieces[c][kingPos] = "k";
- pieces[c][rookPos] = "r";
- pieces[c][immobilizerPos] = "m";
- }
- return (
- pieces["b"].join("") +
- "/pppppppp/8/8/8/8/PPPPPPPP/" +
- pieces["w"].join("").toUpperCase() +
- " w 0"
- );
- }
-