X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FUpsidedown.js;h=538fb4a896f3f733990cdf86c3cd603d3be2ca4d;hp=bf3e37c46b950f6ec156669a3a6326841db8c114;hb=6808d7a16ec1e761c6a2dffec2281c96953e4d89;hpb=ae2c49bb0bbaac3953f63be5b720e9c6835f00b6 diff --git a/client/src/variants/Upsidedown.js b/client/src/variants/Upsidedown.js index bf3e37c4..538fb4a8 100644 --- a/client/src/variants/Upsidedown.js +++ b/client/src/variants/Upsidedown.js @@ -2,24 +2,27 @@ import { ChessRules } from "@/base_rules"; import { randInt } from "@/utils/alea"; import { ArrayFun } from "@/utils/array"; -export const VariantRules = class UpsidedownRules extends ChessRules -{ - static get HasFlags() { return false; } +export const VariantRules = class UpsidedownRules extends ChessRules { + static get HasFlags() { + return false; + } - static get HasEnpassant() { return false; } + static get HasEnpassant() { + return false; + } - getPotentialKingMoves(sq) - { + getPotentialKingMoves(sq) { // No castle - return this.getSlideNJumpMoves(sq, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep"); + return this.getSlideNJumpMoves( + sq, + V.steps[V.ROOK].concat(V.steps[V.BISHOP]), + "oneStep" + ); } - static GenRandInitFen() - { - let pieces = { "w": new Array(8), "b": new Array(8) }; - for (let c of ["w","b"]) - { + static GenRandInitFen() { + let pieces = { w: new Array(8), b: new Array(8) }; + for (let c of ["w", "b"]) { let positions = ArrayFun.range(8); let randIndex = randInt(8); @@ -28,12 +31,9 @@ export const VariantRules = class UpsidedownRules extends ChessRules // At least a knight must be next to the king: let knight1Pos = undefined; - if (kingPos == 0) - knight1Pos = 1; - else if (kingPos == V.size.y-1) - knight1Pos = V.size.y-2; - else - knight1Pos = kingPos + (Math.random() < 0.5 ? 1 : -1); + if (kingPos == 0) knight1Pos = 1; + else if (kingPos == V.size.y - 1) knight1Pos = V.size.y - 2; + else knight1Pos = kingPos + (Math.random() < 0.5 ? 1 : -1); // Search for knight1Pos index in positions and remove it const knight1Index = positions.indexOf(knight1Pos); positions.splice(knight1Index, 1); @@ -43,8 +43,8 @@ export const VariantRules = class UpsidedownRules extends ChessRules const bishop1Pos = positions[randIndex]; let randIndex_tmp = 2 * randInt(3) + 1; const bishop2Pos = positions[randIndex_tmp]; - positions.splice(Math.max(randIndex,randIndex_tmp), 1); - positions.splice(Math.min(randIndex,randIndex_tmp), 1); + positions.splice(Math.max(randIndex, randIndex_tmp), 1); + positions.splice(Math.min(randIndex, randIndex_tmp), 1); randIndex = randInt(4); const knight2Pos = positions[randIndex]; @@ -57,18 +57,20 @@ export const VariantRules = class UpsidedownRules extends ChessRules const rook1Pos = positions[0]; const rook2Pos = positions[1]; - 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'; + 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["w"].join("").toUpperCase() + + return ( + pieces["w"].join("").toUpperCase() + "/PPPPPPPP/8/8/8/8/pppppppp/" + pieces["b"].join("") + - " w 0"; //no castle, no en-passant + " w 0" + ); //no castle, no en-passant } -} +};