--- a/ai.js Thu Sep 11 20:01:40 2014 +0300
+++ b/ai.js Mon Sep 15 02:49:02 2014 +0300
@@ -1,10 +1,15 @@
"use strict";
+/** @fileOverview AI modules. */
+
+/** @module */
var ai = {};
+/** Directions. @constant */
ai.dirs = ["up", "right", "down", "left"];
+/** Possible direction function names. @constant */
ai.canDirs = ["canUp", "canRight", "canDown", "canLeft"];
-/* Create empty 'to' if argument missing. */
+/** Create empty 'to' if argument missing. */
ai.copyObj = function(from, to) {
if (to == null || typeof to !== "object")
to = {};
@@ -26,6 +31,9 @@
// Blind random AI.
////////////////////////////////////////////////////////////////
+/** Blind random AI.
+ * @param {Board} brdEngine board engine from board.js
+ * @constructor */
ai.blindRandom = function(brdEngine) {
this.brdEngine = brdEngine;
}
@@ -46,6 +54,19 @@
// Blind weight random AI.
////////////////////////////////////////////////////////////////
+/**
+ * @name ai.BlindWeightRandom.cfg
+ * @namespace
+ * @property {number} left weight
+ * @property {number} right weight
+ * @property {number} up weight
+ * @property {number} down weight
+ */
+
+/** Blind weight random AI.
+ * @param {Board} brdEngine board engine from board.js
+ * @param {ai.BlindWeightRandom.cfg} cfg configuration settings
+ * @constructor */
ai.blindWeightRandom = function(brdEngine, cfg) {
this.brdEngine = brdEngine;
this.cfg = ai.copyObj(ai.blindWeightRandom.bestCfg);
@@ -55,7 +76,9 @@
this.threshold2 = (this.cfg.left + this.cfg.down)/total;
this.threshold3 = (this.cfg.left + this.cfg.down + this.cfg.right)/total;
}
-ai.blindWeightRandom.bestCfg = {left: 1, down: 10, right: 5, up: 1};
+/** @{link ai.BlindWeightRandom.cfg}
+ @namespace */
+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) {
@@ -81,6 +104,17 @@
// Blind cycle AI.
////////////////////////////////////////////////////////////////
+/**
+ * @name ai.BlindCycle.cfg
+ * @namespace
+ * @property {boolean} whilePossible move in one direction while possible
+ * @property {boolean} down switch direction clockwise
+ */
+
+/** Blind cycle AI.
+ * @param {Board} brdEngine board engine from board.js
+ * @param {ai.BlindCycle.cfg} cfg configuration settings
+ * @constructor */
ai.blindCycle = function(brdEngine, cfg) {
this.brdEngine = brdEngine;
this.cfg = cfg || {};
@@ -119,6 +153,21 @@
// for each free field.
////////////////////////////////////////////////////////////////
+/**
+ * Defines coefficient for linear resulted weight function.
+ * @name ai.OneStepDeep.cfg
+ * @namespace
+ * @property {number} scoreCoef multiplicator for score
+ * @property {number} maxValCoef multiplicator for max value
+ * @property {number} cornerBonus bonus for max value at board corner
+ * @property {number} edgeBonus bonus for max value at board edge
+ * @property {number} freeBonus bonus foe each free cell
+ */
+
+/** 1 step deep with * AI.
+ * @param {Board} brdEngine board engine from board.js
+ * @param {ai.OneStepDeep.cfg} cfg configuration settings
+ * @constructor */
ai.oneStepDeep = function(brdEngine, cfg) {
this.brdEngine = brdEngine;
this.cfg = ai.copyObj(ai.oneStepDeep.bestCfg);
@@ -166,6 +215,9 @@
// N level deep on score value without random simulation.
////////////////////////////////////////////////////////////////
+/** N level deep on score value without random simulation.
+ * @param {Board} brdEngine board engine from board.js
+ * @constructor */
ai.deepMaxScore = function(brdEngine) {
this.brdEngine = brdEngine;
}
@@ -221,8 +273,21 @@
// without random simulation.
////////////////////////////////////////////////////////////////
-/* cfg.cornerBonus - value to add if max value at corner. */
-/* cfg.edgeBonus - value to add if max value at edge. */
+/**
+ * Defines coefficient for linear resulted weight function.
+ * @name ai.DeepMaxScoreCorner.cfg
+ * @namespace
+ * @property {number} scoreCoef multiplicator for score
+ * @property {number} maxValCoef multiplicator for max value
+ * @property {number} cornerBonus bonus for max value at board corner
+ * @property {number} edgeBonus bonus for max value at board edge
+ * @property {number} freeBonus bonus foe each free cell
+ */
+
+/** N level deep AI without random simulation.
+ * @param {Board} brdEngine board engine from board.js
+ * @param {Object} cfg configuration settings
+ * @constructor */
ai.deepMaxScoreCorner = function(brdEngine, cfg) {
this.brdEngine = brdEngine;
this.cfg = cfg || {};
@@ -298,8 +363,21 @@
// N level deep with random simulation.
////////////////////////////////////////////////////////////////
-/* cfg.cornerBonus - value to add if max value at corner. */
-/* cfg.edgeBonus - value to add if max value at edge. */
+/**
+ * Defines coefficient for linear resulted weight function.
+ * @name ai.expectimax.cfg
+ * @namespace
+ * @property {number} scoreCoef multiplicator for score
+ * @property {number} maxValCoef multiplicator for max value
+ * @property {number} cornerBonus bonus for max value at board corner
+ * @property {number} edgeBonus bonus for max value at board edge
+ * @property {number} freeBonus bonus foe each free cell
+ */
+
+/** N level deep with random simulation.
+ * @param {Board} brdEngine board engine from board.js
+ * @param {ai.expectimax.cfg} cfg configuration settings
+ * @constructor */
ai.expectimax = function(brdEngine, cfg) {
this.brdEngine = brdEngine;
this.cfg = cfg || {};