Capitilize AI names.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Mon, 15 Sep 2014 02:54:09 +0300
changeset 59 28613a54c71c
parent 58 847ed98813d1
child 60 434fa4b14209
Capitilize AI names.
2048.html
ai.js
--- a/2048.html	Mon Sep 15 02:50:32 2014 +0300
+++ b/2048.html	Mon Sep 15 02:54:09 2014 +0300
@@ -559,29 +559,29 @@
 
     ui.ai.algList = {
       "ai-blind-random": function() {
-        return new ai.blindRandom(ui.brdEngine);
+        return new ai.BlindRandom(ui.brdEngine);
       },
       "ai-blind-weight-random": function(aiDom) {
         var cfg = {};
         ui.ai.parseCfg(aiDom, cfg);
-        return new ai.blindWeightRandom(ui.brdEngine, cfg);
+        return new ai.BlindWeightRandom(ui.brdEngine, cfg);
       },
       "ai-blind-cycle": function(aiDom) {
         var cfg = {};
         cfg.clockwise = aiDom.querySelectorAll("input[name='clockwise']")[0].checked;
         cfg.whilePossible = aiDom.querySelectorAll("input[name='whilePossible']")[0].checked;
-        return new ai.blindCycle(ui.brdEngine, cfg);
+        return new ai.BlindCycle(ui.brdEngine, cfg);
       },
       "ai-one-step-deep": function(aiDom) {
         var cfg = {};
         ui.ai.parseCfg(aiDom, cfg);
-        return new ai.oneStepDeep(ui.brdEngine, cfg);
+        return new ai.OneStepDeep(ui.brdEngine, cfg);
       },
       "ai-deep-max-score": function() {
-        return new ai.deepMaxScore(ui.brdEngine);
+        return new ai.DeepMaxScore(ui.brdEngine);
       },
       "ai-deep-max-score-corner": function() {
-        return new ai.deepMaxScoreCorner(ui.brdEngine);
+        return new ai.DeepMaxScoreCorner(ui.brdEngine);
       },
       "ai-expectimax": function() {
         return new ai.expectimax(ui.brdEngine);
--- a/ai.js	Mon Sep 15 02:50:32 2014 +0300
+++ b/ai.js	Mon Sep 15 02:54:09 2014 +0300
@@ -34,10 +34,10 @@
 /** Blind random AI.
  * @param {Board} brdEngine  board engine from board.js
  * @constructor */
-ai.blindRandom = function(brdEngine) {
+ai.BlindRandom = function(brdEngine) {
     this.brdEngine = brdEngine;
 }
-ai.blindRandom.prototype.analyse = function(brd) {
+ai.BlindRandom.prototype.analyse = function(brd) {
     var origBrd = new this.brdEngine(brd);
     while (true) {
         var rnd = Math.floor(Math.random()*4);
@@ -46,7 +46,7 @@
     }
 }
 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */
-ai.blindRandom.prototype.cleanup = function() { }
+ai.BlindRandom.prototype.cleanup = function() { }
 
 
 
@@ -67,9 +67,9 @@
  * @param {Board} brdEngine  board engine from board.js
  * @param {ai.BlindWeightRandom.cfg} cfg  configuration settings
  * @constructor */
-ai.blindWeightRandom = function(brdEngine, cfg) {
+ai.BlindWeightRandom = function(brdEngine, cfg) {
     this.brdEngine = brdEngine;
-    this.cfg = ai.copyObj(ai.blindWeightRandom.bestCfg);
+    this.cfg = ai.copyObj(ai.BlindWeightRandom.bestCfg);
     ai.copyObj(cfg, this.cfg);
     var total = this.cfg.left + this.cfg.right + this.cfg.up + this.cfg.down;
     this.threshold1 = this.cfg.left/total;
@@ -78,8 +78,8 @@
 }
 /** @{link ai.BlindWeightRandom.cfg}
     @namespace */
-ai.blindWeightRandom.bestCfg = { left: 1, down: 10, right: 5, up: 1 };
-ai.blindWeightRandom.prototype.analyse = function(brd) {
+ai.BlindWeightRandom.bestCfg = { left: 1, down: 10, right: 5, up: 1 };
+ai.BlindWeightRandom.prototype.analyse = function(brd) {
     var origBrd = new this.brdEngine(brd);
     while (true) {
         var rnd = Math.random();
@@ -96,7 +96,7 @@
     }
 }
 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */
-ai.blindWeightRandom.prototype.cleanup = function() { }
+ai.BlindWeightRandom.prototype.cleanup = function() { }
 
 
 
@@ -115,33 +115,33 @@
  * @param {Board} brdEngine  board engine from board.js
  * @param {ai.BlindCycle.cfg} cfg  configuration settings
  * @constructor */
-ai.blindCycle = function(brdEngine, cfg) {
+ai.BlindCycle = function(brdEngine, cfg) {
     this.brdEngine = brdEngine;
     this.cfg = cfg || {};
     this.cfg.whilePossible = this.cfg.whilePossible || false;
     this.cfg.clockwise = this.cfg.clockwise || false;
 }
-ai.blindCycle.dirs = ["left", "down", "right", "up"];
-ai.blindCycle.canDirs = ["canLeft", "canDown", "canRight", "canUp"];
-ai.blindCycle.prototype.nextDir = function(dir) {
+ai.BlindCycle.dirs = ["left", "down", "right", "up"];
+ai.BlindCycle.canDirs = ["canLeft", "canDown", "canRight", "canUp"];
+ai.BlindCycle.prototype.nextDir = function(dir) {
     if (this.cfg.clockwise)
         return (dir + (4-1)) % 4;
     else
         return (dir + 1) % 4;
 }
-ai.blindCycle.prototype.analyse = function(brd) {
+ai.BlindCycle.prototype.analyse = function(brd) {
     var origBrd = new this.brdEngine(brd);
     this.prevDir = this.prevDir || 0;
     if (!this.cfg.whilePossible)
         this.prevDir = this.nextDir(this.prevDir);
     while (true) {
-        if (origBrd[ai.blindCycle.canDirs[this.prevDir]]())
-            return ai.blindCycle.dirs[this.prevDir];
+        if (origBrd[ai.BlindCycle.canDirs[this.prevDir]]())
+            return ai.BlindCycle.dirs[this.prevDir];
         this.prevDir = this.nextDir(this.prevDir);
     }
 }
 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */
-ai.blindCycle.prototype.cleanup = function() {
+ai.BlindCycle.prototype.cleanup = function() {
     delete this.prevDir;
 }
 
@@ -168,13 +168,13 @@
  * @param {Board} brdEngine  board engine from board.js
  * @param {ai.OneStepDeep.cfg} cfg  configuration settings
  * @constructor */
-ai.oneStepDeep = function(brdEngine, cfg) {
+ai.OneStepDeep = function(brdEngine, cfg) {
     this.brdEngine = brdEngine;
-    this.cfg = ai.copyObj(ai.oneStepDeep.bestCfg);
+    this.cfg = ai.copyObj(ai.OneStepDeep.bestCfg);
     ai.copyObj(cfg, this.cfg);
 }
-ai.oneStepDeep.bestCfg = {scoreCoef: 1, maxValCoef: 0, cornerBonus: 0, edgeBonus: 0, freeBonus: 0};
-ai.oneStepDeep.prototype.weight = function(brd) {
+ai.OneStepDeep.bestCfg = {scoreCoef: 1, maxValCoef: 0, cornerBonus: 0, edgeBonus: 0, freeBonus: 0};
+ai.OneStepDeep.prototype.weight = function(brd) {
     var weight = 0;
     if (this.cfg.scoreCoef > 0)
         weight += this.cfg.scoreCoef * brd.score();
@@ -189,7 +189,7 @@
         weight += this.cfg.freeBonus * brd.free();
     return weight;
 }
-ai.oneStepDeep.prototype.analyse = function(brd) {
+ai.OneStepDeep.prototype.analyse = function(brd) {
     var origBrd = new this.brdEngine(brd);
     var nextBrd = new this.brdEngine();
     var maxWeight = -1;
@@ -207,7 +207,7 @@
     return bestDir;
 }
 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */
-ai.oneStepDeep.prototype.cleanup = function() { }
+ai.OneStepDeep.prototype.cleanup = function() { }
 
 
 
@@ -218,10 +218,10 @@
 /** N level deep on score value without random simulation.
  * @param {Board} brdEngine  board engine from board.js
  * @constructor */
-ai.deepMaxScore = function(brdEngine) {
+ai.DeepMaxScore = function(brdEngine) {
     this.brdEngine = brdEngine;
 }
-ai.deepMaxScore.prototype.analyse = function(brd) {
+ai.DeepMaxScore.prototype.analyse = function(brd) {
     var origBrd = new this.brdEngine(brd);
     var nextBrd = new this.brdEngine();
     var prevScore = -1, nextScore = -1;
@@ -242,7 +242,7 @@
     }
     return bestDir;
 }
-ai.deepMaxScore.prototype.bestScore = function(brd, seenBrds) {
+ai.DeepMaxScore.prototype.bestScore = function(brd, seenBrds) {
     if (seenBrds) {
         for (var i = 0; i < seenBrds.length; i++)
             if (brd.equals(seenBrds[i]))
@@ -264,7 +264,7 @@
     return maxScore;
 }
 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */
-ai.deepMaxScore.prototype.cleanup = function() { }
+ai.DeepMaxScore.prototype.cleanup = function() { }
 
 
 
@@ -288,14 +288,14 @@
  * @param {Board} brdEngine  board engine from board.js
  * @param {Object} cfg  configuration settings
  * @constructor */
-ai.deepMaxScoreCorner = function(brdEngine, cfg) {
+ai.DeepMaxScoreCorner = function(brdEngine, cfg) {
     this.brdEngine = brdEngine;
     this.cfg = cfg || {};
     this.cfg.cornerBonus = this.cfg.cornerBonus || 20000;
     this.cfg.edgeBonus = this.cfg.edgeBonus || 100;
     this.cfg.freeBonus = this.cfg.edgeBonus || 100;
 }
-ai.deepMaxScoreCorner.prototype.scoreCorner = function(brd) {
+ai.DeepMaxScoreCorner.prototype.scoreCorner = function(brd) {
     var score = brd.score();
     var max = brd.max();
     if (brd.atCorner(max))
@@ -305,7 +305,7 @@
     score += brd.free() * this.cfg.freeBonus;
     return score;
 }
-ai.deepMaxScoreCorner.prototype.scoreEdge = function(brd) {
+ai.DeepMaxScoreCorner.prototype.scoreEdge = function(brd) {
     var score = brd.score();
     var max = brd.max();
     if (brd.atEdge(max))
@@ -313,7 +313,7 @@
     score += brd.free() * this.cfg.freeBonus;
     return score;
 }
-ai.deepMaxScoreCorner.prototype.analyse = function(brd) {
+ai.DeepMaxScoreCorner.prototype.analyse = function(brd) {
     var origBrd = new this.brdEngine(brd);
     var nextBrd = new this.brdEngine();
     var prevScore = -1, nextScore = -1;
@@ -334,7 +334,7 @@
     }
     return bestDir;
 }
-ai.deepMaxScoreCorner.prototype.bestScore = function(brd, seenBrds) {
+ai.DeepMaxScoreCorner.prototype.bestScore = function(brd, seenBrds) {
     if (seenBrds) {
         for (var i = 0; i < seenBrds.length; i++)
             if (brd.equals(seenBrds[i]))
@@ -356,7 +356,7 @@
     return maxScore;
 }
 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */
-ai.deepMaxScoreCorner.prototype.cleanup = function() { }
+ai.DeepMaxScoreCorner.prototype.cleanup = function() { }
 
 
 ////////////////////////////////////////////////////////////////