From: Benjamin Auder Date: Wed, 29 Apr 2020 08:48:42 +0000 (+0200) Subject: Improve Chakart computer play X-Git-Url: https://git.auder.net/doc/html/vendor/img/css/%24%7BgetWhatsApp%28link%29%7D?a=commitdiff_plain;h=13ce1e9b92741e6dc1c0241bb001272090bb0e15;p=vchess.git Improve Chakart computer play --- diff --git a/client/src/variants/Chakart.js b/client/src/variants/Chakart.js index 1c7225c7..e423fa6f 100644 --- a/client/src/variants/Chakart.js +++ b/client/src/variants/Chakart.js @@ -1316,10 +1316,45 @@ export class ChakartRules extends ChessRules { return moves; } + static get VALUES() { + return Object.assign( + {}, + ChessRules.VALUES, + { + s: 1, + u: 5, + o: 3, + c: 3, + t: 9, + l: 1000, + e: 0, + d: 0, + w: 0, + m: 0 + } + ); + } + + static get SEARCH_DEPTH() { + return 1; + } + getComputerMove() { - // Random mover: const moves = this.getAllValidMoves(); - let move1 = moves[randInt(moves.length)]; + // Split into "normal" and "random" moves: + // (Next splitting condition is OK because cannot take self object + // without a banana or bomb on the way). + const deterministicMoves = moves.filter(m => { + return m.vanish.every(a => a.c != 'a' || a.p == V.MUSHROOM); + }); + const randomMoves = moves.filter(m => { + return m.vanish.some(a => a.c == 'a' && a.p != V.MUSHROOM); + }); + if (Math.random() < deterministicMoves.length / randomMoves.length) + // Play a deterministic one: capture king or material if possible + return super.getComputerMove(deterministicMoves); + // Play a random effect move, at random: + let move1 = randomMoves[randInt(moves.length)]; this.play(move1); let move2 = undefined; if (this.subTurn == 2) {