// TODO: onpointerdown/move/up ? See reveal.js /controllers/touch.js
}
+ // NOTE: not called if isDiagram, or genFenOnly
removeListeners() {
let container = document.getElementById(this.containerId);
this.windowResizeObs.unobserve(container);
- if (this.isDiagram)
- return; //no listeners in this case
if ('onmousedown' in window) {
this.mouseListeners.forEach(ml => {
document.removeEventListener(ml.type, ml.listener);
-//TODO:
-// - pass btn on top + message if opponent just passed
-// - do not count points: rely on players' ability to do that
-// - implement Ko rule (need something in fen: lastMove)
-
import ChessRules from "/base_rules.js";
import Move from "/utils/Move.js";
import PiPo from "/utils/PiPo.js";
export default class WeiqiRules extends ChessRules {
- // TODO: option oneColor (just alter pieces class of white stones)
static get Options() {
return {
input: [
variable: "bsize",
type: "number",
defaut: 9
+ },
+ {
+ label: "One color",
+ variable: "onecolor",
+ type: "checkbox",
+ defaut: false
}
]
};
genRandInitBaseFen() {
const fenLine = C.FenEmptySquares(this.size.y);
return {
- fen: (fenLine + '/').repeat(this.size.x - 1) + fenLine + " w 0",
+ fen: (fenLine + '/').repeat(this.size.x - 1) + fenLine,
o: {}
};
}
+ constructor(o) {
+ super(o);
+ if (!o.genFenOnly && !o.diagram) {
+
+ this.passListener = () => this.play({pass: true}); //TODO: wrong, need to use buildMoveStack (warning empty move...)
+
+ // Show pass btn
+ let passBtn = document.createElement("button");
+ C.AddClass_es(passBtn, "pass-btn");
+ passBtn.innerHTML = "pass";
+ passBtn.addEventListener("click", this.passListener);
+ let container = document.getElementById(this.containerId);
+ container.appendChild(passBtn);
+ }
+ }
+
+ removeListeners() {
+ super.removeListeners();
+ let passBtn = document.getElementsByClassName("pass-btn")[0];
+ passBtn.removeEventListener("click", this.passListener);
+ }
+
pieces(color, x, y) {
+ let classe_s = ["stone"];
+ if (this.options["onecolor"] && color == 'w')
+ classe_s.push("one-color");
return {
's': {
- "class": "stone",
+ "class": classe_s,
moves: []
}
};
return res;
}
+ play(move) {
+ if (move.pass) {
+ if (this.turn != this.playerColor)
+ super.displayMessage(null, "pass", "pass-text", 2000);
+ else
+ this.turn = C.GetOppCol(this.turn);
+ }
+ else
+ super.play(move);
+ }
+
filterValid(moves) {
// Suicide check not here, because side-computation of captures
return moves;
piece.white.stone {
background-image: url('/variants/Weiqi/pieces/black_stone.svg');
}
-piece.black.stone {
+piece.black.stone, piece.white.stone.one-color {
background-image: url('/variants/Weiqi/pieces/white_stone.svg');
}
+
+button.pass-btn {
+ display: block;
+ position: relative;
+ margin: 0 auto;
+}
+
+/* TODO: copy-paste from Chakart */
+div.pass-text {
+ position: relative;
+ margin-top: 15px;
+ width: 100%;
+ text-align: center;
+ background-color: transparent;
+ color: darkred;
+ font-weight: bold;
+ font-size: 2em;
+ animation: blinker 0.5s linear infinite;
+}
+
+@keyframes blinker {
+ 50% {
+ opacity: 0;
+ }
+}