The cost()
callback lets you choose how to prioritize node weight, but is there a way to actually change those node weights dynamically?
If I were to do this:
let graph = [];
for (let x = 0; x < 100; x++) {
for (let y = 0; y < 100; y++) {
graph[x] = graph[x] || [];
graph[x][y] = { weight: 1 };
}
}
let graphOptions = {
order: "xy",
torus: false,
diagonals: true,
cutting: false,
heuristic: "euclidian",
cost: (a, b) => {
return b.weight;
},
thread: false
};
let nodeGraph = Lowlight.Astar.Configuration(graph, graphOptions);
How would I change the weight of a random node? My intuition tells me that I should be able to do something like this:
let firstNode = nodeGraph.graphs[0].node(1);
firstNode.weight = 1;
But it doesn't seem as if the weight is accessible there.
I have noticed that if I create a node directly that I can then access the weight as I would expect, however. (new Lowlight.Astar.Node(1, { x: 1, y: 0, weight: 0 })
)
How would you go about solving this?