ai.js
changeset 56 76d257640b7d
parent 54 2c389325d13b
child 57 94e1b2d0bd31
equal deleted inserted replaced
55:8ba9dc89be87 56:76d257640b7d
    46 // Blind weight random AI.
    46 // Blind weight random AI.
    47 ////////////////////////////////////////////////////////////////
    47 ////////////////////////////////////////////////////////////////
    48 
    48 
    49 ai.blindWeightRandom = function(brdEngine, cfg) {
    49 ai.blindWeightRandom = function(brdEngine, cfg) {
    50     this.brdEngine = brdEngine;
    50     this.brdEngine = brdEngine;
    51     this.cfg = this.cfg || {};
    51     this.cfg = ai.copyObj(ai.blindWeightRandom.bestCfg);
    52     var left = ai.blindWeightRandom.fixWeight(this.cfg.left);
    52     ai.copyObj(cfg, this.cfg);
    53     var right = ai.blindWeightRandom.fixWeight(this.cfg.right);
    53     var total = this.cfg.left + this.cfg.right + this.cfg.up + this.cfg.down;
    54     var up = ai.blindWeightRandom.fixWeight(this.cfg.up);
    54     this.threshold1 = this.cfg.left/total;
    55     var down = ai.blindWeightRandom.fixWeight(this.cfg.down);
    55     this.threshold2 = (this.cfg.left + this.cfg.down)/total;
    56     var total = left + right + up + down;
    56     this.threshold3 = (this.cfg.left + this.cfg.down + this.cfg.right)/total;
    57     this.threshold1 = left/total;
    57 }
    58     this.threshold2 = (left+down)/total;
    58 ai.blindWeightRandom.bestCfg = {left: 1, down: 10, right: 5, up: 1};
    59     this.threshold3 = (left+down+right)/total;
       
    60 }
       
    61 ai.blindWeightRandom.fixWeight = function(val) {
       
    62     val = val && parseFloat(v) || 1;
       
    63     if (val <= 0)
       
    64         val = 1;
       
    65     return val;
       
    66 }
       
    67 ai.blindWeightRandom.prototype.analyse = function(brd) {
    59 ai.blindWeightRandom.prototype.analyse = function(brd) {
    68     var origBrd = new this.brdEngine(brd);
    60     var origBrd = new this.brdEngine(brd);
    69     while (true) {
    61     while (true) {
    70         var rnd = Math.random();
    62         var rnd = Math.random();
    71         if (rnd < this.threshold1)
    63         if (rnd < this.threshold1)