c# - List.Contains always returning false -
i trying implement basic a* implementation.
i have 'completed' list contains coordinates of assessed nodes.
for sake of argument, lets trying (1,0) (3,0).
after third iteration, 'completed' list contains (1,0) , (2,0). assessing of neighbours around 2,0. includes assessed (1,0).
when calling completed.contains(neighbour), neighbour = (1,0) should return true. somehow not meet condition. creating duplicate node , assesses in infinite loop.
the below example in code of happening. point = simple object containing x , y.
point1 = new point(1,0); point2 = new point(2,0); neighbour = point1; var completed = new list<point>(); completed.add(point1); completed.add(point2); if(completed.contains(neighbour)) { // something. (in code, should break loop, so...) continue; } // however, happening instead... if(!completed.contains(neighbour)) { // adds list of next node worked on. creating loop. }
there more conditions on these if's in actual code, arguments sake , sanity have made them basic above, no avail. i'm not sure why cannot see existing value. because not looking @ values themselves, index? (therefore 1,0 never exists)?
method list<t>.contains
uses method t.equals
comparing. yous should override equals point class.
https://msdn.microsoft.com/en-us/library/ms173147(v=vs.80).aspx
Comments
Post a Comment