Hi Nina,
Thanks for the response. The odd behavior using my version is that it won’t place additional towers (which is correct), but it does create additional blocked positions (when it shouldn’t be able to). Gary’s version doesn’t result in the latter part, which is strange because they should mean the exact same thing. Let me explain my logic.
In each iteration step, we check the value of connectedTo
of the current Node object. If our startNode
is A, whose connectedTo
variable is A?
This is where the currentNode.connectedTo would be null, right? Node B would have a connectedTo of A, but A would have nothing and return null.
Because A was the first element explored in ExploreNeighbors() (passed into via the BeadthFirstSearch method) it’s never assigned a connectedTo value.
neighbor.connectedTo = currentSearchNode;
Maybe I’m misunderstanding, but I thought that we were then starting BuildPath() with the end:
List<Node> path = new List<Node>();
Node currentNode = destinationNode;
And then because of that, BuildPath works backwards - which is why we reverse it before returning the final path.
So the chain of connected would be E > D > C > B > A > Null. Those get added to the chain during BuildPath in that order. Since A is never assigned a connectedTo (since it’s never a neighbor) it would be the last one added. E however would have a connectedTo value of D. A then is simultaneously the only one with a null value for connectedTo and it would also be the startNode.
At least that’s where my confusion is coming from. We explore from start to finish, then build the bath backwards using the reverse connections we made, so A wouldn’t have any connections.
Am I making sense? Sorry, it’s late here.