X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCrazyhouse.js;h=9cb076850f4f8d4b12dccd801bda1a1ef661a8fd;hp=0ee4bd3788bb5898a70a67008b0aef458fb55e93;hb=1221ac47836806efb287b0323b92957d9129c653;hpb=a6abf094c35a26019e47fea21302c4be32ff030b diff --git a/public/javascripts/variants/Crazyhouse.js b/public/javascripts/variants/Crazyhouse.js index 0ee4bd37..9cb07685 100644 --- a/public/javascripts/variants/Crazyhouse.js +++ b/public/javascripts/variants/Crazyhouse.js @@ -2,7 +2,7 @@ class CrazyhouseRules extends ChessRules { initVariables(fen) { - super.initVariables(); + super.initVariables(fen); // Also init reserves (used by the interface to show landing pieces) const V = VariantRules; this.reserve = @@ -24,59 +24,111 @@ class CrazyhouseRules extends ChessRules [V.QUEEN]: 0, } }; - // It may be a continuation: adjust numbers of pieces according to captures + rebirths - // TODO + // 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]--; + }); } // Used by the interface: - getReservePieces(color) + getReservePpath(color, index) { - return { - [color+V.PAWN]: this.reserve[color][V.PAWN], - [color+V.ROOK]: this.reserve[color][V.ROOK], - [color+V.KNIGHT]: this.reserve[color][V.KNIGHT], - [color+V.BISHOP]: this.reserve[color][V.BISHOP], - [color+V.QUEEN]: this.reserve[color][V.QUEEN], - }; + return color + VariantRules.RESERVE_PIECES[index]; } - getPotentialMovesFrom([x,y]) + // Put an ordering on reserve pieces + static get RESERVE_PIECES() { + const V = VariantRules; + return [V.PAWN,V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN]; + } + + getReserveMoves([x,y]) { - let moves = super.getPotentialMovesFrom([x,y]); - // Add landing moves: const color = this.turn; - Object.keys(this.reserve[color]).forEach(p => { - - moves.push(...); //concat... just appear - }); + const p = VariantRules.RESERVE_PIECES[y]; + if (this.reserve[color][p] == 0) + return []; + let moves = []; + for (let i=0; i special square !!! coordinates ?? - getPossibleMovesFrom(sq) + getPotentialMovesFrom([x,y]) { - // Assuming color is right (already checked) - return this.filterValid( this.getPotentialMovesFrom(sq) ); + const sizeX = VariantRules.size[0]; + if (x < sizeX) + return super.getPotentialMovesFrom([x,y]); + // Reserves, outside of board: x == sizeX + return this.getReserveMoves([x,y]); } - // TODO: add reserve moves getAllValidMoves() { - + let moves = super.getAllValidMoves(); + const color = this.turn; + const sizeX = VariantRules.size[0]; + for (let i=0; i 0) + return true; + } + return false; + } + return true; } - // TODO: update reserve updateVariables(move) { + super.updateVariables(move); + const color = this.turn; + if (move.vanish.length==2) + this.reserve[color][move.appear[0].p]++; + if (move.vanish.length==0) + this.reserve[color][move.appear[0].p]--; } + unupdateVariables(move) { + super.unupdateVariables(move); + const color = this.turn; + if (move.vanish.length==2) + this.reserve[color][move.appear[0].p]--; + if (move.vanish.length==0) + this.reserve[color][move.appear[0].p]++; } static get SEARCH_DEPTH() { return 2; } //high branching factor