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);

      // Get random square for queen
      randIndex = randInt(10);
      const queenPos = positions[randIndex];
      positions.splice(randIndex, 1);

      // Get random square for king
      randIndex = randInt(9);
      const kingPos = positions[randIndex];
      positions.splice(randIndex, 1);

      // Pawns position are all remaining slots:
      for (let p of positions)
        pieces[c][p] = "s";

      // Finally put the shuffled pieces in the board array
      pieces[c][rook1Pos] = "u";
      pieces[c][knight1Pos] = "o";
      pieces[c][bishop1Pos] = "c";
      pieces[c][queenPos] = "t";
      pieces[c][kingPos] = "l";
      pieces[c][bishop2Pos] = "c";
      pieces[c][knight2Pos] = "o";
      pieces[c][rook2Pos] = "u";
    }
    let upFen = pieces["b"].join("");
    upFen = upFen.substr(0,8) + "/" +
      upFen.substr(8).split("").reverse().join("");
    let downFen = pieces["b"].join("").toUpperCase();
    downFen = downFen.substr(0,8) + "/" +
      downFen.substr(8).split("").reverse().join("");
    return upFen + "/8/8/8/8/" + downFen + " w 0";
  }
// Ignore randomness here: placement is always random asymmetric
Ignore randomness here: placement is always random asymmetric
Ignore randomness here : placement is always random asymmetric
static GenRandInitFen() {
    let pieces = { w: new Array(8), b: new Array(8) };
    for (let c of ["w", "b"]) {
      let positions = ArrayFun.range(16);
      let randIndex = 2 * randInt(8);
      const bishop1Pos = positions[randIndex];
      let randIndex_tmp = 2 * randInt(8) + 1;
      const bishop2Pos = positions[randIndex_tmp];
      positions.splice(Math.max(randIndex, randIndex_tmp), 1);
      positions.splice(Math.min(randIndex, randIndex_tmp), 1);
      randIndex = randInt(14);
      const knight1Pos = positions[randIndex];
      positions.splice(randIndex, 1);
      randIndex = randInt(13);
      const knight2Pos = positions[randIndex];
      positions.splice(randIndex, 1);
      randIndex = randInt(12);
      const rook1Pos = positions[randIndex];
      positions.splice(randIndex, 1);
      randIndex = randInt(11);
      const rook2Pos = positions[randIndex];
      positions.splice(randIndex, 1);
      randIndex = randInt(10);
      const queenPos = positions[randIndex];
      positions.splice(randIndex, 1);
      randIndex = randInt(9);
      const kingPos = positions[randIndex];
      positions.splice(randIndex, 1);
      for (let p of positions)
        pieces[c][p] = "s";
      pieces[c][rook1Pos] = "u";
      pieces[c][knight1Pos] = "o";
      pieces[c][bishop1Pos] = "c";
      pieces[c][queenPos] = "t";
      pieces[c][kingPos] = "l";
      pieces[c][bishop2Pos] = "c";
      pieces[c][knight2Pos] = "o";
      pieces[c][rook2Pos] = "u";
    }
    let upFen = pieces["b"].join("");
    upFen = upFen.substr(0,8) + "/" +
      upFen.substr(8).split("").reverse().join("");
    let downFen = pieces["b"].join("").toUpperCase();
    downFen = downFen.substr(0,8) + "/" +
      downFen.substr(8).split("").reverse().join("");
    return upFen + "/8/8/8/8/" + downFen + " w 0";
  }
static GenRandInitFen ( ) { let pieces = { w : new Array ( 8 ) , b : new Array ( 8 ) } ; for ( let c of [ "w" , "b" ] ) { let positions = ArrayFun . range ( 16 ) ; let randIndex = 2 * randInt ( 8 ) ; const bishop1Pos = positions [ randIndex ] ; let randIndex_tmp = 2 * randInt ( 8 ) + 1 ; const bishop2Pos = positions [ randIndex_tmp ] ; positions . splice ( Math . max ( randIndex , randIndex_tmp ) , 1 ) ; positions . splice ( Math . min ( randIndex , randIndex_tmp ) , 1 ) ; randIndex = randInt ( 14 ) ; const knight1Pos = positions [ randIndex ] ; positions . splice ( randIndex , 1 ) ; randIndex = randInt ( 13 ) ; const knight2Pos = positions [ randIndex ] ; positions . splice ( randIndex , 1 ) ; randIndex = randInt ( 12 ) ; const rook1Pos = positions [ randIndex ] ; positions . splice ( randIndex , 1 ) ; randIndex = randInt ( 11 ) ; const rook2Pos = positions [ randIndex ] ; positions . splice ( randIndex , 1 ) ; randIndex = randInt ( 10 ) ; const queenPos = positions [ randIndex ] ; positions . splice ( randIndex , 1 ) ; randIndex = randInt ( 9 ) ; const kingPos = positions [ randIndex ] ; positions . splice ( randIndex , 1 ) ; for ( let p of positions ) pieces [ c ] [ p ] = "s" ; pieces [ c ] [ rook1Pos ] = "u" ; pieces [ c ] [ knight1Pos ] = "o" ; pieces [ c ] [ bishop1Pos ] = "c" ; pieces [ c ] [ queenPos ] = "t" ; pieces [ c ] [ kingPos ] = "l" ; pieces [ c ] [ bishop2Pos ] = "c" ; pieces [ c ] [ knight2Pos ] = "o" ; pieces [ c ] [ rook2Pos ] = "u" ; } let upFen = pieces [ "b" ] . join ( "" ) ; upFen = upFen . substr ( 0 , 8 ) + "/" + upFen . substr ( 8 ) . split ( "" ) . reverse ( ) . join ( "" ) ; let downFen = pieces [ "b" ] . join ( "" ) . toUpperCase ( ) ; downFen = downFen . substr ( 0 , 8 ) + "/" + downFen . substr ( 8 ) . split ( "" ) . reverse ( ) . join ( "" ) ; return upFen + "/8/8/8/8/" + downFen + " w 0" ; }
Ignore randomness here: placement is always random asymmetric
Ignore randomness here : placement is always random asymmetric
// Shuffle pieces + pawns on two first ranks // Get random squares for bishops // The second bishop must be on a square of different color // Remove chosen squares // Get random squares for knights // Get random squares for rooks // Get random square for queen // Get random square for king // Pawns position are all remaining slots: // Finally put the shuffled pieces in the board array