• Create Account

## Path Finding Potential Field problem

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1bombshell93  Members

225
Like
0Likes
Like

Posted 01 December 2012 - 04:02 AM

I'm writing my own path finding, aimed at guiding crowds of enemies I've gone for a potential field approach.
while recalculating it keeps looping through already complete elements which is obviously not what I want.
I've tried various things but I can't figure out whats going on, its likely something stupid and small but I've tried many things to prevent this, now I'm even using a dictionary to log all the completed elements and checking if a key is in the dictionary before adding it, but despite my efforts its still adding completed elements!

U, D, L, R are the elements to the Up, Down, Left and Right respectively to the element in question, its worth noting that the field loops around the map, so with a map of 32x 32 elements, element[0,0].L will be element[31,0].
EDIT: position is the elements position within the array of elements making the field.

public void start()
{
value = 0;
List list;
List next;
List A = new List();
List B = new List();
Dictionary done = new Dictionary();
if (U.value >= 0) A.Add(U);
if (D.value >= 0) A.Add(D);
if (L.value >= 0) A.Add(L);
if (R.value >= 0) A.Add(R);
list = A;
next = B;
int x = 1;
while (list.Count > 0)
{
foreach (Potential i in list)
{
i.recalc(x);
if (!done.ContainsKey(i.U.position) &amp;&amp; i.U.value >= 0) next.Add(i.U);
if (!done.ContainsKey(i.D.position) &amp;&amp; i.D.value >= 0) next.Add(i.D);
if (!done.ContainsKey(i.L.position) &amp;&amp; i.L.value >= 0) next.Add(i.L);
if (!done.ContainsKey(i.R.position) &amp;&amp; i.R.value >= 0) next.Add(i.R);
}
list.Clear();
list = (list == A ? B : A);
next = (next == A ? B : A);
x++;
}
}

any and all help would be greatly appreciated,