Merge config with best settings.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Thu, 11 Sep 2014 20:01:40 +0300
changeset 56 76d257640b7d
parent 55 8ba9dc89be87
child 57 94e1b2d0bd31
Merge config with best settings.
ai.js
--- a/ai.js	Thu Sep 11 20:01:09 2014 +0300
+++ b/ai.js	Thu Sep 11 20:01:40 2014 +0300
@@ -48,22 +48,14 @@
 
 ai.blindWeightRandom = function(brdEngine, cfg) {
     this.brdEngine = brdEngine;
-    this.cfg = this.cfg || {};
-    var left = ai.blindWeightRandom.fixWeight(this.cfg.left);
-    var right = ai.blindWeightRandom.fixWeight(this.cfg.right);
-    var up = ai.blindWeightRandom.fixWeight(this.cfg.up);
-    var down = ai.blindWeightRandom.fixWeight(this.cfg.down);
-    var total = left + right + up + down;
-    this.threshold1 = left/total;
-    this.threshold2 = (left+down)/total;
-    this.threshold3 = (left+down+right)/total;
+    this.cfg = ai.copyObj(ai.blindWeightRandom.bestCfg);
+    ai.copyObj(cfg, this.cfg);
+    var total = this.cfg.left + this.cfg.right + this.cfg.up + this.cfg.down;
+    this.threshold1 = this.cfg.left/total;
+    this.threshold2 = (this.cfg.left + this.cfg.down)/total;
+    this.threshold3 = (this.cfg.left + this.cfg.down + this.cfg.right)/total;
 }
-ai.blindWeightRandom.fixWeight = function(val) {
-    val = val && parseFloat(v) || 1;
-    if (val <= 0)
-        val = 1;
-    return val;
-}
+ai.blindWeightRandom.bestCfg = {left: 1, down: 10, right: 5, up: 1};
 ai.blindWeightRandom.prototype.analyse = function(brd) {
     var origBrd = new this.brdEngine(brd);
     while (true) {