X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FJanggi.js;h=aecc8fe2fd859784bf865794b88609c04add57e4;hb=b2e8c34e0158f512741d67b8a1c25425e0b8747e;hp=98660a4bf08428d9a8e224697713a394a6f756dc;hpb=fe887246377e76ea1fbd6fa19d99d6b1fdecbc7d;p=vchess.git diff --git a/client/src/variants/Janggi.js b/client/src/variants/Janggi.js index 98660a4b..aecc8fe2 100644 --- a/client/src/variants/Janggi.js +++ b/client/src/variants/Janggi.js @@ -1,4 +1,5 @@ import { ChessRules, Move, PiPo } from "@/base_rules"; +import { randInt } from "@/utils/alea"; export class JanggiRules extends ChessRules { @@ -34,10 +35,6 @@ export class JanggiRules extends ChessRules { return false; } - static get LoseOnRepetition() { - return true; - } - static get ELEPHANT() { return "e"; } @@ -55,7 +52,7 @@ export class JanggiRules extends ChessRules { } getPpath(b) { - return "Jiangqi/" + b; + return "Janggi/" + b; } static get size() { @@ -109,9 +106,14 @@ export class JanggiRules extends ChessRules { // TODO: next "if" is mutually exclusive with the block above if (this.movesCount <= 1) { const firstRank = (this.movesCount == 0 ? 9 : 0); - const [initFile, destFile] = (this.subTurn == 1 ? [1, 2] : [7, 6]); - // Only option is knight / elephant swap: - if (x == firstRank && y == initFile) { + const initDestFile = new Map([[1, 2], [7, 6]]); + // Only option is knight --> elephant swap: + if ( + x == firstRank && + !!initDestFile.get(y) && + this.getPiece(x, y) == V.KNIGHT + ) { + const destFile = initDestFile.get(y); moves.push( new Move({ appear: [ @@ -590,6 +592,24 @@ export class JanggiRules extends ChessRules { if (move.vanish.length > 0) super.postUndo(move); } + getComputerMove() { + if (this.movesCount <= 1) { + // Special case: swap and pass at random + const moves1 = this.getAllValidMoves(); + const m1 = moves1[randInt(moves1.length)]; + this.play(m1); + if (m1.vanish.length == 0) { + this.undo(m1); + return m1; + } + const moves2 = this.getAllValidMoves(); + const m2 = moves2[randInt(moves2.length)]; + this.undo(m1); + return [m1, m2]; + } + return super.getComputerMove(); + } + getNotation(move) { if (move.vanish.length == 0) return "pass"; if (move.appear.length == 2) return "S"; //"swap"