X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCrazyhouse.js;h=37337650c7bb94bf506cfd5fe8fab251eef8677f;hp=9558fe4bf1b5048b251964eaea34c3aa07c03ed5;hb=6752407b88b6d7678b9b19df4ffe1224d17625d7;hpb=44e87e497eeb05eb93164337da43d51a69a9c445 diff --git a/public/javascripts/variants/Crazyhouse.js b/public/javascripts/variants/Crazyhouse.js index 9558fe4b..37337650 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) @@ -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 + 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 +240,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; + } }