- Home /
Item not being taked off from the List
Hey guys. Could someone tell me why I can't just remove an item from the list? This is making me get stuck in the loop. I execute the command but the item isn't taked off. I also try closedList.Remove(current), without success.
List<Node> AStar (Node initialNode, Node finalNode) {
openList = closedList = new List<Node>();
initialNode.G = 0;
initialNode.H = initialNode.GetH( finalNode );
openList.Add(initialNode);
int justToNotBreak = 0;
Node current = null;
for(int i = 0; i < 4; i++) {
current = openList[0];
closedList.Add(current);
openList.RemoveAt(0); // why the print always return me 1 if I just deleted the one item that openList has?
print(openList.Count);
foreach(Node neighbor in current.Neighbors) {
if(closedList.Contains(neighbor)) {
Debug.Log("Neighbor is in closed list. Ignored.");
continue;
} else {
[...]
What could be the reason to this to happen? I read that is something with the iteration. Can someone help me? Thanks from now!
Answer by AchillesWF · May 15, 2012 at 02:22 PM
I think this is because your open list is actually the same as your closed list due to this line:
openList = closedList = new List();
You are adding the item from the openList to the closedList, but since the closedList is the same as the openList, the openList count does not really change.
This is exactly the problem! Thanks man! This would be the last thing that I would take a look at! hehe