X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fbase_rules.js;h=a8f24893558a660f3b305210beb280aa2bdecc65;hb=e82cd97976a6c7707467a384f7d6ca1daa9a0772;hp=5c1ef97c08563f0ac7e0bc3ffee9730a37b75150;hpb=9234226104764b91df9d677fb360ad538b98510c;p=vchess.git diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index 5c1ef97c..a8f24893 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -824,7 +824,6 @@ class ChessRules // NOTE: works also for extinction chess because depth is 3... getComputerMove() { - this.shouldReturn = false; const maxeval = VariantRules.INFINITY; const color = this.turn; // Some variants may show a bigger moves list to the human (Switching), @@ -889,14 +888,17 @@ class ChessRules candidates.push(j); let currentBest = moves1[_.sample(candidates, 1)]; + // From here, depth >= 3: may take a while, so we control time + const timeStart = Date.now(); + // Skip depth 3+ if we found a checkmate (or if we are checkmated in 1...) if (VariantRules.SEARCH_DEPTH >= 3 && Math.abs(moves1[0].eval) < VariantRules.THRESHOLD_MATE) { for (let i=0; i= 5000) //more than 5 seconds + return currentBest; //depth 2 at least this.play(moves1[i]); // 0.1 * oldEval : heuristic to avoid some bad moves (not all...) moves1[i].eval = 0.1*moves1[i].eval +