X-Git-Url: https://git.auder.net/pieces/Checkered/cb.svg?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FPandemonium.js;h=bb614ec301030f9cc21f446a5a8248f5bb862977;hb=4cf77a102880d53b242a972b7eaa43e75ba9c338;hp=3997e2b0a8a282c3dc334a9f81030206adda5b1b;hpb=822d71d68d98ab35989cc41683c93ce9a0714ffe;p=vchess.git diff --git a/client/src/variants/Pandemonium.js b/client/src/variants/Pandemonium.js index 3997e2b0..bb614ec3 100644 --- a/client/src/variants/Pandemonium.js +++ b/client/src/variants/Pandemonium.js @@ -7,13 +7,15 @@ export class PandemoniumRules extends ChessRules { return Object.assign( {}, ChessRules.PawnSpecs, - { - threeSquares: true, - promotions: [V.GILDING] - } + { promotions: [V.GILDING] } ); } + loseOnRepetition() { + // If current side is under check: lost + return this.underCheck(this.turn); + } + static get GILDING() { return "g"; } @@ -147,20 +149,11 @@ export class PandemoniumRules extends ChessRules { return counts.join(""); } - setFlags(fenflags) { - // white a-castle, h-castle, king pos, then same for black. - this.castleFlags = { w: [-1, -1, -1], b: [-1, -1, -1] }; - for (let i = 0; i < 6; i++) { - this.castleFlags[i < 3 ? "w" : "b"][i % 3] = - V.ColumnToCoord(fenflags.charAt(i)); - } - } - static GenRandInitFen(randomness) { // No randomization here for now (but initial setup choice) return ( "rnbqkmcbnr/pppppppppp/91/91/91/91/91/91/PPPPPPPPPP/RNBQKMCBNR " + - "w 0 ajeaje - 00000000000000" + "w 0 ajaj - 00000000000000" ); // TODO later: randomization too --> 2 bishops, not next to each other. // then knights next to bishops. Then other pieces (...). @@ -333,7 +326,7 @@ export class PandemoniumRules extends ChessRules { return []; } // Normal move (after initial setup) - if (x >= V.size.x) return this.getReserveMoves(x, y); + if (x >= V.size.x) return this.getReserveMoves([x, y]); const p = this.getPiece(x, y); const sq = [x, y]; let moves = []; @@ -377,17 +370,17 @@ export class PandemoniumRules extends ChessRules { getPotentialPawnMoves([x, y]) { const color = this.turn; - const shiftX = V.PawnSpecs.directions[color]; + const shiftX = (color == 'w' ? -1 : 1); let moves = []; if (this.board[x + shiftX][y] == V.EMPTY) { this.addPawnMoves([x, y], [x + shiftX, y], moves); - if ((color == 'w' && x >= V.size.x - 3) || (color == 'b' && x <= 3)) { + if ((color == 'w' && x >= V.size.x - 3) || (color == 'b' && x <= 2)) { if (this.board[x + 2 * shiftX][y] == V.EMPTY) { moves.push(this.getBasicMove([x, y], [x + 2 * shiftX, y])); if ( ( - (color == 'w' && x >= V.size.x - 2) || - (color == 'b' && x <= 2) + (color == 'w' && x == V.size.x - 2) || + (color == 'b' && x == 1) ) && this.board[x + 3 * shiftX][y] == V.EMPTY @@ -478,25 +471,14 @@ export class PandemoniumRules extends ChessRules { if ( this.castleFlags[c][0] < V.size.y || this.castleFlags[c][1] < V.size.y - ) { - moves = moves.concat(this.getCastleMoves(sq)); - } - return moves; - } - - getCastleMoves([x, y]) { - const c = this.getColor(x, y); - if ( - ((c == 'w' && x == 9) || (c == 'b' && x == 0)) && - y == this.castleFlags[c][2] ) { const finalSquares = [ [1, 2], [7, 6] ]; - return super.getCastleMoves([x, y], finalSquares, false, [V.ROOK]); + moves = moves.concat(super.getCastleMoves(sq, finalSquares)); } - return []; + return moves; } isAttacked(sq, color) { @@ -542,7 +524,7 @@ export class PandemoniumRules extends ChessRules { const steps = V.steps[V.KNIGHT].concat(V.steps[V.ROOK]).concat(V.steps[V.BISHOP]); return ( - super.isAttackedBySlideNJump(sq, color, steps, V.SCEPTER, "oneStep") + super.isAttackedBySlideNJump(sq, color, V.SCEPTER, steps, "oneStep") ); } @@ -550,7 +532,7 @@ export class PandemoniumRules extends ChessRules { return ( super.isAttackedBySlideNJump(sq, color, V.steps[V.BISHOP], V.HORSE) || super.isAttackedBySlideNJump( - sq, color, V.steps[V.ROOK], V.HORSE, "oneStep") + sq, color, V.HORSE, V.steps[V.ROOK], "oneStep") ); } @@ -558,7 +540,7 @@ export class PandemoniumRules extends ChessRules { return ( super.isAttackedBySlideNJump(sq, color, V.steps[V.ROOK], V.DRAGON) || super.isAttackedBySlideNJump( - sq, color, V.steps[V.BISHOP], V.DRAGON, "oneStep") + sq, color, V.DRAGON, V.steps[V.BISHOP], "oneStep") ); } @@ -624,7 +606,8 @@ export class PandemoniumRules extends ChessRules { s: 'n', h: 'b', w: 'c', - a: 'm' + a: 'm', + g: 'p' }; } @@ -648,14 +631,6 @@ export class PandemoniumRules extends ChessRules { this.postPlay(move); } - updateCastleFlags(move, piece) { - if (piece == V.KING && move.appear.length == 2) { - // Castling (only move which disable flags) - this.castleFlags[move.appear[0].c][0] = 10; - this.castleFlags[move.appear[0].c][1] = 10; - } - } - postPlay(move) { if (move.vanish.length == 0 && move.appear.length == 0) return; super.postPlay(move); @@ -690,37 +665,6 @@ export class PandemoniumRules extends ChessRules { this.reserve[color][V.MayDecode(move.vanish[1].p)]--; } - getCurrentScore() { - const c = this.turn, - oppCol = V.GetOppCol(this.turn); - let facingKings = false; - if ( - this.kingPos[c][0] == this.kingPos[oppCol][0] || - this.kingPos[c][1] == this.kingPos[oppCol][1] - ) { - facingKings = true; - let step = [ - this.kingPos[oppCol][0] - this.kingPos[c][0], - this.kingPos[oppCol][1] - this.kingPos[c][1] - ]; - if (step[0] != 0) step[0] /= Math.abs(step[0]); - else step[1] /= Math.abs(step[1]); - let [x, y] = - [ this.kingPos[c][0] + step[0], this.kingPos[c][1] + step[1] ]; - while (x != this.kingPos[oppCol][0] || y != this.kingPos[oppCol][1]) { - if (this.board[x][y] != V.EMPTY) { - facingKings = false; - break; - } - x += step[0]; - y += step[1]; - } - } - if (facingKings) return (c == "w" ? "1-0" : "0-1"); - if (!this.atLeastOneMove()) return (c == "w" ? "0-1" : "1-0"); - return "*"; - } - static get VALUES() { return Object.assign( {},