animation works in logan GUI - terribly inefficient
This commit is contained in:
@@ -80,7 +80,7 @@ public class Pathfinder
|
||||
Debug.Log("GO!");
|
||||
|
||||
open.Add(initialState);
|
||||
int cap = 1000;
|
||||
int cap = 2000;
|
||||
while (true && cap > 0)
|
||||
{
|
||||
if (!open.Any())
|
||||
@@ -99,9 +99,6 @@ public class Pathfinder
|
||||
{
|
||||
Debug.Log("Gottem");
|
||||
|
||||
|
||||
//Node n = FindLastSample(open);
|
||||
|
||||
while (currentNode.parent != null)
|
||||
{
|
||||
solution.Push(currentNode);
|
||||
@@ -115,10 +112,10 @@ public class Pathfinder
|
||||
List<Node> children = currentNode.expand(-1);
|
||||
|
||||
if (heuristic == 0)
|
||||
h0(children);
|
||||
/* else if (heuristic.Equals("h1"))
|
||||
h2(children);/*
|
||||
else if (heuristic == 1)
|
||||
h1(children);
|
||||
else if (heuristic.Equals("h2"))
|
||||
else if (heuristic == 2)
|
||||
h2(children);*/
|
||||
|
||||
foreach (Node child in children)
|
||||
@@ -127,23 +124,10 @@ public class Pathfinder
|
||||
}
|
||||
cap--;
|
||||
}
|
||||
|
||||
Debug.Log("too much work :(");
|
||||
return solution;
|
||||
}
|
||||
|
||||
/* private Node GetLowestNode(List<Node> NodeList)
|
||||
{
|
||||
Node lowest = NodeList[0];
|
||||
for (int i = 1; i < NodeList.Count; i++)
|
||||
{
|
||||
if (NodeList[i].fn < lowest.fn)
|
||||
{
|
||||
lowest = NodeList[i];
|
||||
}
|
||||
}
|
||||
return lowest;
|
||||
}*/
|
||||
|
||||
// HEURISTICS FOR ASTAR
|
||||
public static List<Node> h0(List<Node> children)
|
||||
{
|
||||
@@ -161,40 +145,40 @@ public class Pathfinder
|
||||
return sorted;
|
||||
}
|
||||
|
||||
/* public static List<Node> h1(List<Node> children)
|
||||
public static List<Node> h1(List<Node> children)
|
||||
{
|
||||
Queue<Node> sorted = new PriorityQueue<>(new NodeComparator());
|
||||
List<Node> sorted = new List<Node>();
|
||||
|
||||
for (int i = 0; i < children.size(); i++)
|
||||
for (int i = 0; i < children.Count; i++)
|
||||
{
|
||||
// estimated moves left: samples left
|
||||
children.get(i).heuristic = children.get(i).samples.size();
|
||||
sorted.add(children.get(i));
|
||||
children[i].heuristic = children[i].samples.Count;
|
||||
sorted.Add(children[i]);
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
public static Queue<Node> h2(List<Node> children)
|
||||
public static List<Node> h2(List<Node> children)
|
||||
{
|
||||
Queue<Node> sorted = new PriorityQueue<>(new NodeComparator());
|
||||
List<Node> sorted = new List<Node>();
|
||||
|
||||
if (children.size() == 0)
|
||||
if (children.Count() == 0)
|
||||
return sorted;
|
||||
|
||||
Node child;
|
||||
|
||||
for (int i = 0; i < children.size(); i++)
|
||||
for (int i = 0; i < children.Count(); i++)
|
||||
{
|
||||
// estimated moves left:
|
||||
// distance to nearest sample + 1 (+1 to account for sample action)
|
||||
child = children.get(i);
|
||||
child = children[i];
|
||||
child.heuristic = Node.distance(child.agent, child.nearestSample()) + 1;
|
||||
|
||||
sorted.add(child);
|
||||
sorted.Add(child);
|
||||
}
|
||||
|
||||
return sorted;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public class Node
|
||||
|
||||
@@ -27,9 +27,9 @@ public class nMain : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
// Create world
|
||||
int width = 32;
|
||||
int height = 16;
|
||||
float cellSize = 5f;
|
||||
int width = 16;
|
||||
int height = 8;
|
||||
float cellSize = 10f;
|
||||
Vector3 origin = new Vector3(-77, -34);
|
||||
|
||||
world = new LogicGrid(width, height, cellSize, origin);
|
||||
@@ -107,11 +107,15 @@ public class nMain : MonoBehaviour
|
||||
public void ResetGrid()
|
||||
{
|
||||
world.reset();
|
||||
agent = new Vector2Int();
|
||||
obstacles = new List<Vector2Int>();
|
||||
samples = new List<Vector2Int>();
|
||||
}
|
||||
|
||||
public void StartAlgorithm()
|
||||
{
|
||||
Vector2Int coord = new Vector2Int();
|
||||
bool agentFound = false;
|
||||
|
||||
// Collect information about world
|
||||
for (int x = 0; x < world.GetWidth(); x++)
|
||||
@@ -120,7 +124,7 @@ public class nMain : MonoBehaviour
|
||||
int index = x * world.GetHeight() + y;
|
||||
int value = world.GetValue(x, y);
|
||||
|
||||
Debug.Log("x: " + x + " y: " + y + " | value: " + value);
|
||||
//Debug.Log("x: " + x + " y: " + y + " | value: " + value);
|
||||
|
||||
// Add coordinate to obstacle array
|
||||
if (value == 1)
|
||||
@@ -140,18 +144,33 @@ public class nMain : MonoBehaviour
|
||||
if (!samples.Contains(coord))
|
||||
samples.Add(coord);
|
||||
}
|
||||
// Add coordinate to obstacle array
|
||||
// Add coordinate to agent array
|
||||
if (value == 3)
|
||||
{
|
||||
agent.x = x;
|
||||
agent.y = y;
|
||||
agentFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!agentFound)
|
||||
{
|
||||
Debug.Log("NO AGENT!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (samples.Count == 0)
|
||||
{
|
||||
Debug.Log("NO SAMPLES!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (true)
|
||||
{
|
||||
Pathfinder astar = new Pathfinder(world, agent, obstacles, samples, algorithm, 0);
|
||||
Pathfinder path = new Pathfinder(world, agent, obstacles, samples, 0, 0);
|
||||
Stack<Node> result = path.result;
|
||||
Debug.Log("GO ANIMATE");
|
||||
cellMesh.Animate(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user