Add merges function names. Refactoring: Rename function.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sat, 27 Sep 2014 00:12:54 +0300
changeset 152 07814b979a8a
parent 151 bb5994be7eda
child 153 5a2d38d67319
Add merges function names. Refactoring: Rename function.
ai.js
--- a/ai.js	Sat Sep 27 00:03:51 2014 +0300
+++ b/ai.js	Sat Sep 27 00:12:54 2014 +0300
@@ -6,8 +6,10 @@
 var ai = {};
 /** Directions. @constant */
 ai.dirs = ["up", "right", "down", "left"];
-/** Possible direction function names. @constant */
-ai.canDirs = ["canUp", "canRight", "canDown", "canLeft"];
+/** Possible direction check function names ordered by ai.dirs. @constant */
+ai.canFn = ["canUp", "canRight", "canDown", "canLeft"];
+/** Possible merge function names ordered by ai.dirs. @constant */
+ai.mergeFn = ["upMerges", "rightMerges", "downMerges", "leftMerges"];
 
 /** Create empty 'to' if argument missing. */
 ai.copyObj = function(from, to) {
@@ -64,7 +66,7 @@
     var origBrd = new this.brdEngine(brd2d);
     while (true) {
         var rnd = Math.floor(Math.random()*4);
-        if (origBrd[ai.canDirs[rnd]]())
+        if (origBrd[ai.canFn[rnd]]())
             return ai.dirs[rnd];
     }
 }
@@ -113,7 +115,7 @@
             var dir = 2;
         else
             var dir = 3;
-        if (origBrd[ai.canDirs[dir]]())
+        if (origBrd[ai.canFn[dir]]())
             return ai.dirs[dir];
     }
 }
@@ -144,7 +146,7 @@
     this.cfg.clockwise = this.cfg.clockwise || false;
 }
 ai.BlindCycle.dirs = ["left", "down", "right", "up"];
-ai.BlindCycle.canDirs = ["canLeft", "canDown", "canRight", "canUp"];
+ai.BlindCycle.canFn = ["canLeft", "canDown", "canRight", "canUp"];
 ai.BlindCycle.prototype.nextDir = function(dir) {
     if (this.cfg.clockwise)
         return (dir + (4-1)) % 4;
@@ -158,7 +160,7 @@
     if (!this.cfg.whilePossible)
         this.prevDir = this.nextDir(this.prevDir);
     while (true) {
-        if (origBrd[ai.BlindCycle.canDirs[this.prevDir]]())
+        if (origBrd[ai.BlindCycle.canFn[this.prevDir]]())
             return ai.BlindCycle.dirs[this.prevDir];
         this.prevDir = this.nextDir(this.prevDir);
     }