X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCrazyhouse.js;h=b297f1fb78cbe776d3abb3d65e18ce2ac9d9da37;hb=9234226104764b91df9d677fb360ad538b98510c;hp=9cb076850f4f8d4b12dccd801bda1a1ef661a8fd;hpb=1221ac47836806efb287b0323b92957d9129c653;p=vchess.git diff --git a/public/javascripts/variants/Crazyhouse.js b/public/javascripts/variants/Crazyhouse.js index 9cb07685..b297f1fb 100644 --- a/public/javascripts/variants/Crazyhouse.js +++ b/public/javascripts/variants/Crazyhouse.js @@ -24,13 +24,25 @@ 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]--; - }); + 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) + { + const sizeX = VariantRules.size[0]; + if (i >= sizeX) + return (i==sizeX ? "w" : "b"); + return this.board[i][j].charAt(0); + } + getPiece(i,j) + { + const sizeX = VariantRules.size[0]; + if (i >= sizeX) + return VariantRules.RESERVE_PIECES[j]; + return this.board[i][j].charAt(1); } // Used by the interface: @@ -39,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]; @@ -52,11 +64,13 @@ class CrazyhouseRules extends ChessRules if (this.reserve[color][p] == 0) return []; let moves = []; - for (let i=0; i= sizeX) + { + // Reserves, outside of board: x == sizeX(+1) + return this.getReserveMoves([x,y]); + } + // Standard moves + return super.getPotentialMovesFrom([x,y]); } getAllValidMoves() @@ -90,7 +110,7 @@ class CrazyhouseRules extends ChessRules const color = this.turn; const sizeX = VariantRules.size[0]; for (let i=0; i 0) return super.getNotation(move); // Rebirth: const piece = - (move.appear[0].p != VariantRules.PAWN ? move.appear.p.toUpperCase() : ""); + (move.appear[0].p != VariantRules.PAWN ? move.appear[0].p.toUpperCase() : ""); const finalSquare = 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; + } }