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
    Constructor
    Description
    AStarNode(boolean walkable, Rectangle bound, int gridX, int gridY)
    Constructs a new AStarNode with the specified properties.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the assigned costs and the predecessor for this node.
    Gets the rectangular bounds of this node.
    double
    Calculates the movement cost from this node to the target node.
    double
    Gets the total cost (f-cost) for this node.
    double
    Gets the cost from the start node to this node (g-cost).
    int
    Gets the x-coordinate of this node in the grid.
    int
    Gets the y-coordinate of this node in the grid.
    double
    Gets the estimated cost from this node to the target node (h-cost).
    Gets the center location of this node as a Point.
    double
    Gets the penalty cost for this node.
    Gets the predecessor node in the path.
    boolean
    Checks if this node is walkable.
    void
    setGCost(double gCost)
    Sets the cost from the start node to this node (g-cost).
    void
    setHCost(double hCost)
    Sets the estimated cost from this node to the target node (h-cost).
    void
    setPenalty(double penalty)
    Sets the penalty cost for this node.
    void
    Sets the predecessor node in the path.
    void
    setWalkable(boolean walkable)
    Sets whether this node is walkable.
    Returns a string representation of this node, including its grid position and costs.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • AStarNode

      public AStarNode(boolean walkable, Rectangle bound, int gridX, int gridY)
      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

      public Rectangle getBounds()
      Gets the rectangular bounds of this node.
      Returns:
      The bounds of the node.
    • getCosts

      public double getCosts(AStarNode target)
      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

      public Point 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

      public AStarNode 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

      public void setPredecessor(AStarNode predecessor)
      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

      public String toString()
      Returns a string representation of this node, including its grid position and costs.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the node.