changeset 171:6fce1391c2c0

Take max value at corner into account in first move.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Fri, 03 Jul 2015 23:45:55 -0500
parents b2e6398d2b06
children 021cd45cb5ef
files ai.js
diffstat 1 files changed, 9 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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() {