-import ChessRules from "/base_rules.js";
+import AbstractClickFillRules from "/variants/_ClickFill/class.js";
import PiPo from "/utils/PiPo.js";
import Move from "/utils/Move.js";
-export default class HexRules extends ChessRules {
+export default class HexRules extends AbstractClickFillRules {
static get Options() {
return {
get hasReserve() {
return false;
}
-
get noAnimate() {
return true;
}
+ get clickOnly() {
+ return true;
+ }
doClick(coords) {
if (
return res;
}
- genRandInitFen() {
+ genRandInitBaseFen() {
// NOTE: size.x == size.y (square boards)
const emptyCount = C.FenEmptySquares(this.size.x);
- return (emptyCount + "/").repeat(this.size.x).slice(0, -1) + " w 0";
+ return {
+ fen: (emptyCount + "/").repeat(this.size.x).slice(0, -1) + " w 0",
+ o: {}
+ };
}
getSvgChessboard() {
return board;
}
- setupPieces() {
- for (let i=0; i<this.size.x; i++) {
- for (let j=0; j<this.size.y; j++) {
- if (this.board[i][j] != "") {
- const sqColor = (this.getColor(i, j) == 'w' ? "white" : "black");
- const elt = document.getElementById(this.coordsToId({x: i, y: j}));
- elt.classList.remove("neutral-square");
- elt.classList.add("bg-" + sqColor);
- }
- }
- }
- }
-
- initMouseEvents() {
- const mousedown = (e) => {
- if (e.touches && e.touches.length > 1)
- e.preventDefault();
- const cd = this.idToCoords(e.target.id);
- if (cd) {
- const move = this.doClick(cd);
- if (move)
- this.playPlusVisual(move);
- }
- };
-
- if ('onmousedown' in window) {
- document.addEventListener("mousedown", mousedown);
- document.addEventListener("wheel",
- (e) => this.rescale(e.deltaY < 0 ? "up" : "down"));
- }
- if ('ontouchstart' in window)
- document.addEventListener("touchstart", mousedown, {passive: false});
- }
-
get size() {
const baseRatio = 1.6191907514450865; //2801.2 / 1730, "widescreen"
- const rotate = window.innerWidth < window.innerHeight; //"vertical screen"
+ const rc =
+ document.getElementById(this.containerId).getBoundingClientRect();
+ const rotate = rc.width < rc.height; //"vertical screen"
return {
x: this.options["bsize"],
y: this.options["bsize"],
this.turn = C.GetOppCol(this.turn);
}
- getCurrentScore(move) {
+ getCurrentScore() {
const oppCol = C.GetOppCol(this.turn);
// Search for connecting path of opp color:
let explored = {}, component;
return "*";
}
- playVisual(move) {
- move.vanish.forEach(v => {
- let elt = document.getElementById(this.coordsToId({x: v.x, y: v.y}));
- elt.classList.remove("bg-" + (v.c == 'w' ? "white" : "black"));
- });
- move.appear.forEach(a => {
- let elt = document.getElementById(this.coordsToId({x: a.x, y: a.y}));
- elt.classList.add("bg-" + (a.c == 'w' ? "white" : "black"));
- });
- }
-
};