Take max value at corner into account in first move.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Fri, 03 Jul 2015 23:45:55 -0500
changeset 171 6fce1391c2c0
parent 170 b2e6398d2b06
child 172 021cd45cb5ef
Take max value at corner into account in first move.
ai.js
--- a/ai.js	Fri Jul 03 23:45:05 2015 -0500
+++ b/ai.js	Fri Jul 03 23:45:55 2015 -0500
@@ -584,6 +584,14 @@
                 var tmpBrd = nextBrd.copy();
                 utility += this.play(tmpBrd, this.cfg.maxDepth);
             }
+            utility /= this.cfg.simulations;
+
+            var max = nextBrd.maxVal();
+            if (this.cfg.cornerBonus > 0 && nextBrd.atCorner(max))
+                utility += this.cfg.cornerBonus;
+            if (this.cfg.edgeBonus > 0 && nextBrd.atEdge(max))
+                utility += this.cfg.edgeBonus;
+
             if (utility > bestUtility) {
                 bestUtility = utility;
                 bestDir = dir;
@@ -608,17 +616,7 @@
     return -1;
 }
 ai.MonteCarlo.prototype.evalFn = function(brd) {
-    var utility = 0;
-    if (this.cfg.freeBonus > 0)
-        utility += this.cfg.freeBonus * brd.freeCnt();
-    var max = brd.maxVal();
-    if (max > 7) {
-        if (this.cfg.cornerBonus > 0 && brd.atCorner(max))
-            utility += this.cfg.cornerBonus;
-        if (this.cfg.edgeBonus > 0 && brd.atEdge(max))
-            utility += this.cfg.edgeBonus;
-    }
-    return utility;
+    return this.cfg.freeBonus * brd.freeCnt();
 }
 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */
 ai.MonteCarlo.prototype.cleanup = function() {