Increase depth limit.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Wed, 24 Sep 2014 15:25:11 +0300
changeset 126 e634761d0432
parent 125 fa1f44d3888d
child 127 4cc0421184ac
Increase depth limit.
ai.js
--- a/ai.js	Wed Sep 24 14:57:53 2014 +0300
+++ b/ai.js	Wed Sep 24 15:25:11 2014 +0300
@@ -318,10 +318,10 @@
         this.cfg.balance = ai.expectimax.bestCfg.balance;
     if ( this.cfg.balance > 1)
         this.cfg.balance = 1;
-    if (!this.cfg.depth || this.cfg.depth < 0 || 8 <= this.cfg.depth)
+    if (!this.cfg.depth || this.cfg.depth < 0 || 9 <= this.cfg.depth)
         this.cfg.depth = ai.expectimax.bestCfg.depth;
 }
-ai.expectimax.bestCfg = {balance: .9, depth: 3, scoreCoef: 1, maxValCoef: 0, cornerBonus: 0, edgeBonus: 0, freeBonus: 0};
+ai.expectimax.bestCfg = {balance: .9, depth: 5, scoreCoef: 1, maxValCoef: 0, cornerBonus: 0, edgeBonus: 0, freeBonus: 0};
 ai.expectimax.prototype.weight = function(brd) {
     var score = 0;
     var cfg = this.cfg;
@@ -348,6 +348,10 @@
     var maxW = -1;
     var bestDir;
     this.cleanup();
+    this.depthLimit = this.cfg.depth;
+    var free = origBrd.free();
+    if (free >= 6)
+        this.depthLimit = Math.min(this.depthLimit, 6 - free/3);
     for (var i = 0; i < ai.dirs.length; i++) {
         var dir = ai.dirs[i];
         if (origBrd[dir](nextBrd)) {
@@ -362,7 +366,7 @@
     return bestDir;
 }
 ai.expectimax.prototype.evalFn = function(brd, depth) {
-    if (depth >= this.cfg.depth)
+    if (depth >= this.depthLimit)
         return this.weight(brd);
     if (this.cache[depth]) {
         var cache = this.cache[depth];