X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAntiking2.js;h=fa0bbcc45fcfe7042204317d9b77c867c16e44c0;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=3be41af550b5d4678279d2333a2075e5d32d8e98;hpb=c583ef1c1dfd19aee88b22c2175202fbdf4dc1c0;p=vchess.git diff --git a/client/src/variants/Antiking2.js b/client/src/variants/Antiking2.js index 3be41af5..fa0bbcc4 100644 --- a/client/src/variants/Antiking2.js +++ b/client/src/variants/Antiking2.js @@ -2,7 +2,8 @@ import { ChessRules } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; -export const VariantRules = class Antiking2Rules extends ChessRules { +export class Antiking2Rules extends ChessRules { + static get ANTIKING() { return "a"; } @@ -15,6 +16,19 @@ export const VariantRules = class Antiking2Rules extends ChessRules { return b[1] == "a" ? "Antiking/" + b : b; } + static IsGoodPosition(position) { + if (!ChessRules.IsGoodPosition(position)) return false; + const rows = position.split("/"); + // Check that exactly one antiking of each color is there: + let antikings = { 'a': 0, 'A': 0 }; + for (let row of rows) { + for (let i = 0; i < row.length; i++) + if (['A','a'].includes(row[i])) antikings[row[i]]++; + } + if (Object.values(antikings).some(v => v != 1)) return false; + return true; + } + setOtherVariables(fen) { super.setOtherVariables(fen); this.antikingPos = { w: [-1, -1], b: [-1, -1] }; @@ -30,7 +44,7 @@ export const VariantRules = class Antiking2Rules extends ChessRules { this.antikingPos["w"] = [i, k]; break; default: { - const num = parseInt(rows[i].charAt(j)); + const num = parseInt(rows[i].charAt(j), 10); if (!isNaN(num)) k += num - 1; } } @@ -65,10 +79,7 @@ export const VariantRules = class Antiking2Rules extends ChessRules { getPotentialAntikingMoves(sq) { // The antiking moves like a king (only captured colors differ) return this.getSlideNJumpMoves( - sq, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]), - "oneStep" - ); + sq, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1); } isAttacked(sq, color) { @@ -88,12 +99,7 @@ export const VariantRules = class Antiking2Rules extends ChessRules { // (Anti)King is not attacked by antiking if ([V.KING, V.ANTIKING].includes(this.getPiece(x, y))) return false; return this.isAttackedBySlideNJump( - [x, y], - color, - V.ANTIKING, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]), - "oneStep" - ); + [x, y], color, V.ANTIKING, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1); } underCheck(color) { @@ -104,7 +110,8 @@ export const VariantRules = class Antiking2Rules extends ChessRules { return res; } - getCheckSquares(color) { + getCheckSquares() { + const color = this.turn; let res = []; const oppCol = V.GetOppCol(color); if (this.isAttacked(this.kingPos[color], oppCol)) @@ -132,21 +139,6 @@ export const VariantRules = class Antiking2Rules extends ChessRules { this.antikingPos[c] = [move.start.x, move.start.y]; } - getCurrentScore() { - if (this.atLeastOneMove()) - return "*"; - - const color = this.turn; - const oppCol = V.GetOppCol(color); - if ( - !this.isAttacked(this.kingPos[color], oppCol) && - this.isAttacked(this.antikingPos[color], oppCol) - ) { - return "1/2"; - } - return color == "w" ? "0-1" : "1-0"; - } - static get VALUES() { return Object.assign( { a: 1000 }, @@ -154,15 +146,15 @@ export const VariantRules = class Antiking2Rules extends ChessRules { ); } - static GenRandInitFen(randomness) { - if (randomness == 0) + static GenRandInitFen(options) { + if (options.randomness == 0) return "rnbqkbnr/pppppppp/3A4/8/8/3a4/PPPPPPPP/RNBQKBNR w 0 ahah -"; let pieces = { w: new Array(8), b: new Array(8) }; let flags = ""; let antikingPos = { w: -1, b: -1 }; for (let c of ["w", "b"]) { - if (c == 'b' && randomness == 1) { + if (c == 'b' && options.randomness == 1) { pieces['b'] = pieces['w']; antikingPos['b'] = antikingPos['w']; flags += flags; @@ -233,4 +225,5 @@ export const VariantRules = class Antiking2Rules extends ChessRules { static get SEARCH_DEPTH() { return 2; } + };