1 // https://www.boardspace.net/hex/english/Rules%20-%20HexWiki.htm
2 export default class HexRules
extends ChessRules
{
34 this.board
[coords
.x
][coords
.y
] != "" &&
35 (!this.swap
|| this.movesCount
>= 2)
40 start: {x: coords
.x
, y: coords
.y
},
51 if (this.board
[coords
.x
][coords
.y
] != "") {
56 c: C
.GetOppCol(this.turn
),
65 // NOTE: size.x == size.y (square boards)
66 const emptyCount
= C
.FenEmptySquares(this.size
.x
.repeat
);
67 return (emptyCount
+ "/").repeat(this.size
.x
).slice(0, -1);
70 getPieceWidth(rwidth
) {
71 return (rwidth
/ this.size
.y
); //TODO
78 width="2771.2px" height="1700px"
79 class="chessboard_SVG">
83 style="fill:none;stroke:#000000;stroke-width:1px"
84 points="0,-100.0 86.6,-50.0 86.6,50.0 0,100.0 -86.6,50.0 -86.6,-50.0"
88 for (let i
=0; i
< this.size
.x
; i
++) {
89 for (let j
=0; j
< this.size
.y
; j
++) {
90 let classes
= this.getSquareColorClass(i
, j
);
92 class="neutral-square"
93 id="${this.coordsToId([i, j])}"
96 x="${10*j}" ///////////// + resize ! ratio
100 board
+= "</g></svg>";
105 // TODO: just scan board and get IDs, and addClass "bg-white" or "bg-black"
108 // TODO (NOTE: no flip here, always same view)
109 getPixelPosition(i
, j
, r
) {
111 return [0, 0]; //piece vanishes
113 const sqSize
= r
.width
/ this.size
.y
;
114 const flipped
= (this.playerColor
== 'b');
115 const x
= (flipped
? this.size
.y
- 1 - j : j
) * sqSize
,
116 y
= (flipped
? this.size
.x
- 1 - i : i
) * sqSize
;
117 return [r
.x
+ x
, r
.y
+ y
];
121 const mousedown
= (e
) => {
122 if (e
.touches
&& e
.touches
.length
> 1)
124 const cd
= this.idToCoords(e
.target
.id
);
126 const move = this.doClick(cd
);
128 this.playPlusVisual(move);
132 if ('onmousedown' in window
)
133 document
.addEventListener("mousedown", mousedown
);
134 if ('ontouchstart' in window
)
135 document
.addEventListener("touchstart", mousedown
, {passive: false});
155 super.playOnBoard(move);
159 getCurrentScore(move) {
160 const oppCol
= C
.GetOppCol(this.turn
);
161 // Search for connecting path of opp color: TODO
164 return (oppCol
== "w" ? "1-0" : "0-1");
169 move.vanish
.forEach(v
=> {
170 // TODO: just get ID, and remClass "bg-white" or "bg-black" (in CSS: TODO)
172 move.appear
.forEach(a
=> {
173 // TODO: just get ID, and addClass "bg-white" or "bg-black" (in CSS: TODO)
174 // this.g_pieces[a.x][a.y] = document.createElement("piece");
175 // this.g_pieces[a.x][a.y].classList.add(this.pieces()[a.p]["class"]);
176 // this.g_pieces[a.x][a.y].classList.add(a.c == "w" ? "white" : "black");
177 // this.g_pieces[a.x][a.y].style.width = pieceWidth + "px";
178 // this.g_pieces[a.x][a.y].style.height = pieceWidth + "px";