From: Benjamin Auder Date: Tue, 3 May 2022 19:47:54 +0000 (+0200) Subject: Pause. Next move: generalize base_rules.js to different boards, and complete Hex X-Git-Url: https://git.auder.net/doc/html/assets/pieces/app_dev.php/mini-custom.min.css?a=commitdiff_plain;h=728cb1e3b2ae84b1cf4aaa7e66b295f77dea359e;p=xogo.git Pause. Next move: generalize base_rules.js to different boards, and complete Hex --- diff --git a/base_rules.js b/base_rules.js index 2b2ecfa..353af39 100644 --- a/base_rules.js +++ b/base_rules.js @@ -619,16 +619,14 @@ export default class ChessRules { // Get SVG board (background, no pieces) getSvgChessboard() { - const [sizeX, sizeY] = [this.size.x, this.size.y]; const flipped = (this.playerColor == 'b'); let board = ` `; - for (let i=0; i < sizeX; i++) { - for (let j=0; j < sizeY; j++) { + for (let i=0; i < this.size.x; i++) { + for (let j=0; j < this.size.y; j++) { const ii = (flipped ? this.size.x - 1 - i : i); const jj = (flipped ? this.size.y - 1 - j : j); let classes = this.getSquareColorClass(ii, jj); @@ -1026,7 +1024,7 @@ export default class ChessRules { // BASIC UTILS get size() { - return {"x": 8, "y": 8}; + return {x: 8, y: 8}; } // Color of thing on square (i,j). 'undefined' if square is empty diff --git a/variants/Hex/Hex_board_11x11.svg b/variants/Hex/Hex_board_11x11.svg deleted file mode 100644 index 67082d7..0000000 --- a/variants/Hex/Hex_board_11x11.svg +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - -ABCDEFGHIJKABCDEFGHIJK11223344556677889910101111 - - diff --git a/variants/Hex/Regular_hexagon.svg b/variants/Hex/Regular_hexagon.svg index fc1c0d2..fc47b04 100644 --- a/variants/Hex/Regular_hexagon.svg +++ b/variants/Hex/Regular_hexagon.svg @@ -1,5 +1,9 @@ - - - - - + + + + + + + + + diff --git a/variants/Hex/class.js b/variants/Hex/class.js new file mode 100644 index 0000000..f1e3a83 --- /dev/null +++ b/variants/Hex/class.js @@ -0,0 +1,36 @@ + getSvgChessboard() { + const flipped = (this.playerColor == 'b'); + let board = ` + + + + + + `; + for (let i=0; i < this.size.x; i++) { + for (let j=0; j < this.size.y; j++) { + let classes = this.getSquareColorClass(i, j); + board += ``; + } + } + board += ""; + return board; + } + +// neutral-light neutral-dark --> specify per variant in CSS file + getSquareColorClass(i, j) { + return ((i+j) % 2 == 0 ? "light-square": "dark-square"); + } + +// TODO: generalize base_rules.js to not assume size.x == width and size.y == height (not true here).