X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKonane.js;h=357bae75846e72c4cf1316b1bf1041b0599caa77;hb=cdab566355412821c9187078ee0864ceb30545de;hp=1ff77ee9d5330ea8abf0126b278abe3d9291d1bb;hpb=cbe9537881e68f50c43f48d3699c4b248690fb4d;p=vchess.git diff --git a/client/src/variants/Konane.js b/client/src/variants/Konane.js index 1ff77ee9..357bae75 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; @@ -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) {