X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FZen.js;h=0675fbc94973940143447c6ca406b396f66bb56c;hb=69f3d8014e594ef949792d04d97b8286e9c2c268;hp=b7f229c3c19ee083a1db1b952c0153dc179817b8;hpb=46302e643947a66a5593a8eb1140d314effcea95;p=vchess.git diff --git a/public/javascripts/variants/Zen.js b/public/javascripts/variants/Zen.js index b7f229c3..0675fbc9 100644 --- a/public/javascripts/variants/Zen.js +++ b/public/javascripts/variants/Zen.js @@ -1,25 +1,20 @@ class ZenRules extends ChessRules { // NOTE: enPassant, if enabled, would need to redefine carefully getEpSquare - getEpSquare(move) - { - return undefined; - } + static get HasEnpassant() { return false; } - // TODO: some duplicated code in 2 next functions + // TODO(?): some duplicated code in 2 next functions getSlideNJumpMoves([x,y], steps, oneStep) { const color = this.getColor(x,y); - var moves = []; - let [sizeX,sizeY] = VariantRules.size; + let moves = []; outerLoop: - for (var loop=0; loop=0 && i=0 && j=0 && i=0 && j=0 && i=0 && j= 0 && x+shift < sizeX && x+shift != lastRank) + let moves = []; + const [sizeX,sizeY] = [V.size.x,V.size.y]; + const shift = (color == 'w' ? -1 : 1); + const startRank = (color == 'w' ? sizeY-2 : 1); + const firstRank = (color == 'w' ? sizeY-1 : 0); + const lastRank = (color == "w" ? 0 : sizeY-1); + + if (x+shift != lastRank) { // Normal moves if (this.board[x+shift][y] == V.EMPTY) @@ -129,9 +111,8 @@ class ZenRules extends ChessRules } } - if (x+shift == lastRank) + else //promotion { - // Promotion let promotionPieces = [V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN]; promotionPieces.forEach(p => { // Normal move @@ -150,28 +131,29 @@ class ZenRules extends ChessRules getPotentialRookMoves(sq) { - let noCaptures = this.getSlideNJumpMoves(sq, VariantRules.steps[VariantRules.ROOK]); + let noCaptures = this.getSlideNJumpMoves(sq, V.steps[V.ROOK]); let captures = this.findCaptures(sq); return noCaptures.concat(captures); } getPotentialKnightMoves(sq) { - let noCaptures = this.getSlideNJumpMoves(sq, VariantRules.steps[VariantRules.KNIGHT], "oneStep"); + let noCaptures = this.getSlideNJumpMoves(sq, V.steps[V.KNIGHT], "oneStep"); let captures = this.findCaptures(sq); return noCaptures.concat(captures); } getPotentialBishopMoves(sq) { - let noCaptures = this.getSlideNJumpMoves(sq, VariantRules.steps[VariantRules.BISHOP]); + let noCaptures = this.getSlideNJumpMoves(sq, V.steps[V.BISHOP]); let captures = this.findCaptures(sq); return noCaptures.concat(captures); } getPotentialQueenMoves(sq) { - let noCaptures = this.getSlideNJumpMoves(sq, VariantRules.steps[VariantRules.QUEEN]); + let noCaptures = this.getSlideNJumpMoves( + sq, V.steps[V.ROOK].concat(V.steps[V.BISHOP])); let captures = this.findCaptures(sq); return noCaptures.concat(captures); } @@ -179,7 +161,8 @@ class ZenRules extends ChessRules getPotentialKingMoves(sq) { // Initialize with normal moves - let noCaptures = this.getSlideNJumpMoves(sq, VariantRules.steps[VariantRules.QUEEN], "oneStep"); + let noCaptures = this.getSlideNJumpMoves(sq, + V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep"); let captures = this.findCaptures(sq); return noCaptures.concat(captures).concat(this.getCastleMoves(sq)); } @@ -197,16 +180,14 @@ class ZenRules extends ChessRules } // Translate initial square (because pieces may fly unusually in this variant!) - let initialSquare = - String.fromCharCode(97 + move.start.y) + (VariantRules.size[0]-move.start.x); + const initialSquare = V.CoordsToSquare(move.start); // Translate final square - let finalSquare = - String.fromCharCode(97 + move.end.y) + (VariantRules.size[0]-move.end.x); + const finalSquare = V.CoordsToSquare(move.end); let notation = ""; - let piece = this.getPiece(move.start.x, move.start.y); - if (piece == VariantRules.PAWN) + const piece = this.getPiece(move.start.x, move.start.y); + if (piece == V.PAWN) { // pawn move (TODO: enPassant indication) if (move.vanish.length > 1) @@ -231,7 +212,9 @@ class ZenRules extends ChessRules return notation; } - static get VALUES() { //TODO: experimental + static get VALUES() + { + // TODO: experimental return { 'p': 1, 'r': 3, @@ -242,3 +225,5 @@ class ZenRules extends ChessRules } } } + +const VariantRules = ZenRules;