X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FBaroque.js;h=246f51110dcdc2b6c54f56d8d4f44401882cf2be;hb=f35b9960e1c527fc400ebac85321bd4712459da3;hp=79fc73cec5c0f92ee8610823216a15845bf1ca7d;hpb=6808d7a16ec1e761c6a2dffec2281c96953e4d89;p=vchess.git diff --git a/client/src/variants/Baroque.js b/client/src/variants/Baroque.js index 79fc73ce..246f5111 100644 --- a/client/src/variants/Baroque.js +++ b/client/src/variants/Baroque.js @@ -11,17 +11,17 @@ export const VariantRules = class BaroqueRules extends ChessRules { return false; } - static getPpath(b) { + static get PIECES() { + return ChessRules.PIECES.concat([V.IMMOBILIZER]); + } + + getPpath(b) { if (b[1] == "m") //'m' for Immobilizer (I is too similar to 1) return "Baroque/" + b; return b; //usual piece } - static get PIECES() { - return ChessRules.PIECES.concat([V.IMMOBILIZER]); - } - // No castling, but checks, so keep track of kings setOtherVariables(fen) { this.kingPos = { w: [-1, -1], b: [-1, -1] }; @@ -72,7 +72,7 @@ export const VariantRules = class BaroqueRules extends ChessRules { ) { const oppPiece = this.getPiece(i, j); if (oppPiece == V.IMMOBILIZER) { - // Moving is impossible only if this immobilizer is not neutralized + // Moving is possible only if this immobilizer is neutralized for (let step2 of adjacentSteps) { const [i2, j2] = [i + step2[0], j + step2[1]]; if (i2 == x && j2 == y) continue; //skip initial piece! @@ -203,7 +203,6 @@ export const VariantRules = class BaroqueRules extends ChessRules { return moves; } - // Long-leaper getKnightCaptures(startSquare, byChameleon) { // Look in every direction for captures const steps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); @@ -271,6 +270,7 @@ export const VariantRules = class BaroqueRules extends ChessRules { return super.getPotentialQueenMoves(sq).concat(this.getKnightCaptures(sq)); } + // Chameleon getPotentialBishopMoves([x, y]) { let moves = super .getPotentialQueenMoves([x, y]) @@ -297,7 +297,6 @@ export const VariantRules = class BaroqueRules extends ChessRules { return moves; } - // Withdrawer addQueenCaptures(moves, byChameleon) { if (moves.length == 0) return; const [x, y] = [moves[0].start.x, moves[0].start.y]; @@ -341,6 +340,7 @@ export const VariantRules = class BaroqueRules extends ChessRules { }); } + // Withdrawer getPotentialQueenMoves(sq) { let moves = super.getPotentialQueenMoves(sq); this.addQueenCaptures(moves); @@ -474,8 +474,8 @@ export const VariantRules = class BaroqueRules extends ChessRules { } isAttackedByBishop([x, y], colors) { - // We cheat a little here: since this function is used exclusively for king, - // it's enough to check the immediate surrounding of the square. + // We cheat a little here: since this function is used exclusively for + // the king, it's enough to check the immediate surrounding of the square. const adjacentSteps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); for (let step of adjacentSteps) { const [i, j] = [x + step[0], y + step[1]]; @@ -512,6 +512,23 @@ export const VariantRules = class BaroqueRules extends ChessRules { return false; } + isAttackedByKing([x, y], colors) { + const steps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); + for (let step of steps) { + let rx = x + step[0], + ry = y + step[1]; + if ( + V.OnBoard(rx, ry) && + this.getPiece(rx, ry) === V.KING && + colors.includes(this.getColor(rx, ry)) && + !this.isImmobilized([rx, ry]) + ) { + return true; + } + } + return false; + } + static get VALUES() { return { p: 1, @@ -528,10 +545,19 @@ export const VariantRules = class BaroqueRules extends ChessRules { return 2; } - static GenRandInitFen() { + static GenRandInitFen(randomness) { + if (randomness == 0) + // Deterministic: + return "rnbqkbnrm/pppppppp/8/8/8/8/PPPPPPPP/MNBKQBNR w 0"; + let pieces = { w: new Array(8), b: new Array(8) }; // Shuffle pieces on first and last rank for (let c of ["w", "b"]) { + if (c == 'b' && randomness == 1) { + pieces['b'] = pieces['w']; + break; + } + let positions = ArrayFun.range(8); // Get random squares for every piece, totally freely @@ -591,7 +617,8 @@ export const VariantRules = class BaroqueRules extends ChessRules { } else if (move.appear[0].p == V.KING) notation = "K" + (move.vanish.length > 1 ? "x" : "") + finalSquare; else notation = move.appear[0].p.toUpperCase() + finalSquare; - if (move.vanish.length > 1 && move.appear[0].p != V.KING) notation += "X"; //capture mark (not describing what is captured...) + // Add a capture mark (not describing what is captured...): + if (move.vanish.length > 1 && move.appear[0].p != V.KING) notation += "X"; return notation; } };