X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FDoublemove1.js;h=c30ad0cf75ae8ec69cb3af53539d136f2d5abaa8;hb=032ecd58543d1182b41da0c45b272e99a3014ad8;hp=7d1ee4dc5bc4b013b751645b3c88043abc58e897;hpb=b406466b0f0ce67451f1718053e5f5691d6507fb;p=vchess.git diff --git a/client/src/variants/Doublemove1.js b/client/src/variants/Doublemove1.js index 7d1ee4dc..c30ad0cf 100644 --- a/client/src/variants/Doublemove1.js +++ b/client/src/variants/Doublemove1.js @@ -201,7 +201,7 @@ export class Doublemove1Rules extends ChessRules { return res; }; - let moves11 = this.getAllValidMoves(); + const moves11 = this.getAllValidMoves(); let doubleMoves = []; // Rank moves using a min-max at depth 2 for (let i = 0; i < moves11.length; i++) { @@ -209,13 +209,14 @@ export class Doublemove1Rules extends ChessRules { if (this.turn != color) { // We gave check with last move: search the best opponent move doubleMoves.push({ moves: [moves11[i]], eval: getBestMoveEval() }); - } else { + } + else { let 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: getBestMoveEval() + 0.05 - Math.random() / 10 }); this.undo(moves12[j]); } @@ -223,6 +224,8 @@ export class Doublemove1Rules extends ChessRules { this.undo(moves11[i]); } + // TODO: array + sort + candidates logic not required when adding small + // fluctuations to the eval function (could also be generalized). doubleMoves.sort((a, b) => { return (color == "w" ? 1 : -1) * (b.eval - a.eval); }); @@ -234,7 +237,6 @@ export class Doublemove1Rules extends ChessRules { ) { candidates.push(i); } - const selected = doubleMoves[randInt(candidates.length)].moves; if (selected.length == 1) return selected[0]; return selected;