# HG changeset patch # User Oleksandr Gavenko # Date 1435906862 -10800 # Node ID cdde490085008b672fcde33db7e407a886a85df4 # Parent 87479ae5688963d6314cf36d515e3f3ef2574de3 Add more options to Monte Carlo heuristics. diff -r 87479ae56889 -r cdde49008500 2048.html --- a/2048.html Thu Jul 02 03:03:10 2015 +0300 +++ b/2048.html Fri Jul 03 10:01:02 2015 +0300 @@ -298,7 +298,16 @@ depth limit
- simulations + simulations +
+
+ max value at corner bonus +
+
+ max value at edge bonus +
+
+ free cell coefficient
diff -r 87479ae56889 -r cdde49008500 ai.js --- a/ai.js Thu Jul 02 03:03:10 2015 +0300 +++ b/ai.js Fri Jul 03 10:01:02 2015 +0300 @@ -568,7 +568,7 @@ if (!this.cfg.maxDepth || this.cfg.maxDepth <= 0 || 20 <= this.cfg.maxDepth) this.cfg.maxDepth = ai.MonteCarlo.bestCfg.maxDepth; } -ai.MonteCarlo.bestCfg = {simulations: 1000, maxDepth: 20}; +ai.MonteCarlo.bestCfg = {simulations: 1000, maxDepth: 20, cornerBonus: 0, edgeBonus: 0, freeBonus: 0}; /** Select best direction for next step. */ ai.MonteCarlo.prototype.analyse = function(brd2d) { var origBrd = new this.brd(brd2d); @@ -594,7 +594,7 @@ } ai.MonteCarlo.prototype.play = function(brd, depth) { if (depth <= 0) { - return brd.freeCnt(); + return this.evalFn(brd); } brd.rnd(1); var dirs = ai.randDirs(); @@ -607,6 +607,19 @@ } return -1; } +ai.MonteCarlo.prototype.evalFn = function(brd) { + var w = 0; + if (this.cfg.freeBonus > 0) + w += this.cfg.freeBonus * brd.freeCnt(); + var max = brd.maxVal(); + if (max > 7) { + if (this.cfg.cornerBonus > 0 && brd.atCorner(max)) + w += this.cfg.cornerBonus; + if (this.cfg.edgeBonus > 0 && brd.atEdge(max)) + w += this.cfg.edgeBonus; + } + return w; +} /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */ ai.MonteCarlo.prototype.cleanup = function() { }