Jump to content

  • Log In with Google      Sign In   
  • 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.

  • You cannot reply to this topic
No replies to this topic

#1 bombshell93   Members   -  Reputation: 198

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();
   done.Add(this.position, this);
   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)
	{
	 done.Add(i.position, i);
	 i.recalc(x);
	 if (!done.ContainsKey(i.U.position) && i.U.value >= 0) next.Add(i.U);
	 if (!done.ContainsKey(i.D.position) && i.D.value >= 0) next.Add(i.D);
	 if (!done.ContainsKey(i.L.position) && i.L.value >= 0) next.Add(i.L);
	 if (!done.ContainsKey(i.R.position) && 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,
thanks in advanced,
Bombshell

BIG EDIT: I'm a complete dumbo, completely missed that elements may be added to "next" multiple times, I was stuck on this for at least 2 hours and it was one of those silly little mistakes! so sorry to waste your time with this topic.

Edited by bombshell93, 01 December 2012 - 04:15 AM.


Sponsor:



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.



PARTNERS