rlgamekit.pathfinding
Class Path

java.lang.Object
  extended by rlgamekit.pathfinding.Path

public class Path
extends java.lang.Object

A breadth-first pathfinder, searching the shortest path from a start coordinate to a destination condistion. A path consists of discrete steps from one location to another. This pathfinding implementation is not reentrant, so each thread needs it's own instance of a path for pathfinding.


Nested Class Summary
 class Path.Node
          One step of the path.
 
Constructor Summary
Path()
          Creates a new instance of Path with no nodes.
 
Method Summary
 void addStep(int x, int y)
          Add a step to this path
 void advance()
          Advance current step by one.
 void clear()
          Reset path, remove all nodes.
 Path.Node currentStep()
          Retrieve current step. path.getCurrentStep() is equivalent to path.getStep(path.getCurrentIndex());
 boolean findPath(PathSource pathSource, PathDestination pathDestination, int sx, int sy)
          Breadth first pathfinding.
 int getCurrentStepIndex()
          Retrieve the current index on the path. path.getCurrentStep() is equivalent to path.getStep(path.getCurrentIndex());
 Path.Node getStep(int n)
          Random access for a step
 int length()
           
 Path.Node nextStep()
          Look ahead on next step
 void setUseDiagonals(boolean yesno)
          Use diagonals in pathfinding?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Path

public Path()
Creates a new instance of Path with no nodes.

Method Detail

setUseDiagonals

public void setUseDiagonals(boolean yesno)
Use diagonals in pathfinding? Default is true.


length

public int length()
Returns:
length of path in steps

nextStep

public Path.Node nextStep()
Look ahead on next step

Returns:
node at next position, or null if there is no such node (end of path reached)

getCurrentStepIndex

public int getCurrentStepIndex()
Retrieve the current index on the path. path.getCurrentStep() is equivalent to path.getStep(path.getCurrentIndex());

Returns:
The current index on the path.

currentStep

public Path.Node currentStep()
Retrieve current step. path.getCurrentStep() is equivalent to path.getStep(path.getCurrentIndex());

Returns:
node at current position, or null if there is no such node (end of path reached)

getStep

public Path.Node getStep(int n)
Random access for a step

Returns:
node at position n, or null if there is no such node

advance

public void advance()
Advance current step by one.


addStep

public void addStep(int x,
                    int y)
Add a step to this path


clear

public void clear()
Reset path, remove all nodes.


findPath

public boolean findPath(PathSource pathSource,
                        PathDestination pathDestination,
                        int sx,
                        int sy)
Breadth first pathfinding.

Parameters:
pathSource - the pathSource to search
pathDestination - to check weather a pathfinding step reachded the destination.
sx - Source x-coordinate
sy - Source y-coordinate
Returns:
true if path was found, false otherwise