ai.js
changeset 122 4cc40a51742a
parent 118 7e93fb8136a3
child 124 4a2551dd179d
equal deleted inserted replaced
121:b7b5e4a03e4b 122:4cc40a51742a
   322         this.cfg.depth = ai.expectimax.bestCfg.depth;
   322         this.cfg.depth = ai.expectimax.bestCfg.depth;
   323 }
   323 }
   324 ai.expectimax.bestCfg = {balance: .9, depth: 3, scoreCoef: 1, maxValCoef: 0, cornerBonus: 0, edgeBonus: 0, freeBonus: 0, weightThreshold: 10};
   324 ai.expectimax.bestCfg = {balance: .9, depth: 3, scoreCoef: 1, maxValCoef: 0, cornerBonus: 0, edgeBonus: 0, freeBonus: 0, weightThreshold: 10};
   325 ai.expectimax.prototype.weight = function(brd) {
   325 ai.expectimax.prototype.weight = function(brd) {
   326     var score = 0;
   326     var score = 0;
   327     if (this.cfg.scoreCoef > 0)
   327     var cfg = this.cfg;
   328         score += this.cfg.scoreCoef * brd.score();
   328     if (cfg.scoreCoef > 0)
   329     var max = brd.max();
   329         score += cfg.scoreCoef * brd.score();
   330     if (this.cfg.maxValCoef > 0)
   330     if (cfg.maxValCoef > 0 || cfg.cornerBonus > 0 || cfg.edgeBonus > 0) {
   331         score += this.cfg.maxValCoef * max;
   331         var max = brd.max();
   332     if (this.cfg.cornerBonus > 0)
   332         if (cfg.maxValCoef > 0)
   333         if (brd.atCorner(max))
   333             score += cfg.maxValCoef * max;
   334             score += this.cfg.cornerBonus;
   334         if (cfg.cornerBonus > 0)
   335     if (this.cfg.edgeBonus > 0)
   335             if (brd.atCorner(max))
   336         if (brd.atEdge(max))
   336                 score += cfg.cornerBonus;
   337             score += this.cfg.edgeBonus;
   337         if (cfg.edgeBonus > 0)
   338     if (this.cfg.freeBonus > 0)
   338             if (brd.atEdge(max))
   339         score += this.cfg.freeBonus * brd.free();
   339                 score += cfg.edgeBonus;
       
   340         if (cfg.freeBonus > 0)
       
   341             score += cfg.freeBonus * brd.free();
       
   342     }
   340     return score;
   343     return score;
   341 }
   344 }
   342 ai.expectimax.prototype.analyse = function(brd) {
   345 ai.expectimax.prototype.analyse = function(brd) {
   343     var origBrd = new this.brdEngine(brd);
   346     var origBrd = new this.brdEngine(brd);
   344     var nextBrd = new this.brdEngine();
   347     var nextBrd = new this.brdEngine();