X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FGrand.js;h=cafdadabb4d65d483fbafba76760fa4e7c6b6f42;hb=7931e479adf93c87771ded1892a0873af72ae46d;hp=f4e325dcbf12da055fec2b468e800d26d77e8a45;hpb=3c09dc498791ac478679bf2f42f441342c4fa22c;p=vchess.git diff --git a/public/javascripts/variants/Grand.js b/public/javascripts/variants/Grand.js index f4e325dc..cafdadab 100644 --- a/public/javascripts/variants/Grand.js +++ b/public/javascripts/variants/Grand.js @@ -1,9 +1,9 @@ -//https://www.chessvariants.com/large.dir/freeling.html +// NOTE: initial setup differs from the original; see +// https://www.chessvariants.com/large.dir/freeling.html class GrandRules extends ChessRules { static getPpath(b) { - const V = VariantRules; return ([V.MARSHALL,V.CARDINAL].includes(b[1]) ? "Grand/" : "") + b; } @@ -13,16 +13,20 @@ class GrandRules extends ChessRules this.captures = { "w": {}, "b": {} }; //for promotions } - static get size() { return [10,10]; } + static get size() { return {x:10,y:10}; } static get MARSHALL() { return 'm'; } //rook+knight static get CARDINAL() { return 'c'; } //bishop+knight + static get PIECES() { + return ChessRules.PIECES.concat([V.MARSHALL,V.CARDINAL]); + } + // En-passant after 2-sq or 3-sq jumps getEpSquare(move) { const [sx,sy,ex] = [move.start.x,move.start.y,move.end.x]; - if (this.getPiece(sx,sy) == VariantRules.PAWN && Math.abs(sx - ex) >= 2) + if (this.getPiece(sx,sy) == V.PAWN && Math.abs(sx - ex) >= 2) { const step = (ex-sx) / Math.abs(ex-sx); let res = [{ @@ -45,9 +49,9 @@ class GrandRules extends ChessRules { switch (this.getPiece(x,y)) { - case VariantRules.MARSHALL: + case V.MARSHALL: return this.getPotentialMarshallMoves([x,y]); - case VariantRules.CARDINAL: + case V.CARDINAL: return this.getPotentialCardinalMoves([x,y]); default: return super.getPotentialMovesFrom([x,y]) @@ -60,11 +64,10 @@ class GrandRules extends ChessRules { const color = this.turn; let moves = []; - const V = VariantRules; - const [sizeX,sizeY] = VariantRules.size; + const [sizeX,sizeY] = [V.size.x,V.size.y]; const shift = (color == "w" ? -1 : 1); - const startRanks = (color == "w" ? [sizeY-2,sizeY-3] : [1,2]); - const lastRanks = (color == "w" ? [0,1,2] : [sizeY-1,sizeY-2,sizeY-3]); + const startRanks = (color == "w" ? [sizeX-2,sizeX-3] : [1,2]); + const lastRanks = (color == "w" ? [0,1,2] : [sizeX-1,sizeX-2,sizeX-3]); if (x+shift >= 0 && x+shift < sizeX && x+shift != lastRanks[0]) { @@ -76,7 +79,7 @@ class GrandRules extends ChessRules { // Two squares jump moves.push(this.getBasicMove([x,y], [x+2*shift,y])); - if (x == startRanks[0] && this.board[x+2*shift][y] == V.EMPTY) + if (x == startRanks[0] && this.board[x+3*shift][y] == V.EMPTY) { // 3-squares jump moves.push(this.getBasicMove([x,y], [x+3*shift,y])); @@ -84,16 +87,22 @@ class GrandRules extends ChessRules } } // Captures - if (y>0 && this.canTake([x,y], [x+shift,y-1]) && this.board[x+shift][y-1] != V.EMPTY) + if (y>0 && this.canTake([x,y], [x+shift,y-1]) + && this.board[x+shift][y-1] != V.EMPTY) + { moves.push(this.getBasicMove([x,y], [x+shift,y-1])); - if (y { if (!this.captures[color][p] || this.captures[color][p]==0) return; @@ -101,10 +110,16 @@ class GrandRules extends ChessRules if (this.board[x+shift][y] == V.EMPTY) moves.push(this.getBasicMove([x,y], [x+shift,y], {c:color,p:p})); // Captures - if (y>0 && this.canTake([x,y], [x+shift,y-1]) && this.board[x+shift][y-1] != V.EMPTY) + if (y>0 && this.canTake([x,y], [x+shift,y-1]) + && this.board[x+shift][y-1] != V.EMPTY) + { moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:color,p:p})); - if (y