From d094f0baf65e87f1cb7032096b89bc58787b148b Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 4 Aug 2013 00:04:16 -0400 Subject: [PATCH] Finished A* Pathfinder --- .../contractor/Pathfinding.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/resonantinduction/contractor/Pathfinding.java b/src/resonantinduction/contractor/Pathfinding.java index 4b568937..333dcd4c 100644 --- a/src/resonantinduction/contractor/Pathfinding.java +++ b/src/resonantinduction/contractor/Pathfinding.java @@ -73,9 +73,28 @@ public class Pathfinding { ForgeDirection direction = ForgeDirection.getOrientation(i); Vector3 neighbor = currentNode.clone().translate(new Vector3(direction.offsetX, direction.offsetY, direction.offsetZ)); - + + double tentativeG = this.gScore.get(currentNode); + + if (this.closedSet.contains(neighbor)) + { + if (tentativeG >= this.gScore.get(neighbor)) + { + continue; + } + } + + if (!this.openSet.contains(neighbor) || tentativeG < this.gScore.get(neighbor)) + { + this.navMap.put(neighbor, currentNode); + this.gScore.put(neighbor, tentativeG); + this.fScore.put(neighbor, this.gScore.get(neighbor) + this.getEstimate(neighbor, this.target)); + this.openSet.add(neighbor); + } } } + + return false; } private Set reconstructPath(HashMap naviMap, Vector3 currentNode)