# HG changeset patch # User Oleksandr Gavenko # Date 1435985155 18000 # Node ID 6fce1391c2c04fe7857ae5043d04f2f6a6a6629b # Parent b2e6398d2b065f36fb024f84e7ab3bbe614d7b97 Take max value at corner into account in first move. diff -r b2e6398d2b06 -r 6fce1391c2c0 ai.js --- a/ai.js Fri Jul 03 23:45:05 2015 -0500 +++ b/ai.js Fri Jul 03 23:45:55 2015 -0500 @@ -584,6 +584,14 @@ var tmpBrd = nextBrd.copy(); utility += this.play(tmpBrd, this.cfg.maxDepth); } + utility /= this.cfg.simulations; + + var max = nextBrd.maxVal(); + if (this.cfg.cornerBonus > 0 && nextBrd.atCorner(max)) + utility += this.cfg.cornerBonus; + if (this.cfg.edgeBonus > 0 && nextBrd.atEdge(max)) + utility += this.cfg.edgeBonus; + if (utility > bestUtility) { bestUtility = utility; bestDir = dir; @@ -608,17 +616,7 @@ return -1; } ai.MonteCarlo.prototype.evalFn = function(brd) { - var utility = 0; - if (this.cfg.freeBonus > 0) - utility += this.cfg.freeBonus * brd.freeCnt(); - var max = brd.maxVal(); - if (max > 7) { - if (this.cfg.cornerBonus > 0 && brd.atCorner(max)) - utility += this.cfg.cornerBonus; - if (this.cfg.edgeBonus > 0 && brd.atEdge(max)) - utility += this.cfg.edgeBonus; - } - return utility; + return this.cfg.freeBonus * brd.freeCnt(); } /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */ ai.MonteCarlo.prototype.cleanup = function() {