Commit 7d1e5e5f authored by 15박보승's avatar 15박보승

Remove Contains function from A*. Optimization completed.

parent a0205e78
......@@ -261,13 +261,13 @@ MonoBehaviour:
bounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 10, y: 10, z: 0}
pointInterval: 0.768
pointInterval: 0.614
agentRadius: 0.1
blockMask:
serializedVersion: 2
m_Bits: 256
isOptimizing: 1
complementLevel: 10
complementLevel: 8
enableGizmos: 1
--- !u!4 &178212235
Transform:
......
......@@ -32,6 +32,11 @@ public class PriorityQueue<T>
{
heap.HeapUpdated(item);
}
public IEnumerator<T> GetEnumerator()
{
return heap.GetEnumerator();
}
}
class Heap<T>
......@@ -219,4 +224,9 @@ class Heap<T>
TryWithParent(Parent(index));
}
}
public IEnumerator<T> GetEnumerator()
{
return list.GetEnumerator();
}
}
\ No newline at end of file
......@@ -425,6 +425,7 @@ namespace BS
List<Node> closed = new List<Node>();
queue.Enqueue(start);
start.state = 1;
while (queue.Count > 0)
{
Node cur = queue.Dequeue();
......@@ -436,6 +437,7 @@ namespace BS
if(cur.gridPosition == goal.gridPosition)
{
closed.Add(cur);
cur.state = -1;
break;
}
......@@ -443,8 +445,8 @@ namespace BS
foreach (var adj in cur.adjacencies)
{
Node adjNode = nodes[adj];
bool isOpened = queue.Contains(nodes[adj]);
bool isClosed = closed.Contains(nodes[adj]);
bool isOpened = nodes[adj].state > 0;
bool isClosed = nodes[adj].state < 0;
if (isOpened)
{
......@@ -462,10 +464,11 @@ namespace BS
adjNode.cost = cur.cost + Vector2.Distance(cur.worldPositon, adjNode.worldPositon);
adjNode.CalculateScore(to);
queue.Enqueue(adjNode);
adjNode.state = 1;
}
}
cur.state = -1;
closed.Add(cur);
}
......@@ -492,14 +495,16 @@ namespace BS
{
path.Add(to);
}
/*
foreach(var node in nodes.Values)
foreach(var close in closed)
{
node.cost = 0;
node.parent = null;
node.score = 0;
close.state = 0;
}
*/
foreach(var open in queue)
{
open.state = 0;
}
return path;
}
......@@ -632,15 +637,7 @@ namespace BS
cost = 0;
score = 0;
parent = null;
}
public Node(Node node, Node parent, float cost = 0)
{
this.gridPosition = node.gridPosition;
this.worldPositon = node.worldPositon;
this.adjacencies = node.adjacencies;
this.cost = cost;
this.parent = parent;
score = 0;
state = 0;
}
public Vector2Int gridPosition;
......@@ -649,7 +646,7 @@ namespace BS
public float cost;
public float score;
public Node parent;
public int state; // -1 : closed, 1 : opened, 0 : neutral
public void CalculateScore(Vector3 destination)
{
score = cost + GetHeuristic(destination);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment