X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FDoublemove1.js;h=c30ad0cf75ae8ec69cb3af53539d136f2d5abaa8;hp=7d1ee4dc5bc4b013b751645b3c88043abc58e897;hb=bc0b9205e41c5db0552e4ccf060b945342e36ed0;hpb=978fa11c8c9838018124a36ec14e06856d948d1e 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;