Class AStarNode
public class AStarNode
Represents a node in the A* pathfinding algorithm. Each node contains information about its position, costs, and walkability.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the assigned costs and the predecessor for this node.Gets the rectangular bounds of this node.doubleCalculates the movement cost from this node to the target node.doublegetFCost()Gets the total cost (f-cost) for this node.doublegetGCost()Gets the cost from the start node to this node (g-cost).intgetGridX()Gets the x-coordinate of this node in the grid.intgetGridY()Gets the y-coordinate of this node in the grid.doublegetHCost()Gets the estimated cost from this node to the target node (h-cost).Gets the center location of this node as a Point.doubleGets the penalty cost for this node.Gets the predecessor node in the path.booleanChecks if this node is walkable.voidsetGCost(double gCost) Sets the cost from the start node to this node (g-cost).voidsetHCost(double hCost) Sets the estimated cost from this node to the target node (h-cost).voidsetPenalty(double penalty) Sets the penalty cost for this node.voidsetPredecessor(AStarNode predecessor) Sets the predecessor node in the path.voidsetWalkable(boolean walkable) Sets whether this node is walkable.toString()Returns a string representation of this node, including its grid position and costs.
-
Constructor Details
-
AStarNode
Constructs a new AStarNode with the specified properties.- Parameters:
walkable- Whether the node is walkable.bound- The rectangular bounds of the node.gridX- The x-coordinate of the node in the grid.gridY- The y-coordinate of the node in the grid.
-
-
Method Details
-
getBounds
Gets the rectangular bounds of this node.- Returns:
- The bounds of the node.
-
getCosts
Calculates the movement cost from this node to the target node.- Parameters:
target- The target node.- Returns:
- The movement cost to the target node.
-
getFCost
public double getFCost()Gets the total cost (f-cost) for this node. The f-cost is the sum of g-cost and h-cost.- Returns:
- The total cost.
-
getGCost
public double getGCost()Gets the cost from the start node to this node (g-cost).- Returns:
- The g-cost.
-
getGridX
public int getGridX()Gets the x-coordinate of this node in the grid.- Returns:
- The x-coordinate.
-
getGridY
public int getGridY()Gets the y-coordinate of this node in the grid.- Returns:
- The y-coordinate.
-
getHCost
public double getHCost()Gets the estimated cost from this node to the target node (h-cost).- Returns:
- The h-cost.
-
getLocation
Gets the center location of this node as a Point.- Returns:
- The center location of the node.
-
getPenalty
public double getPenalty()Gets the penalty cost for this node.- Returns:
- The penalty cost.
-
getPredecessor
Gets the predecessor node in the path.- Returns:
- The predecessor node.
-
isWalkable
public boolean isWalkable()Checks if this node is walkable.- Returns:
- True if the node is walkable, false otherwise.
-
setGCost
public void setGCost(double gCost) Sets the cost from the start node to this node (g-cost).- Parameters:
gCost- The g-cost to set.
-
setHCost
public void setHCost(double hCost) Sets the estimated cost from this node to the target node (h-cost).- Parameters:
hCost- The h-cost to set.
-
setPenalty
public void setPenalty(double penalty) Sets the penalty cost for this node.- Parameters:
penalty- The penalty cost to set.
-
setPredecessor
Sets the predecessor node in the path.- Parameters:
predecessor- The predecessor node to set.
-
setWalkable
public void setWalkable(boolean walkable) Sets whether this node is walkable.- Parameters:
walkable- True if the node is walkable, false otherwise.
-
clear
public void clear()Clears the assigned costs and the predecessor for this node. -
toString
-