We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › AStar questions
Page Index Toggle Pages: 1
AStar questions (Read 871 times)
AStar questions
Jan 3rd, 2007, 11:30am
 
I'm looking at writing a route-finding applet for players fo a game I play (http://cities.totl.net) which I thoguht would be fairly easy since the world there is divided into squares, and you move one at a time.

However I'm having difficulty seeing how one aspect maps to the library. Each square has a travel cost associated with it. roads cost 1, fields 2, forests 4 etc, but from looking at the  AStar documentation the only way to simulate this seems to be by adding an extra "dimension" but that causes problems since in the game forest->forest costs 4 whilst (as far as I can see) p[2]=4 -> p[2]=4 only costs 1 since they're at the same "height"

Another problem is there's some means for teleporting to set locations for a set cost, which I imagined was just an extra link from every node, but there seems to be no way to do this sort of thing? Is AStar limited to planar 2D grids of nodes with no non-euclidian extra paths?
Re: AStar questions
Reply #1 - Jan 3rd, 2007, 1:54pm
 
AStar is in serious need of updating. I've been writing in Flash and Perl just recently so I haven't had the time.

I've worked on Dijkstra recently and it made me realise that extra dimensions didn't make sense when it came to travelling along a path with a specific cost. In fact AStar I've realised is pretty impossible to configure in this respect.

Teleportation won't work with AStar. It is in fact impossible to configure any 'A*' algorithm for teleportation because if it doesn't walk by the teleporter it won't find it. Only Dijkstra would account for teleportation because it doesn't search using distance, it considers the lines travelled.

And AStar is limited to a hypercube. The makeCuboidNodes accept an array of dimensions which could have no limit, but the nodes can only measure up to 4 dimensions. But if I had connectors - no need for measuring - faster algorithm.

So...

Best I can offer is this, either write your own Dijkstra, or you could adapt my Dijkstra example to your situation. It can handle non-euclidean paths - that's what it's good at, and it builds a search for the whole damned map. You would need a method though to deal with the distances built in to the Connectors so you can multiply them for your map.
Code:

void mulDistance(Node n, float m){
for(int i = 0; i < n.links.size(); i++){
Connector c = (Connector)n.links.get(i);
c.d *= m;
for(int j = 0; j < c.n.links.size(); j++){
Connector r = (Connector)c.n.links.get(j);
if(r.n == n){
r.d *= m;
}
}
}
}

My apologies for my flaky library.
Re: AStar questions
Reply #2 - Jan 3rd, 2007, 2:29pm
 
Your Dijkstra example looks fairly useful thanks.

It looks like I shoudl be able to fairly easily adapt it to my needs.
Page Index Toggle Pages: 1