X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FLoser.js;h=6a322b9db35730a51a3ead31abbde0b55d868a9b;hb=2eef6db6cdce30fe785e601b88858c7fc743eee8;hp=da4999fe61bfeab78f92f7c49cdedf6a747b1a38;hpb=32cfcea44bf00b0c6c4d172cca715823076ff490;p=vchess.git diff --git a/public/javascripts/variants/Loser.js b/public/javascripts/variants/Loser.js index da4999fe..6a322b9d 100644 --- a/public/javascripts/variants/Loser.js +++ b/public/javascripts/variants/Loser.js @@ -142,4 +142,60 @@ class LoserRules extends ChessRules { return - super.evalPosition(); //better with less material } + + 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 = _.range(8); + + // Get random squares for bishops + let randIndex = 2 * _.random(3); + let bishop1Pos = positions[randIndex]; + // The second bishop must be on a square of different color + let randIndex_tmp = 2 * _.random(3) + 1; + let 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 = _.random(5); + let knight1Pos = positions[randIndex]; + positions.splice(randIndex, 1); + randIndex = _.random(4); + let knight2Pos = positions[randIndex]; + positions.splice(randIndex, 1); + + // Get random square for queen + randIndex = _.random(3); + let queenPos = positions[randIndex]; + positions.splice(randIndex, 1); + + // Random square for king (no castle) + randIndex = _.random(2); + let kingPos = positions[randIndex]; + positions.splice(randIndex, 1); + + // Rooks positions are now fixed + let rook1Pos = positions[0]; + let rook2Pos = positions[1]; + + // Finally put the shuffled pieces in the board array + pieces[c][rook1Pos] = 'r'; + pieces[c][knight1Pos] = 'n'; + pieces[c][bishop1Pos] = 'b'; + pieces[c][queenPos] = 'q'; + pieces[c][kingPos] = 'k'; + pieces[c][bishop2Pos] = 'b'; + pieces[c][knight2Pos] = 'n'; + pieces[c][rook2Pos] = 'r'; + } + return pieces["b"].join("") + + "/pppppppp/8/8/8/8/PPPPPPPP/" + + pieces["w"].join("").toUpperCase() + + " 0000"; //add flags (TODO?!) + } }