X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAlice.js;h=16ccb84deec962d562d226119215a36f41df9a68;hb=665a8844aa49422692f184703944978510106aa7;hp=15e629a4024f9e42c30d3918e6f16bbdb080d213;hpb=294fe29f8da44f47df48a21b17f4822ecf821890;p=vchess.git diff --git a/client/src/variants/Alice.js b/client/src/variants/Alice.js index 15e629a4..16ccb84d 100644 --- a/client/src/variants/Alice.js +++ b/client/src/variants/Alice.js @@ -5,6 +5,7 @@ import { ArrayFun } from "@/utils/array"; // TODO? atLeastOneMove() would be more efficient if rewritten here // (less sideBoard computations) export class AliceRules extends ChessRules { + static get ALICE_PIECES() { return { s: "p", @@ -60,6 +61,30 @@ export class AliceRules extends ChessRules { return undefined; //default } + // king can be l or L (on the other mirror side) + static IsGoodPosition(position) { + if (position.length == 0) return false; + const rows = position.split("/"); + if (rows.length != V.size.x) return false; + let kings = { "k": 0, "K": 0, 'l': 0, 'L': 0 }; + for (let row of rows) { + let sumElts = 0; + for (let i = 0; i < row.length; i++) { + if (['K','k','L','l'].includes(row[i])) kings[row[i]]++; + if (V.PIECES.includes(row[i].toLowerCase())) sumElts++; + else { + const num = parseInt(row[i], 10); + if (isNaN(num)) return false; + sumElts += num; + } + } + if (sumElts != V.size.y) return false; + } + if (kings['k'] + kings['l'] != 1 || kings['K'] + kings['L'] != 1) + return false; + return true; + } + setOtherVariables(fen) { super.setOtherVariables(fen); const rows = V.ParseFen(fen).position.split("/"); @@ -77,7 +102,7 @@ export class AliceRules extends ChessRules { this.kingPos["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; } } @@ -337,10 +362,10 @@ export class AliceRules extends ChessRules { // Piece or pawn movement let notation = piece.toUpperCase() + pawnMark + captureMark + finalSquare; - if (["s", "p"].includes(piece) && !["s", "p"].includes(move.appear[0].p)) { + if (["s", "p"].includes(piece) && !["s", "p"].includes(move.appear[0].p)) // Promotion notation += "=" + move.appear[0].p.toUpperCase(); - } return notation; } + };