Refactoring: take proper name for function.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Fri, 26 Sep 2014 01:40:08 +0300
changeset 148 93c122e0ea90
parent 147 d4f9433e30b9
child 149 2839f8227a38
Refactoring: take proper name for function.
ai.js
board.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)) {
--- 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++;