From: Benjamin Auder Date: Fri, 1 Jan 2021 02:16:23 +0000 (+0100) Subject: Janggi: fix computer initial setup move X-Git-Url: https://git.auder.net/doc/html/css/img/current/gitweb.css?a=commitdiff_plain;h=ac4e2cabce7a0faeceaa646d31721161bd4a8cf4;p=vchess.git Janggi: fix computer initial setup move --- diff --git a/client/src/variants/Janggi.js b/client/src/variants/Janggi.js index 98660a4b..895e23ff 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 { @@ -590,6 +591,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"