From: Benjamin Auder Date: Wed, 13 May 2026 14:13:06 +0000 (+0200) Subject: Ignore generated SVG. Attempt refactoring pieces() --> pieceDef() X-Git-Url: https://git.auder.net/variants/current/doc/css/assets/scripts/pieces/%7B%7B%20pkg.url%20%7D%7D?a=commitdiff_plain;p=xogo.git Ignore generated SVG. Attempt refactoring pieces() --> pieceDef() --- diff --git a/TODO b/TODO index 2020aca..7114f80 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -Issue with Dark Bario - Otage, Emergo, Pacosako : fonction "buildPiece(arg1, arg2)" returns HTML element with 2 SVG or SVG + number ==> plus simple : deux classes, images superposées (?) diff --git a/js/base_rules.js b/js/base_rules.js index 894e8aa..1a7543c 100644 --- a/js/base_rules.js +++ b/js/base_rules.js @@ -352,7 +352,8 @@ export default class ChessRules { if (o.init) return Array(2 * V.ReserveArray.length).fill('0').join(""); return ( - ['w', 'b'].map(c => Object.values(this.reserve[c]).join("")).join("") + ['w', 'b'].map(c => Object.values(this.reserve[c]).map( + v => v.toString(36)).join("")).join("") ); } @@ -497,7 +498,7 @@ export default class ChessRules { } getRankInReserve(c, p) { - const pieces = Object.keys(this.pieces(c, c, p)); + const pieces = Object.keys(V.ReserveArray); const lastIndex = pieces.findIndex(pp => pp == p) let toTest = pieces.slice(0, lastIndex); return toTest.reduce( @@ -674,7 +675,8 @@ export default class ChessRules { if (this.board[i][j] != "") { const color = this.getColor(i, j); const piece = this.getPiece(i, j); - addPiece(i, j, "g_pieces", this.pieces(color, i, j)[piece]["class"]); + addPiece(i, j, "g_pieces", + this.pieceDef(piece, color, i, j)["class"]); this.g_pieces[i][j].classList.add(V.GetColorClass(color)); if (this.enlightened && !this.enlightened[i][j]) this.g_pieces[i][j].classList.add("hidden"); @@ -741,7 +743,7 @@ export default class ChessRules { r_cell.style.height = sqResSize + "px"; rcontainer.appendChild(r_cell); let piece = document.createElement("piece"); - C.AddClass_es(piece, this.pieces(c, c, p)[p]["class"]); + C.AddClass_es(piece, this.pieceDef(p, c, c, p)["class"]); piece.classList.add(V.GetColorClass(c)); piece.style.width = "100%"; piece.style.height = "100%"; @@ -1060,7 +1062,7 @@ export default class ChessRules { const piece = document.createElement("piece"); const cdisp = moves[i].choice || moves[i].appear[0].p; C.AddClass_es(piece, - this.pieces(color, moves[i].end.x, moves[i].end.y)[cdisp]["class"]); + this.pieceDef(cdisp, color, moves[i].end.x, moves[i].end.y)["class"]); piece.classList.add(V.GetColorClass(color)); piece.style.width = "100%"; piece.style.height = "100%"; @@ -1110,7 +1112,7 @@ export default class ChessRules { enlightEnpassant() { // NOTE: shortcut, pawn has only one attack type, doesn't depend on square // TODO: (0, 0) is wrong, would need to place an attacker here... - const steps = this.pieces(this.playerColor, 0, 0)["p"].attack[0].steps; + const steps = this.pieceDef('p', this.playerColor, 0, 0).attack[0].steps; for (let step of steps) { const x = this.epSquare.x - step[0], //NOTE: epSquare.x not on edge y = this.getY(this.epSquare.y - step[1]); @@ -1186,7 +1188,7 @@ export default class ChessRules { getPieceType(x, y, p) { if (!p) p = this.getPiece(x, y); - return this.pieces(this.getColor(x, y), x, y)[p].moveas || p; + return this.pieceDef(p, this.getColor(x, y), x, y).moveas || p; } isKing(x, y, p) { @@ -1229,10 +1231,11 @@ export default class ChessRules { return (color == 'w' && x >= 6) || (color == 'b' && x <= 1); } - pieces(color, x, y) { - const pawnShift = this.getPawnShift(color || 'w'); - return { - 'p': { + pieceDef(piece, color, x, y) { + switch (piece) { + case 'p': { + const pawnShift = this.getPawnShift(color || 'w'); + return { "class": "pawn", moves: [ { @@ -1246,14 +1249,17 @@ export default class ChessRules { range: 1 } ] - }, - 'r': { + }; + } + case 'r': + return { "class": "rook", both: [ {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]} ] - }, - 'n': { + }; + case 'n': + return { "class": "knight", both: [ { @@ -1264,14 +1270,16 @@ export default class ChessRules { range: 1 } ] - }, - 'b': { + }; + case 'b': + return { "class": "bishop", both: [ {steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]]} ] - }, - 'q': { + }; + case 'q': + return { "class": "queen", both: [ { @@ -1281,8 +1289,9 @@ export default class ChessRules { ] } ] - }, - 'k': { + }; + case 'k': + return { "class": "king", both: [ { @@ -1293,14 +1302,14 @@ export default class ChessRules { range: 1 } ] - }, - // Cannibal kings: - '!': {"class": "king-pawn", moveas: "p"}, - '#': {"class": "king-rook", moveas: "r"}, - '$': {"class": "king-knight", moveas: "n"}, - '%': {"class": "king-bishop", moveas: "b"}, - '*': {"class": "king-queen", moveas: "q"} - }; + }; + // Cannibal kings: + case '!': return {"class": "king-pawn", moveas: "p"}; + case '#': return {"class": "king-rook", moveas: "r"}; + case '$': return {"class": "king-knight", moveas: "n"}; + case '%': return {"class": "king-bishop", moveas: "b"}; + case '*': return {"class": "king-queen", moveas: "q"}; + } } // NOTE: using special symbols to not interfere with variants' pieces codes @@ -1359,13 +1368,11 @@ export default class ChessRules { } getStepSpec(color, x, y, piece) { - let pieceType = piece; - let allSpecs = this.pieces(color, x, y); - if (!piece) - pieceType = this.getPieceType(x, y); - else if (allSpecs[piece].moveas) - pieceType = allSpecs[piece].moveas; - let res = allSpecs[pieceType]; + let pieceType = + !piece + ? this.getPieceType(x, y) + : this.pieceDef(piece, color, x, y).moveas || piece; + let res = this.pieceDef(pieceType, color, x, y); if (!res["both"]) res.both = []; if (!res["moves"]) @@ -2510,7 +2517,7 @@ export default class ChessRules { move.appear.forEach(a => { this.g_pieces[a.x][a.y] = document.createElement("piece"); C.AddClass_es(this.g_pieces[a.x][a.y], - this.pieces(a.c, a.x, a.y)[a.p]["class"]); + this.pieceDef(a.p, a.c, a.x, a.y)["class"]); this.g_pieces[a.x][a.y].classList.add(V.GetColorClass(a.c)); this.g_pieces[a.x][a.y].style.width = pieceWidth + "px"; this.g_pieces[a.x][a.y].style.height = pieceWidth + "px"; @@ -2585,11 +2592,12 @@ export default class ChessRules { } const maxDist = this.getMaxDistance(r); const apparentColor = this.getColor(start.x, start.y); - const pieces = this.pieces(apparentColor, start.x, start.y); if (drag) { const startCode = this.getPiece(start.x, start.y); - C.RemoveClass_es(movingPiece, pieces[startCode]["class"]); - C.AddClass_es(movingPiece, pieces[drag.p]["class"]); + C.RemoveClass_es(movingPiece, + this.pieceDef(startCode, apparentColor, start.x, start.y)["class"]); + C.AddClass_es(movingPiece, + this.pieceDef(drag.p, apparentColor, start.x, start.y)["class"]); if (apparentColor != drag.c) { movingPiece.classList.remove(V.GetColorClass(apparentColor)); movingPiece.classList.add(V.GetColorClass(drag.c)); diff --git a/pieces/Avalam/.gitignore b/pieces/Avalam/.gitignore new file mode 100644 index 0000000..756b22f --- /dev/null +++ b/pieces/Avalam/.gitignore @@ -0,0 +1 @@ +*.svg diff --git a/pieces/Avalam/black_stack.svg b/pieces/Avalam/black_stack.svg deleted file mode 100644 index 1ee0e2b..0000000 --- a/pieces/Avalam/black_stack.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/pieces/Avalam/black_stack2.svg b/pieces/Avalam/black_stack2.svg deleted file mode 100644 index de29024..0000000 --- a/pieces/Avalam/black_stack2.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pieces/Avalam/black_stack3.svg b/pieces/Avalam/black_stack3.svg deleted file mode 100644 index 3518349..0000000 --- a/pieces/Avalam/black_stack3.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pieces/Avalam/black_stack4.svg b/pieces/Avalam/black_stack4.svg deleted file mode 100644 index 6d92f7c..0000000 --- a/pieces/Avalam/black_stack4.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pieces/Avalam/black_stack5.svg b/pieces/Avalam/black_stack5.svg deleted file mode 100644 index 9ea4b0a..0000000 --- a/pieces/Avalam/black_stack5.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pieces/Avalam/white_stack.svg b/pieces/Avalam/white_stack.svg deleted file mode 100644 index d997ee1..0000000 --- a/pieces/Avalam/white_stack.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/pieces/Avalam/white_stack2.svg b/pieces/Avalam/white_stack2.svg deleted file mode 100644 index b238b2d..0000000 --- a/pieces/Avalam/white_stack2.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pieces/Avalam/white_stack3.svg b/pieces/Avalam/white_stack3.svg deleted file mode 100644 index 3a3df31..0000000 --- a/pieces/Avalam/white_stack3.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pieces/Avalam/white_stack4.svg b/pieces/Avalam/white_stack4.svg deleted file mode 100644 index 91a4df3..0000000 --- a/pieces/Avalam/white_stack4.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pieces/Avalam/white_stack5.svg b/pieces/Avalam/white_stack5.svg deleted file mode 100644 index 7e8cf11..0000000 --- a/pieces/Avalam/white_stack5.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pieces/Emergo/.gitignore b/pieces/Emergo/.gitignore new file mode 100644 index 0000000..756b22f --- /dev/null +++ b/pieces/Emergo/.gitignore @@ -0,0 +1 @@ +*.svg diff --git a/pieces/Emergo/generateSVG_simple.py b/pieces/Emergo/generateSVG.py similarity index 92% rename from pieces/Emergo/generateSVG_simple.py rename to pieces/Emergo/generateSVG.py index 51f734e..258af71 100755 --- a/pieces/Emergo/generateSVG_simple.py +++ b/pieces/Emergo/generateSVG.py @@ -4,7 +4,11 @@ # https://travishorn.com/removing-parts-of-shapes-in-svg-b539a89e5649 # https://developer.mozilla.org/fr/docs/Web/SVG/Tutoriel/Paths -preamble = """ +############################### +# 1. Simple pieces (mono-color) +############################### + +preamble_simple = """ """ @@ -45,7 +49,7 @@ for color in ["white", "black"]: for number in range(12): filename = chr(65 + number + chrShift) + "@.svg" f = open(filename, "w") - f.write(preamble) + f.write(preamble_simple) f.write("\n") f.write(white if color == "white" else black) f.write("\n") @@ -55,8 +59,11 @@ for color in ["white", "black"]: f.write(final) f.close() +################################ +# 1. Composite pieces (bi-color) +################################ -preamble = """ +preamble_composite = """ @@ -134,7 +141,7 @@ for colorTop in ["white", "black"]: for bottom in range(12): filename = chr(65 + top + chrShift) + chr(65 + bottom + chrShift) + ".svg" f = open(filename, "w") - f.write(preamble) + f.write(preamble_composite) f.write("\n") f.write(black_bottom if colorTop == "white" else white_bottom) f.write("\n") diff --git a/pieces/Emergo/generateSVG_composite.py b/pieces/Emergo/generateSVG_composite.py deleted file mode 100755 index 85726d5..0000000 --- a/pieces/Emergo/generateSVG_composite.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python - -# Compose each piece SVG with numbers -# https://travishorn.com/removing-parts-of-shapes-in-svg-b539a89e5649 -# https://developer.mozilla.org/fr/docs/Web/SVG/Tutoriel/Paths - -preamble = """ - - - - - - - -""" - -black_top = '' -white_bottom = '' -white_top = '' -black_bottom = '' - -digits = { - "top": [ - # 1 (unused here) - '= 1: - f.write(digits["top"][top] + ' fill="none" stroke-width="5" ' + ('stroke="red"' if colorTop == "white" else 'stroke="orange"') + '/>') - f.write("\n") - if bottom >= 1: - f.write(digits["bottom"][bottom] + ' fill="none" stroke-width="5" ' + ('stroke="red"' if colorTop == "black" else 'stroke="orange"') + '/>') - f.write("\n") - f.write(final) - f.close() diff --git a/variants/Emergo/class.js b/variants/Emergo/class.js index 2635e63..f40627b 100644 --- a/variants/Emergo/class.js +++ b/variants/Emergo/class.js @@ -19,6 +19,12 @@ export default class EmergoRules extends ChessRules { get hasEnpassant() { return false; } + get hasReserve() { + return true; + } + static get HasKing() { + return false; + } // board element == piece class ref: board2fen(b) { @@ -48,11 +54,15 @@ export default class EmergoRules extends ChessRules { } getColor(x, y) { - if (x >= this.size.x) - return x == this.size.x ? "w" : "b"; - if (this.board[x][y].charCodeAt(0) < 97) - return 'w'; - return 'b'; + const sq = (typeof x == "string" ? x : this.board[x][y]); + return sq.charCodeAt(0) < 97 ? 'w' : 'b'; + } + + pieceDef(piece, color, x, y) { + //this.board[x][y] + // --> TODO + // Moving always the same, but look differs + // class: classUp, class: classDOwn + composition } getPiece(x, y) { @@ -64,21 +74,17 @@ export default class EmergoRules extends ChessRules { } genRandInitBaseFen() { - return { fen: "9/9/9/9/9/9/9/9/9 w 0 12,12", o: {} }; + return { fen: "9/9/9/9/9/9/9/9/9", o: {} }; } static get ReserveArray() { - // Piece type doesn't matter - return ['@']; //TODO :: - - - + return ['a@']; } setOtherVariables(fenParsed) { super.setOtherVariables(fenParsed); - // Local stack of captures during a turn (squares + directions) - this.captures = [ [] ]; + // Last capture during a turn (square + direction) + this.lastCapture = null; } atLeastOneCaptureFrom([x, y], color, forbiddenStep) { @@ -102,13 +108,10 @@ export default class EmergoRules extends ChessRules { } atLeastOneCapture(color) { - const L0 = this.captures.length; - const captures = this.captures[L0 - 1]; - const L = captures.length; - if (L > 0) { + if (!!this.lastCapture) { return ( this.atLeastOneCaptureFrom( - captures[L-1].square, color, captures[L-1].step) + this.lastCapture.square, color, this.lastCapture.step) ); } for (let i = 0; i < this.size.x; i++) { @@ -196,17 +199,14 @@ export default class EmergoRules extends ChessRules { } getAllLongestCaptures(color) { - const L0 = this.captures.length; - const captures = this.captures[L0 - 1]; - const L = captures.length; let caps = []; - if (L > 0) { - let locSteps = [ captures[L-1].step ]; + if (!!this.lastCapture) { + let locSteps = [ this.lastCapture.step ]; let res = - this.getLongestCapturesFrom(captures[L-1].square, color, locSteps); + this.getLongestCapturesFrom(this.lastCapture.square, color, locSteps); Array.prototype.push.apply( caps, - res.map(r => Object.assign({ square: captures[L-1].square }, r)) + res.map(r => Object.assign({ square: this.lastCapture.square }, r)) ); } else { @@ -352,7 +352,7 @@ export default class EmergoRules extends ChessRules { } getPossibleMovesFrom([x, y], longestCaptures) { - if (x >= this.size.x) { + if (typeof x === "string") { if (longestCaptures.length == 0) return this.getReserveMoves(x); return []; @@ -360,14 +360,11 @@ export default class EmergoRules extends ChessRules { const color = this.turn; if (!!this.reserve[color] && !this.atLeastOneCapture(color)) return []; - const L0 = this.captures.length; - const captures = this.captures[L0 - 1]; - const L = captures.length; let moves = []; if (longestCaptures.length > 0) { if ( - L > 0 && - (x != captures[L-1].square[0] || y != captures[L-1].square[1]) + !!this.lastCapture && + (x != this.lastCapture.square[0] || y != this.lastCapture.square[1]) ) { return []; } @@ -403,12 +400,10 @@ export default class EmergoRules extends ChessRules { move.turn = color; //for undo V.PlayOnBoard(this.board, move); if (move.vanish.length == 2) { - const L0 = this.captures.length; - let captures = this.captures[L0 - 1]; - captures.push({ + this.lastCapture = { square: [move.end.x, move.end.y], step: [(move.end.x - move.start.x)/2, (move.end.y - move.start.y)/2] - }); + }; if (this.atLeastOneCapture(color)) // There could be other captures (mandatory) move.notTheEnd = true; @@ -423,7 +418,7 @@ export default class EmergoRules extends ChessRules { if (!move.notTheEnd) { this.turn = V.GetOppCol(color); this.movesCount++; - this.captures.push([]); + this.lastCapture = null; } }