From df10a2c2981e75a78f1ff29c8e917b3e0cbc906b Mon Sep 17 00:00:00 2001 From: Harrison Date: Sun, 26 Apr 2020 17:28:57 -0500 Subject: [PATCH] DFS can now take Point2 as parameters for its searches. --- .../pathfinding/DFSNode.java | 21 +++++++------------ .../pathfinding/DepthFirstSearch.java | 10 +++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/pathfinding/DFSNode.java b/src/main/java/ca/recrown/islandsurvivalcraft/pathfinding/DFSNode.java index db8bfd2..b326652 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/pathfinding/DFSNode.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/pathfinding/DFSNode.java @@ -2,21 +2,24 @@ package ca.recrown.islandsurvivalcraft.pathfinding; import java.util.Objects; -public class DFSNode implements Comparable { +import ca.recrown.islandsurvivalcraft.Types.Point2; + +public class DFSNode extends Point2 implements Comparable { private DFSNode goal; public DFSNode[] child; private DFSNode parent; - private int x; - private int y; public DFSNode(DFSNode parent, int x, int y, DFSNode goal) { + super(x, y); child = new DFSNode[4]; - this.x = x; - this.y = y; this.parent = parent; this.goal = goal; } + public DFSNode(DFSNode parent, Point2 coords, DFSNode goal) { + this(parent, coords.x, coords.y, goal); + } + public int getX() { return x; } @@ -61,12 +64,4 @@ public class DFSNode implements Comparable { public int hashCode() { return Objects.hash(x, y); } - - public void copyTo(DFSNode node) { - node.child = child; - node.parent = parent; - node.x = x; - node.y = y; - node.goal = goal; - } } \ No newline at end of file diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/pathfinding/DepthFirstSearch.java b/src/main/java/ca/recrown/islandsurvivalcraft/pathfinding/DepthFirstSearch.java index 27d58ec..c340a9a 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/pathfinding/DepthFirstSearch.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/pathfinding/DepthFirstSearch.java @@ -6,6 +6,8 @@ import java.util.Queue; import org.apache.commons.lang.NullArgumentException; +import ca.recrown.islandsurvivalcraft.Types.Point2; + public class DepthFirstSearch { private Queue queue; private CoordinateValidatable coordValidatable; @@ -43,10 +45,18 @@ public class DepthFirstSearch { startNode = new DFSNode(null, x, y, endNode); } + public void setStartPosition(Point2 start) { + startNode = new DFSNode(null, start, endNode); + } + public void setEndPosition(int x, int y) { endNode = new DFSNode(null, x, y, endNode); } + public void setEndPosition(Point2 goal) { + endNode = new DFSNode(null, goal, endNode); + } + public DFSNode getFoundNode() { return foundNode; }