X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FAntiking.js;h=0d342713e7c4889bbbe850c63bed7e25e3abe144;hb=643479f8d7c3622b57fc49c4f10d9950793ebf4f;hp=53e5518804012813fca917a7e4e852039dbab24f;hpb=6037f1d82232e62b669018b548845baf480f9e64;p=vchess.git diff --git a/public/javascripts/variants/Antiking.js b/public/javascripts/variants/Antiking.js index 53e55188..0d342713 100644 --- a/public/javascripts/variants/Antiking.js +++ b/public/javascripts/variants/Antiking.js @@ -1,24 +1,28 @@ class AntikingRules extends ChessRules { - // Path to pieces static getPpath(b) { return b[1]=='a' ? "Antiking/"+b : b; } static get ANTIKING() { return 'a'; } - - initVariables(fen) + + static get PIECES() + { + return ChessRules.PIECES.concat([V.ANTIKING]); + } + + setOtherVariables(fen) { - super.initVariables(fen); + super.setOtherVariables(fen); this.antikingPos = {'w':[-1,-1], 'b':[-1,-1]}; - const position = fen.split(" ")[0].split("/"); - for (let i=0; i0?antikingPos:"") + "A" + (antikingPos<7?7-antikingPos:""); - randFen = randFen.replace("pppppppp/8", ranks23); - // White side - antikingPos = _.random(7); - ranks23 = (antikingPos>0?antikingPos:"") + "a" + (antikingPos<7?7-antikingPos:"") + "/PPPPPPPP"; - randFen = randFen.replace("8/PPPPPPPP", ranks23); - return randFen; + let pieces = { "w": new Array(8), "b": new Array(8) }; + let antikingPos = { "w": -1, "b": -1 }; + for (let c of ["w","b"]) + { + let positions = _.range(8); + + // Get random squares for bishops, but avoid corners; because, + // if an antiking blocks a cornered bishop, it can never be checkmated + let randIndex = 2 * _.random(1,3); + const bishop1Pos = positions[randIndex]; + let randIndex_tmp = 2 * _.random(2) + 1; + const bishop2Pos = positions[randIndex_tmp]; + positions.splice(Math.max(randIndex,randIndex_tmp), 1); + positions.splice(Math.min(randIndex,randIndex_tmp), 1); + + randIndex = _.random(5); + const knight1Pos = positions[randIndex]; + positions.splice(randIndex, 1); + randIndex = _.random(4); + const knight2Pos = positions[randIndex]; + positions.splice(randIndex, 1); + + randIndex = _.random(3); + const queenPos = positions[randIndex]; + positions.splice(randIndex, 1); + + const rook1Pos = positions[0]; + const kingPos = positions[1]; + const rook2Pos = positions[2]; + + // Random squares for antikings + antikingPos[c] = _.random(7); + + 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'; + } + const ranks23_black = "pppppppp/" + (antikingPos["w"]>0?antikingPos["w"]:"") + + "A" + (antikingPos["w"]<7?7-antikingPos["w"]:""); + const ranks23_white = (antikingPos["b"]>0?antikingPos["b"]:"") + "a" + + (antikingPos["b"]<7?7-antikingPos["b"]:"") + "/PPPPPPPP"; + return pieces["b"].join("") + "/" + ranks23_black + + "/8/8/" + + ranks23_white + "/" + pieces["w"].join("").toUpperCase() + + " w 1111"; } } + +const VariantRules = AntikingRules;