X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAntiking1.js;h=7876da639b2a5d347e3af8c23601706292d3a1ac;hb=21704b041240cb440d03cfa64a90ed0be6f28415;hp=75cc14cb26fdcbfae9e7943d52f153dbfde2e80e;hpb=32f6285ee325a14286562a53baefc647201df2af;p=vchess.git diff --git a/client/src/variants/Antiking1.js b/client/src/variants/Antiking1.js index 75cc14cb..7876da63 100644 --- a/client/src/variants/Antiking1.js +++ b/client/src/variants/Antiking1.js @@ -4,6 +4,11 @@ import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; export class Antiking1Rules extends BerolinaRules { + + static get Options() { + return null; + } + static get PawnSpecs() { return Object.assign( {}, @@ -25,7 +30,20 @@ export class Antiking1Rules extends BerolinaRules { } getPpath(b) { - return b[1] == "a" ? "Antiking/" + b : b; + return (['a', 'p'].includes(b[1]) ? "Antiking/" : "") + 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) { @@ -43,7 +61,7 @@ export class Antiking1Rules extends BerolinaRules { 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; } } @@ -118,10 +136,7 @@ export class Antiking1Rules extends BerolinaRules { 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) { @@ -135,24 +150,14 @@ export class Antiking1Rules extends BerolinaRules { // Antiking is not attacked by king: if (this.getPiece(x, y) == V.ANTIKING) return false; return this.isAttackedBySlideNJump( - [x, y], - color, - V.KING, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]), - "oneStep" - ); + [x, y], color, V.KING, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1); } isAttackedByAntiking([x, y], color) { // (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) { @@ -163,7 +168,8 @@ export class Antiking1Rules extends BerolinaRules { return res; } - getCheckSquares(color) { + getCheckSquares() { + const color = this.turn; let res = []; const oppCol = V.GetOppCol(color); if (this.isAttacked(this.kingPos[color], oppCol)) @@ -192,21 +198,6 @@ export class Antiking1Rules extends BerolinaRules { 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 }, @@ -222,4 +213,5 @@ export class Antiking1Rules extends BerolinaRules { static get SEARCH_DEPTH() { return 2; } + };