X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FRoyalrace.js;h=5232cc94a4616c028f1910fd760ff857a9c0fafd;hp=6f64d24fccd0a3852b726fc4797686363d558adb;hb=306dab5f2087a35669a114587c0415b31145665b;hpb=c3a86f018aba40e3926e3672c7cea87acc6d1e25 diff --git a/client/src/variants/Royalrace.js b/client/src/variants/Royalrace.js index 6f64d24f..5232cc94 100644 --- a/client/src/variants/Royalrace.js +++ b/client/src/variants/Royalrace.js @@ -2,7 +2,7 @@ import { ChessRules } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; import { randInt, shuffle } from "@/utils/alea"; -export const VariantRules = class RoyalraceRules extends ChessRules { +export class RoyalraceRules extends ChessRules { static get HasFlags() { return false; } @@ -19,10 +19,25 @@ export const VariantRules = class RoyalraceRules extends ChessRules { return { x: 11, y: 11 }; } - static GenRandInitFen() { + getPpath(b) { + return (b[1] == V.KNIGHT ? "Enpassant/" : "") + b; + } + + static GenRandInitFen(randomness) { + if (randomness == 0) + return "92/92/92/92/92/92/92/92/92/qrbnp1PNBRQ/krbnp1PNBRK w 0"; + let pieces = { w: new Array(10), b: new Array(10) }; // Shuffle pieces on first and second rank for (let c of ["w", "b"]) { + if (c == 'b' && randomness == 1) { + pieces['b'] = JSON.parse(JSON.stringify(pieces['w'])).reverse(); + pieces['b'] = + pieces['b'].splice(5,10).reverse().concat( + pieces['b'].splice(0,5).reverse()); + break; + } + // Reserve 4 and 5 which are pawns positions let positions = ArrayFun.range(10).filter(i => i != 4 && i != 5); @@ -81,14 +96,14 @@ export const VariantRules = class RoyalraceRules extends ChessRules { const whiteFen = pieces["w"].join("").toUpperCase(); const blackFen = pieces["b"].join(""); return ( - "11/11/11/11/11/11/11/11/11/" + - whiteFen.substr(5).split("").reverse().join("") + + "92/92/92/92/92/92/92/92/92/" + + blackFen.substr(5).split("").reverse().join("") + "1" + - blackFen.substr(5).split("").join("") + + whiteFen.substr(5).split("").join("") + "/" + - whiteFen.substr(0,5) + + blackFen.substr(0,5) + "1" + - blackFen.substr(0,5).split("").reverse().join("") + + whiteFen.substr(0,5).split("").reverse().join("") + " w 0" ); } @@ -122,15 +137,6 @@ export const VariantRules = class RoyalraceRules extends ChessRules { return this.getSlideNJumpMoves(sq, V.steps[V.KNIGHT]); } - // What are the king moves from square x,y ? - getPotentialKingMoves(sq) { - return this.getSlideNJumpMoves( - sq, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]), - "oneStep" - ); - } - filterValid(moves) { if (moves.length == 0) return []; const color = this.turn; @@ -144,16 +150,16 @@ export const VariantRules = class RoyalraceRules extends ChessRules { }); } - isAttackedByPawn([x, y], colors) { - const pawnShift = 1; - if (x + pawnShift < V.size.x) { - for (let c of colors) { + isAttackedByPawn([x, y], color) { + // Pawns can capture forward and backward: + for (let pawnShift of [-1, 1]) { + if (0 < x + pawnShift && x + pawnShift < V.size.x) { for (let i of [-1, 1]) { if ( y + i >= 0 && y + i < V.size.y && this.getPiece(x + pawnShift, y + i) == V.PAWN && - this.getColor(x + pawnShift, y + i) == c + this.getColor(x + pawnShift, y + i) == color ) { return true; } @@ -163,10 +169,10 @@ export const VariantRules = class RoyalraceRules extends ChessRules { return false; } - isAttackedByKnight(sq, colors) { + isAttackedByKnight(sq, color) { return this.isAttackedBySlideNJump( sq, - colors, + color, V.KNIGHT, V.steps[V.KNIGHT] ); @@ -178,8 +184,7 @@ export const VariantRules = class RoyalraceRules extends ChessRules { if (this.kingPos[color][0] == 0) // The opposing edge is reached! return color == "w" ? "1-0" : "0-1"; - if (this.atLeastOneMove()) - return "*"; + if (this.atLeastOneMove()) return "*"; // Stalemate (will probably never happen) return "1/2"; }