equal
deleted
inserted
replaced
582 var utility = 0; |
582 var utility = 0; |
583 for (var gameCnt = this.cfg.simulations; gameCnt > 0; gameCnt--) { |
583 for (var gameCnt = this.cfg.simulations; gameCnt > 0; gameCnt--) { |
584 var tmpBrd = nextBrd.copy(); |
584 var tmpBrd = nextBrd.copy(); |
585 utility += this.play(tmpBrd, this.cfg.maxDepth); |
585 utility += this.play(tmpBrd, this.cfg.maxDepth); |
586 } |
586 } |
|
587 utility /= this.cfg.simulations; |
|
588 |
|
589 var max = nextBrd.maxVal(); |
|
590 if (this.cfg.cornerBonus > 0 && nextBrd.atCorner(max)) |
|
591 utility += this.cfg.cornerBonus; |
|
592 if (this.cfg.edgeBonus > 0 && nextBrd.atEdge(max)) |
|
593 utility += this.cfg.edgeBonus; |
|
594 |
587 if (utility > bestUtility) { |
595 if (utility > bestUtility) { |
588 bestUtility = utility; |
596 bestUtility = utility; |
589 bestDir = dir; |
597 bestDir = dir; |
590 } |
598 } |
591 } |
599 } |
606 } |
614 } |
607 } |
615 } |
608 return -1; |
616 return -1; |
609 } |
617 } |
610 ai.MonteCarlo.prototype.evalFn = function(brd) { |
618 ai.MonteCarlo.prototype.evalFn = function(brd) { |
611 var utility = 0; |
619 return this.cfg.freeBonus * brd.freeCnt(); |
612 if (this.cfg.freeBonus > 0) |
|
613 utility += this.cfg.freeBonus * brd.freeCnt(); |
|
614 var max = brd.maxVal(); |
|
615 if (max > 7) { |
|
616 if (this.cfg.cornerBonus > 0 && brd.atCorner(max)) |
|
617 utility += this.cfg.cornerBonus; |
|
618 if (this.cfg.edgeBonus > 0 && brd.atEdge(max)) |
|
619 utility += this.cfg.edgeBonus; |
|
620 } |
|
621 return utility; |
|
622 } |
620 } |
623 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */ |
621 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */ |
624 ai.MonteCarlo.prototype.cleanup = function() { |
622 ai.MonteCarlo.prototype.cleanup = function() { |
625 } |
623 } |
626 |
624 |