X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fbase_rules.js;h=350e0de642f59a78536af55c3fab92a3278f0853;hb=d7c00f6a7d6ad573df2a27965bf763b3bb1d0c18;hp=056f4774a9c3b56047e7b63ca4f49a6f767f0586;hpb=6808d7a16ec1e761c6a2dffec2281c96953e4d89;p=vchess.git diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 056f4774..350e0de6 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -4,8 +4,8 @@ import { ArrayFun } from "@/utils/array"; import { randInt, shuffle } from "@/utils/alea"; +// class "PiPo": Piece + Position export const PiPo = class PiPo { - //Piece+Position // o: {piece[p], color[c], posX[x], posY[y]} constructor(o) { this.p = o.p; @@ -15,7 +15,6 @@ export const PiPo = class PiPo { } }; -// TODO: for animation, moves should contains "moving" and "fading" maybe... export const Move = class Move { // o: {appear, vanish, [start,] [end,]} // appear,vanish = arrays of PiPo @@ -33,13 +32,26 @@ export const ChessRules = class ChessRules { ////////////// // MISC UTILS + // Some variants don't have flags: static get HasFlags() { return true; - } //some variants don't have flags + } + // Some variants don't have en-passant static get HasEnpassant() { return true; - } //some variants don't have ep. + } + + // Some variants cannot have analyse mode + static get CanAnalyze() { + return true; + } + + // Some variants show incomplete information, + // and thus show only a partial moves list or no list at all. + static get ShowMoves() { + return "all"; + } // Path to pieces static getPpath(b) { @@ -84,9 +96,12 @@ export const ChessRules = class ChessRules { if (position.length == 0) return false; const rows = position.split("/"); if (rows.length != V.size.x) return false; + let kings = {}; for (let row of rows) { let sumElts = 0; for (let i = 0; i < row.length; i++) { + if (['K','k'].includes(row[i])) + kings[row[i]] = true; if (V.PIECES.includes(row[i].toLowerCase())) sumElts++; else { const num = parseInt(row[i]); @@ -96,6 +111,9 @@ export const ChessRules = class ChessRules { } if (sumElts != V.size.y) return false; } + // Both kings should be on board: + if (Object.keys(kings).length != 2) + return false; return true; }