X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKonane.js;h=1daad7afebbee34a750a71d68c1595349a15dbfc;hb=7c05a5f2297bea540c700ebceb0cc8b03a7f6775;hp=1ff77ee9d5330ea8abf0126b278abe3d9291d1bb;hpb=cbe9537881e68f50c43f48d3699c4b248690fb4d;p=vchess.git diff --git a/client/src/variants/Konane.js b/client/src/variants/Konane.js index 1ff77ee9..1daad7af 100644 --- a/client/src/variants/Konane.js +++ b/client/src/variants/Konane.js @@ -1,4 +1,5 @@ import { ChessRules, Move, PiPo } from "@/base_rules"; +import { randInt } from "@/utils/alea"; export class KonaneRules extends ChessRules { @@ -14,10 +15,6 @@ export class KonaneRules extends ChessRules { return true; } - static get PIECES() { - return V.PAWN; - } - getPiece() { return V.PAWN; } @@ -33,7 +30,7 @@ export class KonaneRules extends ChessRules { for (let row of rows) { let sumElts = 0; for (let i = 0; i < row.length; i++) { - if (V.PIECES.includes(row[i].toLowerCase())) sumElts++; + if (row[i].toLowerCase() == V.PAWN) sumElts++; else { const num = parseInt(row[i], 10); if (isNaN(num) || num <= 0) return false; @@ -56,9 +53,9 @@ export class KonaneRules extends ChessRules { this.captures = []; //reinit for each move } - hoverHighlight(x, y) { - if (this.movesCount >= 2) return false; + hoverHighlight([x, y], side) { const c = this.turn; + if (this.movesCount >= 2 || (!!side && side != c)) return false; if (c == 'w') return (x == y && [0, 3, 4, 7].includes(x)); // "Black": search for empty square and allow nearby for (let i of [0, 3, 4, 7]) { @@ -199,8 +196,27 @@ export class KonaneRules extends ChessRules { else this.captures.pop(); } - static get SEARCH_DEPTH() { - return 4; + getComputerMove() { + const color = this.turn; + let mvArray = []; + let mv = null; + const undoAll = () => { + for (let i = mvArray.length - 1; i >= 0; i--) this.undo(mvArray[i]); + }; + // Just play random moves (for now at least. TODO?) + while (this.turn == color) { + let moves = super.getAllValidMoves(); + if (moves.length == 0) { + // Shouldn't happen, but... + undoAll(); + return null; + } + mv = moves[randInt(moves.length)]; + mvArray.push(mv); + this.play(mv); + } + undoAll(); + return (mvArray.length > 1 ? mvArray : mvArray[0]); } getNotation(move) {