X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAlice.js;h=61fcd01527c9e4b4fd8f2d2da5e8d5f3360eddb0;hb=c3ff3a0c807d97c0311a06491318fe02440266db;hp=15e629a4024f9e42c30d3918e6f16bbdb080d213;hpb=294fe29f8da44f47df48a21b17f4822ecf821890;p=vchess.git diff --git a/client/src/variants/Alice.js b/client/src/variants/Alice.js index 15e629a4..61fcd015 100644 --- a/client/src/variants/Alice.js +++ b/client/src/variants/Alice.js @@ -60,6 +60,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 +101,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 +361,9 @@ 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; } };