X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FWeiqi%2Fclass.js;h=ce8531f6047fa6e61cf027ef1591e7451e8156af;hb=27a6d311f49e4c1ae9415f4dc4b79dfcb690c80d;hp=e528719e684c1d38976ed5b75a6715f8761d40b2;hpb=3cc4a84559092337d916c83367a6b457d6ca2b02;p=xogo.git diff --git a/variants/Weiqi/class.js b/variants/Weiqi/class.js index e528719..ce8531f 100644 --- a/variants/Weiqi/class.js +++ b/variants/Weiqi/class.js @@ -1,8 +1,3 @@ -//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"; @@ -10,7 +5,6 @@ import {ArrayFun} from "/utils/array.js"; export default class WeiqiRules extends ChessRules { - // TODO: option oneColor (just alter pieces class of white stones) static get Options() { return { input: [ @@ -19,6 +13,12 @@ export default class WeiqiRules extends ChessRules { variable: "bsize", type: "number", defaut: 9 + }, + { + label: "One color", + variable: "onecolor", + type: "checkbox", + defaut: false } ] }; @@ -82,15 +82,40 @@ export default class WeiqiRules extends ChessRules { 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: [] } }; @@ -162,6 +187,17 @@ export default class WeiqiRules extends ChessRules { 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;