-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.js
More file actions
40 lines (38 loc) · 999 Bytes
/
graph.js
File metadata and controls
40 lines (38 loc) · 999 Bytes
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
40
var GraphNodeType = { OPEN: 0, WALL: 1 };
function Graph(grid) {
this.elements = grid;
this.nodes = [];
for (var x = 0, len = grid.length; x < len; ++x) {
var row = grid[x];
this.nodes[x] = [];
for (var y = 0, l = row.length; y < l; ++y) {
this.nodes[x].push(new GraphNode(x, y, row[y]));
}
}
}
Graph.prototype.toString = function() {
var graphString = "\n";
var nodes = this.nodes;
for (var x = 0, len = nodes.length; x < len; ++x) {
var rowDebug = "";
var row = nodes[x];
for (var y = 0, l = row.length; y < l; ++y) {
rowDebug += row[y].type + " ";
}
graphString = graphString + rowDebug + "\n";
}
return graphString;
};
function GraphNode(x, y, type) {
this.data = {};
this.x = x;
this.y = y;
this.pos = { x: x, y: y };
this.type = type;
}
GraphNode.prototype.toString = function() {
return "[" + this.x + " " + this.y + "]";
};
GraphNode.prototype.isWall = function() {
return this.type == GraphNodeType.WALL;
};