X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAntiking1.js;h=781984f9c80e4118c5d79f7f186ec07abca49682;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=ed6173e0ececed934355a42848ac3fad9ed374f1;hpb=11482348f50058d235adb89bfc174a1da7c6abc4;p=vchess.git diff --git a/client/src/variants/Antiking1.js b/client/src/variants/Antiking1.js index ed6173e0..781984f9 100644 --- a/client/src/variants/Antiking1.js +++ b/client/src/variants/Antiking1.js @@ -1,10 +1,20 @@ import { ChessRules } from "@/base_rules"; +import { BerolinaRules } from "@/variants/Berolina"; import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; -export const VariantRules = class Antiking1Rules extends ChessRules { - static get HasEnpassant() { - return false; +export class Antiking1Rules extends BerolinaRules { + + static get Options() { + return null; + } + + static get PawnSpecs() { + return Object.assign( + {}, + ChessRules.PawnSpecs, + { twoSquares: false } + ); } static get HasCastle() { @@ -23,6 +33,19 @@ export const VariantRules = class Antiking1Rules 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] }; @@ -38,7 +61,7 @@ export const VariantRules = class Antiking1Rules 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; } } @@ -110,50 +133,10 @@ export const VariantRules = class Antiking1Rules extends ChessRules { return moves; } - getPotentialPawnMoves([x, y]) { - const color = this.turn; - let moves = []; - const [sizeX, sizeY] = [V.size.x, V.size.y]; - const shiftX = color == "w" ? -1 : 1; - const startRank = color == "w" ? sizeX - 2 : 1; - const lastRank = color == "w" ? 0 : sizeX - 1; - const finalPieces = - x + shiftX == lastRank ? [V.ROOK, V.KNIGHT, V.BISHOP, V.QUEEN] : [V.PAWN]; - - // One square diagonally - for (let shiftY of [-1, 1]) { - if (this.board[x + shiftX][y + shiftY] == V.EMPTY) { - for (let piece of finalPieces) { - moves.push( - this.getBasicMove([x, y], [x + shiftX, y + shiftY], { - c: color, - p: piece - }) - ); - } - } - } - // Capture - if ( - this.board[x + shiftX][y] != V.EMPTY && - this.canTake([x, y], [x + shiftX, y]) - ) { - for (let piece of finalPieces) - moves.push( - this.getBasicMove([x, y], [x + shiftX, y], { c: color, p: piece }) - ); - } - - return moves; - } - 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) { @@ -163,41 +146,18 @@ export const VariantRules = class Antiking1Rules extends ChessRules { ); } - isAttackedByPawn([x, y], color) { - let pawnShift = (color == "w" ? 1 : -1); - if (x + pawnShift >= 0 && x + pawnShift < V.size.x) { - if ( - this.getPiece(x + pawnShift, y) == V.PAWN && - this.getColor(x + pawnShift, y) == color - ) { - return true; - } - } - return false; - } - isAttackedByKing([x, y], color) { // 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) { @@ -208,7 +168,8 @@ export const VariantRules = class Antiking1Rules 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)) @@ -237,21 +198,6 @@ export const VariantRules = class Antiking1Rules 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 }, @@ -268,26 +214,4 @@ export const VariantRules = class Antiking1Rules extends ChessRules { return 2; } - // TODO: notation copied from Berolina - getNotation(move) { - const piece = this.getPiece(move.start.x, move.start.y); - if (piece == V.PAWN) { - // Pawn move - const finalSquare = V.CoordsToSquare(move.end); - let notation = ""; - if (move.vanish.length == 2) - //capture - notation = "Px" + finalSquare; - else { - // No capture: indicate the initial square for potential ambiguity - const startSquare = V.CoordsToSquare(move.start); - notation = startSquare + finalSquare; - } - if (move.appear[0].p != V.PAWN) - // Promotion - notation += "=" + move.appear[0].p.toUpperCase(); - return notation; - } - return super.getNotation(move); //all other pieces are orthodox - } };