A-star 101

Hey,
Im all new to this site, and to java, but i’ve been doing VB and C for many years.
anyways, im not that smart on OOP yet, and now i’ve convertet my VB a* algorthym to Java.
The thing is, i KNOW it’s not very optimized, but i thought i’d share it. It’s implemented in a sample here,

click space to find a path

all comments and corrections are welcome.
in fact, i hope someone can help me optimize it
http://www.stud.ntnu.no/~jonasas/astar.zip

Thanks for the algorithm. I doubt that many will be willing to download the ZIP, open all java files and go through the complete algorithm (I certainly wasn’t - sorry).

Maybe you could post a short section of your code where you expect potential for further optimization.

From a quick glance I had the impression that the code was a fairly straightforward implementation of the A* algorithm. One (rather formal) hint: Convention has it that method names begin with a lower case character.

oh, yeah, I see what youre saying…
Its alot of work to get into someones esles code.
But if there are any hard core nitpickers out there, bent on finding something to correct me on, they are still welcome to do so =)

Anyways, i’ll keep that lovercase thing in mind, thanks

Just curious. What do you mean you know it’s not very optimized? How does it run compared to your VB code?

rd

I ment that I dont know much about java, and so Im sure people can improve on it. Thus optimizing it :slight_smile:

BUT, one thing is peculiar. Yesterday i buildt an object oriented pathfinder, with a MUCH better algorythm. But it is 10 times slower than the VB-style code. i don’t get it…

A different pathfinder algorithm than your first one? What is the difference between the two algorythms, as you call them?

rd

it’s hard to explain, but ill try.
i made two algorythms. one is old, and not objectoriented. It is not a real astar and was originaly made for visual basic. i’ve convertet it to java.

The second is a full blooded A* (at least as far as i know) based on OPEN and CLOSED lists and whatnot. followed a tutorial to make it. it’s short and sweet codewise.

BUT, for reasons unknows the old algorythm is about 10 times faster. now i know that you might think (after looking at the code) that the old algorythm just checks four direction while the new oo code cheks eight. but it should not make that much of a difference!

Controles for supplied app: 1,2 SPACE and ENTER

http://www.stud.ntnu.no/~jonasas/astar.zip

I cannot compile your code :frowning:
It gives me 29errors!

public class Pathfinder2 {

private ArrayList<Node2> board; //our nodes

I think it should be the C++ syntax but not java.

[quote]public class Pathfinder2 {

private ArrayList<Node2> board; //our nodes

I think it should be the C++ syntax but not java.
[/quote]
That’s Java 1.5, not C++

Thx.
That’s why I can’t compile the codes. I’m using the 1.4 version. But the java 1.5 looks much like the C++.