Class Pathfinder.TreeNode
java.lang.Object
games.stendhal.server.core.pathfinder.Pathfinder.TreeNode
- Enclosing class:
- Pathfinder
The pathfinder node.
-
Constructor Summary
ModifierConstructorDescriptionprotected
TreeNode(int x, int y)
The default constructor with positional information. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Creates valid child nodes.abstract Pathfinder.TreeNode
createNode(int x, int y)
Create a newTreeNode
.protected abstract int
createNodeID(int x, int y)
Calculates the node id.boolean
protected double
getCost()
The cost of moving to this node.double
getHeuristic(Pathfinder.TreeNode nodeGoal)
Calculates the heuristic for the move form node1 to node2.Return the parent node.int
getX()
Return the x-position of the node.int
getY()
Return the y-position of the node.int
hashCode()
boolean
isOpen()
boolean
isValid()
Checks if the entity could stand on the position of this node.abstract boolean
isValid(int x, int y)
Checks if the entity could stand on the given by the coordinates.void
setOpen(boolean open)
-
Constructor Details
-
TreeNode
protected TreeNode(int x, int y)The default constructor with positional information.- Parameters:
x
- the x-position of the node.y
- the y-position of the node.
-
-
Method Details
-
getX
public int getX()Return the x-position of the node.- Returns:
- the x-position of the node.
-
getY
public int getY()Return the y-position of the node.- Returns:
- the y-position of the node.
-
getParent
Return the parent node.- Returns:
- the parent node.
-
getCost
protected double getCost()The cost of moving to this node.- Returns:
- movement cost
-
getHeuristic
Calculates the heuristic for the move form node1 to node2.The right heuristic is very important for A* - a over estimated heuristic will turn A* in to bsf - a under estimated heuristic will turn A* in to Dijkstra's so the manhattan distance seams to be the optimal heuristic here. But it has one disadvantage. It will expand to much. Several nodes will have the same f value It will search the area of the size (abs(startX - goalX) + 1) * (abs(startY - goalY) + 1) So a tie-breaker is needed. 1% square distace seems to work fine. A* will prefer nodes closer to the goal.
- Parameters:
nodeGoal
-- Returns:
- heuristic value for move
-
isValid
public boolean isValid()Checks if the entity could stand on the position of this node.- Returns:
- true if the the entity could stand on the position
-
isValid
public abstract boolean isValid(int x, int y)Checks if the entity could stand on the given by the coordinates.- Parameters:
x
- coordinate of the position to be checkedy
- coordinate of the position to be checked- Returns:
- true if the the entity could stand on the position
-
createNode
Create a newTreeNode
.- Parameters:
x
- x coordinate of the created nodey
- y coordinate of the created node- Returns:
- a
TreeNode
-
createChildren
public void createChildren()Creates valid child nodes.The child nodes have to be
- a valid position
- a f value less than maxDistance (checked against the given node)
-
createNodeID
protected abstract int createNodeID(int x, int y)Calculates the node id.- Parameters:
x
- of the nodey
- of the node- Returns:
- the id of the node
-
isOpen
public final boolean isOpen() -
setOpen
public final void setOpen(boolean open) -
equals
-
hashCode
public int hashCode()
-