public class Node
extends java.lang.Object
SearchAlgorithm
Modifier and Type | Field and Description |
---|---|
private Node |
cameFrom
The predecessor node used by A* search algorithm to mark off the previous node in the search tree.
|
private float |
g_score
The cumulative distance from the start node to this node.
|
private float |
h_score |
(package private) static int |
MULTIPLIER
This constant is multiplied with the float coordinate to get an integer for faster internal
computations.
|
private java.util.ArrayList<Node> |
neighbors
List of neighbors to this node.
|
float |
x
The x coordinate of this node.
|
float |
y
The y coordinate of this node.
|
Constructor and Description |
---|
Node(float x,
float y)
Creates a new instance of a node.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addNeighbor(Node neighbor)
Adds a neighboring node to this node, connecting them together.
|
protected float |
calculateG(Node neighbor)
Calculates the distance to a neighbor node.
|
protected float |
calculateH(Node goal)
Calculates the distance to the goal node.
|
protected float |
getF_Score()
Method used by A* to calculate search score.
|
protected float |
getG_Score()
Method used by A* to calculate search score.
|
java.util.Collection<Node> |
getNeighbors()
Returns all the neighbors which this node is connected to.
|
protected Node |
getPredecessor()
Used by A* search.
|
int |
neighbors()
Indicates the number of neighbors (nodes connected to this node).
|
boolean |
removeNeighbor(Node neighbor)
Removes a node from this node as neighbors, effectively disconnecting them.
|
protected void |
setG_Score(float g)
Method used by A* to calculate search score.
|
protected void |
setH_Score(float h)
Method used by A* to calculate search score.
|
protected void |
setPredecessor(Node orig)
Used by A* search.
|
static final int MULTIPLIER
public float x
public float y
private float g_score
private float h_score
private Node cameFrom
private java.util.ArrayList<Node> neighbors
public Node(float x, float y)
x
- The x coordinate of this node.y
- The y coordinate of this node.public java.util.Collection<Node> getNeighbors()
public int neighbors()
public boolean addNeighbor(Node neighbor)
neighbor
- The neighboring node to connect with.public boolean removeNeighbor(Node neighbor)
neighbor
- The neighboring node to disconnect from.protected void setH_Score(float h)
h
- protected float calculateG(Node neighbor)
neighbor
- protected float calculateH(Node goal)
goal
- protected void setG_Score(float g)
g
- protected float getG_Score()
protected float getF_Score()
protected Node getPredecessor()
protected void setPredecessor(Node orig)
orig
-