everything is a mess
This commit is contained in:
@@ -50,10 +50,10 @@ using UnityEngine;
|
|||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
|
|
||||||
// store coordinates for all potential moves to be checked
|
// store coordinates for all potential moves to be checked
|
||||||
Vector2Int up = new Vector2Int( this.agent.y + 1, this.agent.x );
|
Vector2Int up = new Vector2Int( this.agent.x, this.agent.y + 1 );
|
||||||
Vector2Int down = new Vector2Int( this.agent.y - 1, this.agent.x );
|
Vector2Int down = new Vector2Int( this.agent.x, this.agent.y - 1 );
|
||||||
Vector2Int left = new Vector2Int( this.agent.y, this.agent.x - 1 );
|
Vector2Int left = new Vector2Int( this.agent.x - 1, this.agent.y );
|
||||||
Vector2Int right = new Vector2Int( this.agent.y, this.agent.x + 1 );
|
Vector2Int right = new Vector2Int( this.agent.x + 1, this.agent.y);
|
||||||
|
|
||||||
// make sure going up doesn't go outside world-bounds or into obstacle
|
// make sure going up doesn't go outside world-bounds or into obstacle
|
||||||
if (isOpen(up))
|
if (isOpen(up))
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public class Pathfinder
|
|||||||
public static int height;
|
public static int height;
|
||||||
public static int width;
|
public static int width;
|
||||||
|
|
||||||
|
public Stack<Node> result;
|
||||||
|
|
||||||
|
|
||||||
public Pathfinder(LogicGrid world, Vector2Int a, List<Vector2Int> o, List<Vector2Int> s, int algo, int heu)
|
public Pathfinder(LogicGrid world, Vector2Int a, List<Vector2Int> o, List<Vector2Int> s, int algo, int heu)
|
||||||
{
|
{
|
||||||
@@ -58,25 +60,27 @@ public class Pathfinder
|
|||||||
public void StartWork()
|
public void StartWork()
|
||||||
{
|
{
|
||||||
Node initialState = new Node(null, agent, samples, '0', 0, 0);
|
Node initialState = new Node(null, agent, samples, '0', 0, 0);
|
||||||
List<Node> result = new List<Node>();
|
result = new Stack<Node>();
|
||||||
|
|
||||||
// Run AStar
|
// Run AStar
|
||||||
if (algorithm == 0)
|
if (algorithm == 0)
|
||||||
{
|
{
|
||||||
result = StartAStar(initialState);
|
result = StartAStar(initialState);
|
||||||
Debug.Log(" ");
|
Debug.Log(" ");
|
||||||
for(int i = 0; i < result.Count; i++)
|
|
||||||
|
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("Agent at: " + n.agent.x + ", " + n.agent.y);
|
||||||
Debug.Log(n.lastMove);
|
Debug.Log(n.lastMove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Node> StartAStar(Node initialState)
|
public static Stack<Node> StartAStar(Node initialState)
|
||||||
{
|
{
|
||||||
List<Node> solution = new List<Node>();
|
Stack<Node> solution = new Stack<Node>();
|
||||||
|
|
||||||
List<Node> open = new List<Node>();
|
List<Node> open = new List<Node>();
|
||||||
|
|
||||||
@@ -100,7 +104,7 @@ public class Pathfinder
|
|||||||
Debug.Log("Gottem");
|
Debug.Log("Gottem");
|
||||||
while (currentNode.parent != null)
|
while (currentNode.parent != null)
|
||||||
{
|
{
|
||||||
solution.Add(currentNode);
|
solution.Push(currentNode);
|
||||||
currentNode = currentNode.parent;
|
currentNode = currentNode.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user