diff -r 847ed98813d1 -r 28613a54c71c ai.js --- 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() { } ////////////////////////////////////////////////////////////////