X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FCoregal%2Fclass.js;h=4df32ad178cd1ece9bfa4f6e86e954b09469a779;hb=dcfaab5dc62ccd9701ff314ad4e3d40c40223d44;hp=b563fec44dce9d6ecf840b4d7c41acd9202773db;hpb=8b629a6b470e02c96954054e55e31dffc407f4bd;p=xogo.git diff --git a/variants/Coregal/class.js b/variants/Coregal/class.js index b563fec..4df32ad 100644 --- a/variants/Coregal/class.js +++ b/variants/Coregal/class.js @@ -4,8 +4,6 @@ import { randInt, sample } from "@/utils/alea"; export class CoregalRules extends ChessRules { -//TODO: CSS royal queen symbol - genRandInitBaseFen() { const s = FenUtil.setupPieces( ['r', 'n', 'b', 'l', 'k', 'b', 'n', 'r'], @@ -13,28 +11,35 @@ export class CoregalRules extends ChessRules { randomness: this.options["randomness"], between: [{p1: 'k', p2: 'r'}, {p1: 'l', p2: 'r'}], diffCol: ['b'], - flags: ['r', 'k', 'l'] //TODO: add 'k' to all 'flags' calls ??! + // 'k' and 'l' useful only to get relative position + flags: ['r', 'k', 'l'] } ); return { fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + s.w.join("").toUpperCase(), - o: {flags: s.flags} + // TODO: re-arrange flags, use another init variable "relPos" (in o) + // (maybe after FEN parsing, easier?) + o: {flags: s.flags + s.flags} //second set for royal queen }; } pieces() { let res = super.pieces(); res['l'] = JSON.parse(JSON.stringify(res['q'])); + // TODO: CSS royal queen symbol (with cross?) res['l']["class"] = "royal_queen"; return res; } + // TODO: something like that indeed (+ flags to FEN) setFlags(fenflags) { - // white pieces positions, then black pieces positions - this.castleFlags = { w: [...Array(4)], b: [...Array(4)] }; + this.castleFlags = { + 'k': { 'w': [...Array(4)], b: [...Array(4)] }, + 'l': { 'w': [...Array(4)], b: [...Array(4)] } + }; for (let i = 0; i < 8; i++) { - this.castleFlags[i < 4 ? "w" : "b"][i % 4] = + this.castleFlags[i < 4 ? "k" : "l"][i % 4 < 2 ? "w" : "b"] = parseInt(fenflags.charAt(i), 10); } } @@ -46,22 +51,20 @@ export class CoregalRules extends ChessRules { } getCastleMoves([x, y]) { + const c = this.getColor(x, y), + p = this.getPiece(x, y); // Relative position of the selected piece: left or right ? // If left: small castle left, large castle right. // If right: usual situation. - const c = this.getColor(x, y); - const relPos = (this.castleFlags[c][1] == y ? "left" : "right"); - const finalSquares = [ - relPos == "left" ? [1, 2] : [2, 3], - relPos == "right" ? [6, 5] : [5, 4] + this.relPos[c][p] == "left" ? [1, 2] : [2, 3], + this.relPos[c][p] == "right" ? [6, 5] : [5, 4] ]; - const saveFlags = JSON.stringify(this.castleFlags[c]); - // Alter flags to follow base_rules semantic - this.castleFlags[c] = [0, 3].map(i => this.castleFlags[c][i]); - const moves = super.getCastleMoves([x, y], finalSquares); - this.castleFlags[c] = JSON.parse(saveFlags); + const moves = + super.getCastleMoves([x, y], finalSquares, null, this.castleFlags[p]); return moves; } + // TODO: updateFlags (just pass castleFlags arg) + };