ai.js
changeset 148 93c122e0ea90
parent 147 d4f9433e30b9
child 149 2839f8227a38
equal deleted inserted replaced
147:d4f9433e30b9 148:93c122e0ea90
   207     if (this.cfg.cornerBonus > 0 && brd.atCorner(max))
   207     if (this.cfg.cornerBonus > 0 && brd.atCorner(max))
   208         weight += this.cfg.cornerBonus;
   208         weight += this.cfg.cornerBonus;
   209     if (this.cfg.edgeBonus > 0 && brd.atEdge(max))
   209     if (this.cfg.edgeBonus > 0 && brd.atEdge(max))
   210         weight += this.cfg.edgeBonus;
   210         weight += this.cfg.edgeBonus;
   211     if (this.cfg.freeBonus > 0)
   211     if (this.cfg.freeBonus > 0)
   212         weight += this.cfg.freeBonus * brd.free();
   212         weight += this.cfg.freeBonus * brd.freeCnt();
   213     return weight;
   213     return weight;
   214 }
   214 }
   215 /** Select best direction for next step. */
   215 /** Select best direction for next step. */
   216 ai.OneStepAhead.prototype.analyse = function(brd2d) {
   216 ai.OneStepAhead.prototype.analyse = function(brd2d) {
   217     var origBrd = new this.brdEngine(brd2d);
   217     var origBrd = new this.brdEngine(brd2d);
   270     if (this.cfg.cornerBonus > 0 && brd.atCorner(max))
   270     if (this.cfg.cornerBonus > 0 && brd.atCorner(max))
   271         weight += this.cfg.cornerBonus;
   271         weight += this.cfg.cornerBonus;
   272     if (this.cfg.edgeBonus > 0 && brd.atEdge(max))
   272     if (this.cfg.edgeBonus > 0 && brd.atEdge(max))
   273         weight += this.cfg.edgeBonus;
   273         weight += this.cfg.edgeBonus;
   274     if (this.cfg.freeBonus > 0)
   274     if (this.cfg.freeBonus > 0)
   275         weight += this.cfg.freeBonus * brd.free();
   275         weight += this.cfg.freeBonus * brd.freeCnt();
   276     return weight;
   276     return weight;
   277 }
   277 }
   278 /** Select best direction for next step. */
   278 /** Select best direction for next step. */
   279 ai.StaticDeepMerges.prototype.analyse = function(brd2d) {
   279 ai.StaticDeepMerges.prototype.analyse = function(brd2d) {
   280     var origBrd = new this.brdEngine(brd2d);
   280     var origBrd = new this.brdEngine(brd2d);
   364         if (cfg.edgeBonus > 0)
   364         if (cfg.edgeBonus > 0)
   365             if (brd.atEdge(max))
   365             if (brd.atEdge(max))
   366                 score += cfg.edgeBonus;
   366                 score += cfg.edgeBonus;
   367     }
   367     }
   368     if (cfg.freeBonus > 0)
   368     if (cfg.freeBonus > 0)
   369         score += cfg.freeBonus * brd.free();
   369         score += cfg.freeBonus * brd.freeCnt();
   370     return score;
   370     return score;
   371 }
   371 }
   372 /** Select best direction for next step. */
   372 /** Select best direction for next step. */
   373 ai.expectimax.prototype.analyse = function(brd2d) {
   373 ai.expectimax.prototype.analyse = function(brd2d) {
   374     this.brdCache = new ai.brdCache();
   374     this.brdCache = new ai.brdCache();
   376     var nextBrd = new this.brdEngine();
   376     var nextBrd = new this.brdEngine();
   377     var maxW = -1;
   377     var maxW = -1;
   378     var bestDir;
   378     var bestDir;
   379     this.cleanup();
   379     this.cleanup();
   380     this.depthLimit = this.cfg.depth;
   380     this.depthLimit = this.cfg.depth;
   381     var free = origBrd.free();
   381     var freeCnt = origBrd.freeCnt();
   382     if (free >= 6)
   382     if (freeCnt >= 6)
   383         this.depthLimit = Math.min(this.depthLimit, 6 - free/3);
   383         this.depthLimit = Math.min(this.depthLimit, 6 - freeCnt/3);
   384     for (var i = 0; i < ai.dirs.length; i++) {
   384     for (var i = 0; i < ai.dirs.length; i++) {
   385         var dir = ai.dirs[i];
   385         var dir = ai.dirs[i];
   386         if (origBrd[dir](nextBrd)) {
   386         if (origBrd[dir](nextBrd)) {
   387             var w = this.evalFn(nextBrd, 1);
   387             var w = this.evalFn(nextBrd, 1);
   388             if (w > maxW) {
   388             if (w > maxW) {