Greetings Earthlings !
I've wrote some A*PathFinding dynamic library,of course an algorithm that is able to find the shortest path between a starting point and a target , deprived of any obstacles or blocked areas that interrupt a path.
ScreenShot (no oblique movement allowed, the algorithm confuses a bit on that for short distance only, gotta fix)
Demonstration:
Here it is , deployed as an applet and embeded [fast - loading] :
Click Here
Download Library:
Jar File :
Click Here To Download
Quick Info:
an A*PathFinding algorithm, is based on heuristics, a sub algorithm that defines the way to calculate the closest distance between every step in the path, and the most commonly known / popular ones are the Euclidean (Pythagoras based) and Manhattan , for that reason i added a package that contains predefined heuristics in astarpath.heuristics , for ease of use, it contains Euclidean,Euclidean Squared and Manhattan, however for more dynamics and generics , the library supports a Heuristic interface that implements the heuristic getCost() function, so that users would easily be able to write their very own algorithms for making a heuristic.
Usage Example:
//mports
import astarpath.components.*;
import astarpath.heuristics.*;
import astarpath.interfaces.*;
/**
*
* @author Nader Sleiman
*/
public class UsageExample implements Map{
/*Methods inhereted/implemented by the Map Interface:*/
// mainly used for debugging purposes, as x and y points out to the currently visited nodes/steps.
public void finderVisited(int x, int y)
{
System.out.println("Currenty Processing "+x+","+y);
}
/**
*
* @param sx starting x
* @param sy starting y
* @param tx target x
* @param ty target y
* @return
*/
public float getCost(int sx, int sy, int tx, int ty) {
// returning 1f as the cost is always an ideal ,valid and the most trivial form of a solution.
return 1f;
}
//the height of the map, Not in pixels, but in number of nodes/steps/tiles, its independent of the tile's width, its just the number of it.
public int getHeight() {
return 10;
}
//the width of the map, Not in pixels, but in number of nodes/steps/tiles, its independent of the tile's height, its just the number of it.
public int getWidth() {
return 10;
}
/*On each node/step/tile processed , it will check if its blocked accordingly to the in-putted conditions, so that it decides to include in path if false, or check another way around if true. *
public boolean isBlocked(int x, int y) {
// lets block the point @ 5,5.
return (x == 5 && y ==5)?true:false
}
public static void main(String[] argV)
{
// PathFinder(Map m, int search_Range, boolean allow_diagonal_movement, Heuristic h).
//or
//PathFinder(Map m, int search_Range, boolean allow_diagonal_movement) , uses the standard Euclidena Heuristic.
PathFinder finder = new PathFinder(this,700,false,new Euclidean());
//finder.findPath(int startX, int startY, int targetX, int targetY).
Path p = finder.findPath(0,0,10,10);
System.out.println((p == null?"No valid path is available":"Found a valid path consisting of " + p.getSize() + " steps" + "\n" ));
if( p != null)
for(int i = 0 ; i < p.getSize() ; i++)
System.out.println("["+p.getX(i)+","+p.getY(i)+"]");
}
}
~enjoy