forked from domachine/latexasq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.js
39 lines (34 loc) · 957 Bytes
/
node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var id = 0;
// Represents a node in the path.
function Node (edges) {
id++;
return {
edges: new Array (edges),
pheromone: 0,
ants: new Array(),
antsOnHomerun: new Array(),
id: id
};
}
exports.buildPath = function (depth) {
var _buildPath = function (depth) {
if (depth === 0) {
return undefined;
}
else {
// Build new Node and put it into the
// chain.
var countChilds = Math.floor(Math.random() * globalsN.MAX_CHILDS);
if(depth === 1)//is leafnode
countChilds = 0;
var newNode = Node (countChilds);
for( var i = 0; i < countChilds; i++ )
// Recursive call.
newNode.edges[i] = _buildPath (depth - 1);
return newNode;
}
};
var root = _buildPath (depth);
root.stepcount = 0;
return root;
}