# HG changeset patch # User Oleksandr Gavenko # Date 1411428253 -10800 # Node ID 4cc40a51742af68dd330d51e622c62f5ae9db677 # Parent b7b5e4a03e4be8cd5025336889c87824f43dbc81 Don't calculate max value if it isn't used. diff -r b7b5e4a03e4b -r 4cc40a51742a ai.js --- a/ai.js Tue Sep 23 02:06:32 2014 +0300 +++ b/ai.js Tue Sep 23 02:24:13 2014 +0300 @@ -324,19 +324,22 @@ ai.expectimax.bestCfg = {balance: .9, depth: 3, scoreCoef: 1, maxValCoef: 0, cornerBonus: 0, edgeBonus: 0, freeBonus: 0, weightThreshold: 10}; ai.expectimax.prototype.weight = function(brd) { var score = 0; - if (this.cfg.scoreCoef > 0) - score += this.cfg.scoreCoef * brd.score(); - var max = brd.max(); - if (this.cfg.maxValCoef > 0) - score += this.cfg.maxValCoef * max; - if (this.cfg.cornerBonus > 0) - if (brd.atCorner(max)) - score += this.cfg.cornerBonus; - if (this.cfg.edgeBonus > 0) - if (brd.atEdge(max)) - score += this.cfg.edgeBonus; - if (this.cfg.freeBonus > 0) - score += this.cfg.freeBonus * brd.free(); + var cfg = this.cfg; + if (cfg.scoreCoef > 0) + score += cfg.scoreCoef * brd.score(); + if (cfg.maxValCoef > 0 || cfg.cornerBonus > 0 || cfg.edgeBonus > 0) { + var max = brd.max(); + if (cfg.maxValCoef > 0) + score += cfg.maxValCoef * max; + if (cfg.cornerBonus > 0) + if (brd.atCorner(max)) + score += cfg.cornerBonus; + if (cfg.edgeBonus > 0) + if (brd.atEdge(max)) + score += cfg.edgeBonus; + if (cfg.freeBonus > 0) + score += cfg.freeBonus * brd.free(); + } return score; } ai.expectimax.prototype.analyse = function(brd) {