X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKonane.js;h=357bae75846e72c4cf1316b1bf1041b0599caa77;hb=cdab566355412821c9187078ee0864ceb30545de;hp=8f285efc3996b4d79df925eb5c4d88b834e674eb;hpb=d2af3400944331ffd0c770f83857257c2f48e487;p=vchess.git diff --git a/client/src/variants/Konane.js b/client/src/variants/Konane.js index 8f285efc..357bae75 100644 --- a/client/src/variants/Konane.js +++ b/client/src/variants/Konane.js @@ -1,6 +1,5 @@ import { ChessRules, Move, PiPo } from "@/base_rules"; - -// TODO: Maybe more flexible end of game messages (V.ColorsReversed ?!) +import { randInt } from "@/utils/alea"; export class KonaneRules extends ChessRules { @@ -12,7 +11,11 @@ export class KonaneRules extends ChessRules { return false; } - static get PIECES() { + static get ReverseColors() { + return true; + } + + getPiece() { return V.PAWN; } @@ -27,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; @@ -193,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) {