# HG changeset patch # User Oleksandr Gavenko # Date 1411765974 -10800 # Node ID 07814b979a8afffda465d5bdc95b66fa205faa70 # Parent bb5994be7edab972f140d4b75d43fba26e40db8a Add merges function names. Refactoring: Rename function. diff -r bb5994be7eda -r 07814b979a8a 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); }