ai.js
changeset 164 cdde49008500
parent 163 87479ae56889
child 169 5a17638f0dca
--- a/ai.js	Thu Jul 02 03:03:10 2015 +0300
+++ b/ai.js	Fri Jul 03 10:01:02 2015 +0300
@@ -568,7 +568,7 @@
     if (!this.cfg.maxDepth || this.cfg.maxDepth <= 0 || 20 <= this.cfg.maxDepth)
         this.cfg.maxDepth = ai.MonteCarlo.bestCfg.maxDepth;
 }
-ai.MonteCarlo.bestCfg = {simulations: 1000, maxDepth: 20};
+ai.MonteCarlo.bestCfg = {simulations: 1000, maxDepth: 20, cornerBonus: 0, edgeBonus: 0, freeBonus: 0};
 /** Select best direction for next step. */
 ai.MonteCarlo.prototype.analyse = function(brd2d) {
     var origBrd = new this.brd(brd2d);
@@ -594,7 +594,7 @@
 }
 ai.MonteCarlo.prototype.play = function(brd, depth) {
     if (depth <= 0) {
-        return brd.freeCnt();
+        return this.evalFn(brd);
     }
     brd.rnd(1);
     var dirs = ai.randDirs();
@@ -607,6 +607,19 @@
     }
     return -1;
 }
+ai.MonteCarlo.prototype.evalFn = function(brd) {
+    var w = 0;
+    if (this.cfg.freeBonus > 0)
+        w += this.cfg.freeBonus * brd.freeCnt();
+    var max = brd.maxVal();
+    if (max > 7) {
+        if (this.cfg.cornerBonus > 0 && brd.atCorner(max))
+            w += this.cfg.cornerBonus;
+        if (this.cfg.edgeBonus > 0 && brd.atEdge(max))
+            w += this.cfg.edgeBonus;
+    }
+    return w;
+}
 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */
 ai.MonteCarlo.prototype.cleanup = function() {
 }