From: Benjamin Auder Date: Thu, 5 Oct 2023 14:25:45 +0000 (+0200) Subject: Prepare Coregal variant X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/css/user/doc/pieces/cr.svg?a=commitdiff_plain;h=5c1c7bcec764d94b0469ab4d7d0777ce67e05ae3;p=xogo.git Prepare Coregal variant --- diff --git a/base_rules.js b/base_rules.js index 0b71cf4..6078da8 100644 --- a/base_rules.js +++ b/base_rules.js @@ -235,7 +235,7 @@ export default class ChessRules { randomness: this.options["randomness"], between: [{p1: 'k', p2: 'r'}], diffCol: ['b'], - flags: ['r'] + flags: ['r', 'k'] } ); return { diff --git a/pieces/Coregal/black_royal_queen.svg b/pieces/Coregal/black_royal_queen.svg new file mode 100644 index 0000000..49bfbe3 --- /dev/null +++ b/pieces/Coregal/black_royal_queen.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/pieces/Coregal/white_royal_queen.svg b/pieces/Coregal/white_royal_queen.svg new file mode 100644 index 0000000..b98b76f --- /dev/null +++ b/pieces/Coregal/white_royal_queen.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/variants/Coregal/Coregal.js b/variants/Coregal/Coregal.js deleted file mode 100644 index e12a748..0000000 --- a/variants/Coregal/Coregal.js +++ /dev/null @@ -1,121 +0,0 @@ -import { ChessRules, Move, PiPo } from "@/base_rules"; -import { ArrayFun } from "@/utils/array"; -import { randInt, sample } from "@/utils/alea"; - -export class CoregalRules extends ChessRules { - -// TODO: special symbol (l) for royal queen... - - getPPpath(m) { - if ( - m.vanish.length == 2 && - m.appear.length == 2 && - m.vanish[0].p == V.QUEEN - ) { - // Large castle: show castle symbol - return "Coregal/castle"; - } - return super.getPPpath(m); - } - - genRandInitBaseFen() { - const s = FenUtil.setupPieces( - ['r', 'n', 'b', 'l', 'k', 'b', 'n', 'r'], - { - randomness: this.options["randomness"], - between: [{p1: 'k', p2: 'r'}, {p1: 'l', p2: 'r'}], - diffCol: ['b'], - flags: ['r', 'k', 'l'] - } - ); - return { - fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + - s.w.join("").toUpperCase(), - o: {flags: s.flags} - }; - } - - pieces() { - let res = super.pieces(); - res['l'] = {...}; - return res; - } - - setFlags(fenflags) { - // white pieces positions, then black pieces positions - this.castleFlags = { w: [...Array(4)], b: [...Array(4)] }; - for (let i = 0; i < 8; i++) { - this.castleFlags[i < 4 ? "w" : "b"][i % 4] = - parseInt(fenflags.charAt(i), 10); - } - } - - getPotentialQueenMoves([x, y]) { - let moves = super.getPotentialQueenMoves([x, y]); - const c = this.getColor(x, y); - if (this.castleFlags[c].slice(1, 3).includes(y)) - moves = moves.concat(this.getCastleMoves([x, y])); - return moves; - } - - getPotentialKingMoves([x, y]) { - let moves = this.getSlideNJumpMoves( - [x, y], V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1); - const c = this.getColor(x, y); - if (this.castleFlags[c].slice(1, 3).includes(y)) - moves = moves.concat(this.getCastleMoves([x, y])); - return moves; - } - - getCastleMoves([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] - ]; - 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); - return moves; - } - - // "twoKings" arg for the similar Twokings variant. - updateCastleFlags(move, piece, twoKings) { - const c = V.GetOppCol(this.turn); - const firstRank = (c == "w" ? V.size.x - 1 : 0); - // Update castling flags if castling pieces moved or were captured - const oppCol = V.GetOppCol(c); - const oppFirstRank = V.size.x - 1 - firstRank; - if (move.start.x == firstRank) { - if (piece == V.KING || (!twoKings && piece == V.QUEEN)) { - if (this.castleFlags[c][1] == move.start.y) - this.castleFlags[c][1] = 8; - else if (this.castleFlags[c][2] == move.start.y) - this.castleFlags[c][2] = 8; - // Else: the flag is already turned off - } - } - else if ( - move.start.x == firstRank && //our rook moves? - [this.castleFlags[c][0], this.castleFlags[c][3]].includes(move.start.y) - ) { - const flagIdx = (move.start.y == this.castleFlags[c][0] ? 0 : 3); - this.castleFlags[c][flagIdx] = 8; - } else if ( - move.end.x == oppFirstRank && //we took opponent rook? - [this.castleFlags[oppCol][0], this.castleFlags[oppCol][3]] - .includes(move.end.y) - ) { - const flagIdx = (move.end.y == this.castleFlags[oppCol][0] ? 0 : 3); - this.castleFlags[oppCol][flagIdx] = 8; - } - } - -}; diff --git a/variants/Coregal/class.js b/variants/Coregal/class.js new file mode 100644 index 0000000..b563fec --- /dev/null +++ b/variants/Coregal/class.js @@ -0,0 +1,67 @@ +import { ChessRules, Move, PiPo } from "@/base_rules"; +import { ArrayFun } from "@/utils/array"; +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'], + { + 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 ??! + } + ); + return { + fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + + s.w.join("").toUpperCase(), + o: {flags: s.flags} + }; + } + + pieces() { + let res = super.pieces(); + res['l'] = JSON.parse(JSON.stringify(res['q'])); + res['l']["class"] = "royal_queen"; + return res; + } + + setFlags(fenflags) { + // white pieces positions, then black pieces positions + this.castleFlags = { w: [...Array(4)], b: [...Array(4)] }; + for (let i = 0; i < 8; i++) { + this.castleFlags[i < 4 ? "w" : "b"][i % 4] = + parseInt(fenflags.charAt(i), 10); + } + } + + isKing(x, y, p) { + if (!p) + p = this.getPiece(x, y); + ['k', 'l'].includes(p); //no cannibal mode + } + + getCastleMoves([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] + ]; + 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); + return moves; + } + +}; diff --git a/variants/Coregal/rules.html b/variants/Coregal/rules.html new file mode 100644 index 0000000..8b5ee63 --- /dev/null +++ b/variants/Coregal/rules.html @@ -0,0 +1,6 @@ +

+ The queen is royal too: she cannot move or remain into check, + and can be checkmated. Qhe has the right to castle with either rook. +

+ +

Vernon R. Parton (1970).

diff --git a/variants/Coregal/style.css b/variants/Coregal/style.css new file mode 100644 index 0000000..b0046d0 --- /dev/null +++ b/variants/Coregal/style.css @@ -0,0 +1,8 @@ +@import url("/base_pieces.css"); + +piece.black.royal_queen { + background-image: url('/pieces/Coregal/black_royal_queen.svg'); +} +piece.white.royal_queen { + background-image: url('/pieces/Coregal/white_royal_queen.svg'); +}