X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FZen.js;h=7713b848cc051e54d07727be21cf16644e1b1e86;hb=26b8e4f7c71030d49e44fe1d89632ef91b886d67;hp=64587d204b9cdf3412789aaa6476a0d75aa4ca2a;hpb=0b7d99ecbb5dedc02cd96c457b5fc2962db9b297;p=vchess.git diff --git a/public/javascripts/variants/Zen.js b/public/javascripts/variants/Zen.js index 64587d20..7713b848 100644 --- a/public/javascripts/variants/Zen.js +++ b/public/javascripts/variants/Zen.js @@ -1,10 +1,7 @@ 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 getSlideNJumpMoves([x,y], steps, oneStep) @@ -55,7 +52,7 @@ class ZenRules extends ChessRules i += step[0]; j += step[1]; } - if (V.OnBoard(i,j) && this.getColor(i,j) == this.getOppCol(color) + if (V.OnBoard(i,j) && this.getColor(i,j) == V.GetOppCol(color) && this.getPiece(i,j) == asA) { // eat! @@ -100,7 +97,7 @@ class ZenRules extends ChessRules const firstRank = (color == 'w' ? sizeY-1 : 0); const lastRank = (color == "w" ? 0 : sizeY-1); - if (x+shift >= 0 && x+shift < sizeX && x+shift != lastRank) + if (x+shift != lastRank) { // Normal moves if (this.board[x+shift][y] == V.EMPTY) @@ -114,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 @@ -184,12 +180,10 @@ class ZenRules extends ChessRules } // Translate initial square (because pieces may fly unusually in this variant!) - const initialSquare = - String.fromCharCode(97 + move.start.y) + (V.size.x-move.start.x); + const initialSquare = V.CoordsToSquare(move.start); // Translate final square - const finalSquare = - String.fromCharCode(97 + move.end.y) + (V.size.x-move.end.x); + const finalSquare = V.CoordsToSquare(move.end); let notation = ""; const piece = this.getPiece(move.start.x, move.start.y); @@ -218,7 +212,9 @@ class ZenRules extends ChessRules return notation; } - static get VALUES() { //TODO: experimental + static get VALUES() + { + // TODO: experimental return { 'p': 1, 'r': 3, @@ -229,3 +225,5 @@ class ZenRules extends ChessRules } } } + +const VariantRules = ZenRules;