123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- package pathgame.algorithm;
- import pathgame.tilemap.TileType;
- import java.util.ArrayList;
- /** Class for storing node data for the Dijkstra algorithm
- *
- */
- public class Node2D {
- private int weight;
- private int costSoFar = Integer.MAX_VALUE;
- private char prevOfPath = '\0';
- private int prevBoatPath = -1;
- private TileType type = TileType.LAND;
- private boolean isQAdded = false;
- private boolean hasExtraPaths = false;
- private boolean isBlocked = false;
- private boolean isTown = false;
- private ArrayList<ExtraPath> extraPaths = new ArrayList<>();
- /** Create new Node2D with given weight
- *
- * @param weight cost it takes to travel to this node
- */
- public Node2D(int weight) {
- this.weight = weight;
- }
- /** Returns the weight of the node
- *
- * @return the weight of the node
- */
- public int getWeight() {
- return weight;
- }
- /** Returns the lowest total cost of travelling to this node from where the algorithm started
- *
- * @return lowest cost to get to this node
- */
- public int getCostSoFar() {
- return costSoFar;
- }
- /** Sets the currently lowest total cost of travelling to this node from where the algorithm started
- *
- * @param costSoFar currently lowest cost to get to this node
- */
- public void setCostSoFar(int costSoFar) {
- this.costSoFar = costSoFar;
- }
- /** Returns a character indicating the previous node of the shortest path from the algorithm's starting point to this node
- *
- * @return direction of previous node
- */
- public char getPrevOfPath() {
- return prevOfPath;
- }
- /** Sets the character indicating the previous node of the shortest path from the algorithm's starting point to this node
- *
- * @param prevOfPath direction of previous node
- */
- public void setPrevOfPath(char prevOfPath) {
- this.prevOfPath = prevOfPath;
- }
- /** Returns the list of all ExtraPaths of this node
- *
- * @return list of ExtraPaths
- */
- public ArrayList<ExtraPath> getExtraPaths() {
- return extraPaths;
- }
- /** Creates an ExtraPath using the given parameters and adds it to the node
- *
- * @param dest coordinate of the destination of the path
- * @param pathWeight total weight to travel this path
- * @param pathCoords list of coordinates of the path
- */
- public void addExtraPath(Coord dest, int pathWeight, ArrayList<Coord> pathCoords) {
- hasExtraPaths = true;
- extraPaths.add(new ExtraPath(dest.getX(), dest.getY(), pathWeight, pathCoords));
- }
- /** Returns hasExtraPaths, which is true, if this node has ExtraPaths
- *
- * @return whether node has ExtraPaths
- */
- public boolean hasExtraPaths() {
- return hasExtraPaths;
- }
- /** Returns isQAdded, which is true, if the node has been added to the queue
- *
- * @return whether node has been added to the queue
- */
- public boolean isQAdded() {
- return isQAdded;
- }
- /** Sets isQAdded, which is true, if the node has been added to the queue
- *
- * @param QAdded whether node has been added to the queue
- */
- public void setQAdded(boolean QAdded) {
- isQAdded = QAdded;
- }
- /** Returns isBlocked, which is true, if this node can't be travelled to from adjacent nodes
- *
- * @return whether node is blocked from travel
- */
- public boolean isBlocked() {
- return isBlocked;
- }
- /** Sets isBlocked, which is true, if this node can't be travelled to from adjacent nodes
- *
- * @param blocked whether node is blocked from travel
- */
- public void setBlocked(boolean blocked) {
- isBlocked = blocked;
- }
- /** Returns the type of the Tile that is represented by this node
- *
- * @return the type of the tile
- */
- public TileType getType() {
- return type;
- }
- /** Sets the type of the Tile that is represented by this node
- *
- * @param type the type of the tile
- */
- public void setType(TileType type) {
- this.type = type;
- }
- /** Returns the index of the the previous ExtraPath
- *
- * @return the index of the the previous ExtraPath
- */
- public int getPrevBoatPath() {
- return prevBoatPath;
- }
- /** Sets the index of the the previous ExtraPath
- *
- * @param prevBoatPath the index of the the previous ExtraPath
- */
- public void setPrevBoatPath(int prevBoatPath) {
- this.prevBoatPath = prevBoatPath;
- }
- /** Returns isTown, which is true if the node is a town
- *
- * @return whether node is a town
- */
- public boolean isTown() {
- return isTown;
- }
- /** Sets isTown, which is true if the node is a town
- *
- * @param town whether node is a town
- */
- public void setTown(boolean town) {
- isTown = town;
- }
- }
|