From dc9d5da1a99eda9f303ca6012d270d863deee459 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 4 Aug 2013 00:00:48 -0400 Subject: [PATCH] More work on pathfinder --- .../contractor/Pathfinding.java | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/resonantinduction/contractor/Pathfinding.java b/src/resonantinduction/contractor/Pathfinding.java index 4fcf6d9f..4b568937 100644 --- a/src/resonantinduction/contractor/Pathfinding.java +++ b/src/resonantinduction/contractor/Pathfinding.java @@ -4,8 +4,10 @@ package resonantinduction.contractor; import java.util.HashMap; +import java.util.HashSet; import java.util.Set; +import net.minecraftforge.common.ForgeDirection; import resonantinduction.base.Vector3; /** @@ -16,7 +18,7 @@ import resonantinduction.base.Vector3; */ public class Pathfinding { - public Set openSet; + public Set openSet, closedSet; public HashMap navMap; @@ -24,15 +26,17 @@ public class Pathfinding public Vector3 target; + public Set results; + public Pathfinding(Vector3 target) { this.target = target; } - public void findNodes(Vector3 start) + public boolean find(Vector3 start) { this.openSet.add(start); - this.gScore.put(start, 0); + this.gScore.put(start, (double) 0); this.fScore.put(start, this.gScore.get(start) + getEstimate(start, this.target)); while (!this.openSet.isEmpty()) @@ -53,11 +57,42 @@ public class Pathfinding { break; } + + // Break case here; + + if (currentNode.equals(this.target)) + { + this.results = this.reconstructPath(this.navMap, this.target); + return true; + } + + this.openSet.remove(currentNode); + this.closedSet.add(currentNode); + + for (int i = 0; i < 6; i++) + { + ForgeDirection direction = ForgeDirection.getOrientation(i); + Vector3 neighbor = currentNode.clone().translate(new Vector3(direction.offsetX, direction.offsetY, direction.offsetZ)); + + } } } + private Set reconstructPath(HashMap naviMap, Vector3 currentNode) + { + Set path = new HashSet(); + path.add(currentNode); + + if (naviMap.containsKey(currentNode)) + { + path.addAll(this.reconstructPath(naviMap, currentNode)); + } + + return path; + } + private double getEstimate(Vector3 start, Vector3 target2) { - return null; + return start.distance(target2); } }