X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FHex%2Fclass.js;h=05200bed65b11ed9599c02c21999c62965f7309c;hb=939e06bf9febef0a7935c7f6a58c5e28dee4dedc;hp=925507eb2d7074e7ba3388d51bc7eb4df8347b27;hpb=e7d409fc03a8cd8459a2b41f9fef51c0a3fb0d6d;p=xogo.git diff --git a/variants/Hex/class.js b/variants/Hex/class.js index 925507e..05200be 100644 --- a/variants/Hex/class.js +++ b/variants/Hex/class.js @@ -1,8 +1,8 @@ -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 { @@ -32,10 +32,12 @@ export default class HexRules extends ChessRules { get hasReserve() { return false; } - get noAnimate() { return true; } + get clickOnly() { + return true; + } doClick(coords) { if ( @@ -64,7 +66,7 @@ export default class HexRules extends ChessRules { new PiPo({ x: coords.x, y: coords.y, - c: C.GetOppCol(this.turn), + c: C.GetOppTurn(this.turn), p: 'p' }) ); @@ -72,10 +74,13 @@ export default class HexRules extends ChessRules { 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 - 1) + emptyCount, + o: {} + }; } getSvgChessboard() { @@ -148,43 +153,11 @@ export default class HexRules extends ChessRules { return board; } - setupPieces() { - for (let i=0; i { - 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.buildMoveStack(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"], @@ -195,11 +168,11 @@ export default class HexRules extends ChessRules { play(move) { this.playOnBoard(move); this.movesCount++; - this.turn = C.GetOppCol(this.turn); + this.turn = C.GetOppTurn(this.turn); } - getCurrentScore(move) { - const oppCol = C.GetOppCol(this.turn); + getCurrentScore() { + const oppCol = C.GetOppTurn(this.turn); // Search for connecting path of opp color: let explored = {}, component; let min, max; @@ -214,7 +187,7 @@ export default class HexRules extends ChessRules { max = z; explored[index] = true; component[index] = true; - for (let [dx, dy] of super.pieces()['k'].moves[0].steps) { + for (let [dx, dy] of super.pieces()['k'].both[0].steps) { const [nx, ny] = [x + dx, y + dy]; const nidx = getIndex(nx, ny); if ( @@ -242,15 +215,4 @@ export default class HexRules extends ChessRules { 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")); - }); - } - };