From ce148072ef18fb0b33b0c9f3bef5629601f1d48f Mon Sep 17 00:00:00 2001 From: Simon O'Shea Date: Tue, 8 Aug 2023 21:53:26 -0400 Subject: everything is a mess --- Pathfinding Visualizer/Assets/Scripts/Pathfinder.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'Pathfinding Visualizer/Assets/Scripts/Pathfinder.cs') diff --git a/Pathfinding Visualizer/Assets/Scripts/Pathfinder.cs b/Pathfinding Visualizer/Assets/Scripts/Pathfinder.cs index b7f820e..9d5332c 100644 --- a/Pathfinding Visualizer/Assets/Scripts/Pathfinder.cs +++ b/Pathfinding Visualizer/Assets/Scripts/Pathfinder.cs @@ -21,6 +21,8 @@ public class Pathfinder public static int height; public static int width; + public Stack result; + public Pathfinder(LogicGrid world, Vector2Int a, List o, List s, int algo, int heu) { @@ -58,25 +60,27 @@ public class Pathfinder public void StartWork() { Node initialState = new Node(null, agent, samples, '0', 0, 0); - List result = new List(); + result = new Stack(); // Run AStar if (algorithm == 0) { result = StartAStar(initialState); - Debug.Log(" "); - for(int i = 0; i < result.Count; i++) + Debug.Log(" "); + + int count = result.Count; + for(int i = 0; i < count; i++) { - Node n = result[i]; + Node n = result.Pop(); Debug.Log("Agent at: " + n.agent.x + ", " + n.agent.y); Debug.Log(n.lastMove); } } } - public static List StartAStar(Node initialState) + public static Stack StartAStar(Node initialState) { - List solution = new List(); + Stack solution = new Stack(); List open = new List(); @@ -100,7 +104,7 @@ public class Pathfinder Debug.Log("Gottem"); while (currentNode.parent != null) { - solution.Add(currentNode); + solution.Push(currentNode); currentNode = currentNode.parent; } -- cgit v1.3.1-4-g156e