X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FDoublemove2.js;h=d1afff8371db3fc353a3e6d2adf18edda5966d55;hb=5d75c82c70bcd4bcc43b65571231f0ba1b532b79;hp=26428f117266a5e7bec38f88346752cc5f4d73cd;hpb=ad030c7d24804fbfa06158e93d89a3f101d2c8b3;p=vchess.git diff --git a/client/src/variants/Doublemove2.js b/client/src/variants/Doublemove2.js index 26428f11..d1afff83 100644 --- a/client/src/variants/Doublemove2.js +++ b/client/src/variants/Doublemove2.js @@ -189,52 +189,24 @@ export class Doublemove2Rules extends ChessRules { }; } - // No alpha-beta here, just adapted min-max at depth 2(+1) + // No alpha-beta here, just adapted min-max at depth 1(+1) getComputerMove() { - const maxeval = V.INFINITY; const color = this.turn; - const oppCol = V.GetOppCol(this.turn); + const moves11 = this.getAllValidMoves(); + if (this.movesCount == 0) + // First white move at random: + return moves11[randInt(moves11.length)]; - // Search best (half) move for opponent turn - const getBestMoveEval = () => { - let score = this.getCurrentScore(); - if (score != "*") { - if (score == "1/2") return 0; - return maxeval * (score == "1-0" ? 1 : -1); - } - let moves = this.getAllValidMoves(); - let res = oppCol == "w" ? -maxeval : maxeval; - for (let m of moves) { - this.play(m); - score = this.getCurrentScore(); - // Now turn is oppCol,2 - if (score != "*") { - if (score == "1/2") - res = oppCol == "w" ? Math.max(res, 0) : Math.min(res, 0); - else { - // King captured - this.undo(m); - return maxeval * (score == "1-0" ? 1 : -1); - } - } - const evalPos = this.evalPosition(); - res = oppCol == "w" ? Math.max(res, evalPos) : Math.min(res, evalPos); - this.undo(m); - } - return res; - }; - - let moves11 = this.getAllValidMoves(); let doubleMoves = []; - // Rank moves using a min-max at depth 2(+1) + // Rank moves using a min-max at depth 2 for (let i = 0; i < moves11.length; i++) { this.play(moves11[i]); - let moves12 = this.getAllValidMoves(); + const moves12 = this.getAllValidMoves(); for (let j = 0; j < moves12.length; j++) { this.play(moves12[j]); doubleMoves.push({ moves: [moves11[i], moves12[j]], - eval: getBestMoveEval() + eval: this.evalPosition() }); this.undo(moves12[j]); }