X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCrazyhouse.js;h=b297f1fb78cbe776d3abb3d65e18ce2ac9d9da37;hb=9234226104764b91df9d677fb360ad538b98510c;hp=9558fe4bf1b5048b251964eaea34c3aa07c03ed5;hpb=5c42c64e0b43ad4d687c58a6b7e9b9ac5d212e17;p=vchess.git diff --git a/public/javascripts/variants/Crazyhouse.js b/public/javascripts/variants/Crazyhouse.js index 9558fe4b..b297f1fb 100644 --- a/public/javascripts/variants/Crazyhouse.js +++ b/public/javascripts/variants/Crazyhouse.js @@ -24,14 +24,10 @@ class CrazyhouseRules extends ChessRules [V.QUEEN]: 0, } }; - // May be a continuation: adjust numbers of pieces according to captures + rebirths - this.moves.forEach(m => { - if (m.vanish.length == 2) - this.reserve[m.appear[0].c][m.vanish[1].p]++; - else if (m.vanish.length == 0) - this.reserve[m.appear[0].c][m.appear[0].p]--; - }); - // TODO: keep track of promoted pawns ==> give a pawn if captured. + const [sizeX,sizeY] = VariantRules.size; + this.promoted = doubleArray(sizeX, sizeY, false); + // May be a continuation: adjust numbers of pieces in reserve + promoted pieces + this.moves.forEach(m => { this.updateVariables(m); }); } getColor(i,j) @@ -55,7 +51,7 @@ class CrazyhouseRules extends ChessRules return color + VariantRules.RESERVE_PIECES[index]; } - // Put an ordering on reserve pieces + // Ordering on reserve pieces static get RESERVE_PIECES() { const V = VariantRules; return [V.PAWN,V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN]; @@ -86,7 +82,7 @@ class CrazyhouseRules extends ChessRules }) ], vanish: [], - start: {x:sizeX, y:y}, //a bit artificial... + start: {x:x, y:y}, //a bit artificial... end: {x:i, y:j} }); moves.push(mv); @@ -99,10 +95,13 @@ class CrazyhouseRules extends ChessRules getPotentialMovesFrom([x,y]) { const sizeX = VariantRules.size[0]; - if (x < sizeX) - return super.getPotentialMovesFrom([x,y]); - // Reserves, outside of board: x == sizeX - return this.getReserveMoves([x,y]); + if (x >= sizeX) + { + // Reserves, outside of board: x == sizeX(+1) + return this.getReserveMoves([x,y]); + } + // Standard moves + return super.getPotentialMovesFrom([x,y]); } getAllValidMoves() @@ -111,7 +110,7 @@ class CrazyhouseRules extends ChessRules const color = this.turn; const sizeX = VariantRules.size[0]; for (let i=0; i 0) @@ -165,4 +201,13 @@ class CrazyhouseRules extends ChessRules String.fromCharCode(97 + move.end.y) + (VariantRules.size[0]-move.end.x); return piece + "@" + finalSquare; } + + getLongNotation(move) + { + if (move.vanish.length > 0) + return super.getLongNotation(move); + const finalSquare = + String.fromCharCode(97 + move.end.y) + (VariantRules.size[0]-move.end.x); + return "@" + finalSquare; + } }