# HG changeset patch # User Oleksandr Gavenko # Date 1411684808 -10800 # Node ID 93c122e0ea90ea9e1fd45be8796b17a35109c2d1 # Parent d4f9433e30b954233031b604f31330f50ca44d8d Refactoring: take proper name for function. diff -r d4f9433e30b9 -r 93c122e0ea90 ai.js --- a/ai.js Fri Sep 26 01:33:34 2014 +0300 +++ b/ai.js Fri Sep 26 01:40:08 2014 +0300 @@ -209,7 +209,7 @@ if (this.cfg.edgeBonus > 0 && brd.atEdge(max)) weight += this.cfg.edgeBonus; if (this.cfg.freeBonus > 0) - weight += this.cfg.freeBonus * brd.free(); + weight += this.cfg.freeBonus * brd.freeCnt(); return weight; } /** Select best direction for next step. */ @@ -272,7 +272,7 @@ if (this.cfg.edgeBonus > 0 && brd.atEdge(max)) weight += this.cfg.edgeBonus; if (this.cfg.freeBonus > 0) - weight += this.cfg.freeBonus * brd.free(); + weight += this.cfg.freeBonus * brd.freeCnt(); return weight; } /** Select best direction for next step. */ @@ -366,7 +366,7 @@ score += cfg.edgeBonus; } if (cfg.freeBonus > 0) - score += cfg.freeBonus * brd.free(); + score += cfg.freeBonus * brd.freeCnt(); return score; } /** Select best direction for next step. */ @@ -378,9 +378,9 @@ var bestDir; this.cleanup(); this.depthLimit = this.cfg.depth; - var free = origBrd.free(); - if (free >= 6) - this.depthLimit = Math.min(this.depthLimit, 6 - free/3); + var freeCnt = origBrd.freeCnt(); + if (freeCnt >= 6) + this.depthLimit = Math.min(this.depthLimit, 6 - freeCnt/3); for (var i = 0; i < ai.dirs.length; i++) { var dir = ai.dirs[i]; if (origBrd[dir](nextBrd)) { diff -r d4f9433e30b9 -r 93c122e0ea90 board.js --- a/board.js Fri Sep 26 01:33:34 2014 +0300 +++ b/board.js Fri Sep 26 01:40:08 2014 +0300 @@ -50,7 +50,7 @@ return brd; } /** Number of free cell. */ -BoardArr.prototype.free = function() { +BoardArr.prototype.freeCnt = function() { var cnt = 0; for (var i = 0; i < 16; i++) if (this.brd[i] === 0) @@ -156,7 +156,7 @@ return brd; } /** Number of free cell. */ -BoardArr2d.prototype.free = function() { +BoardArr2d.prototype.freeCnt = function() { var cnt = 0; for (var i = 0; i < 4; i++) for (var j = 0; j < 4; j++) @@ -869,7 +869,7 @@ return brd; } /** Number of free cell. */ -BoardObj.prototype.free = function() { +BoardObj.prototype.freeCnt = function() { var cnt = 0; var brd = this.brd; if (brd.aa === 0) cnt++; if (brd.ab === 0) cnt++; if (brd.ac === 0) cnt++; if (brd.ad === 0) cnt++;